From 59f2e9a39d728b83dbe3d086d278dd9375a4a850 Mon Sep 17 00:00:00 2001 From: Roundabout1 <86153878+Roundabout1@users.noreply.github.com> Date: Mon, 12 Feb 2024 13:33:16 +0800 Subject: [PATCH] =?UTF-8?q?=D0=9E=D0=BA=D0=BD=D0=BE=20=C2=AB=D0=A1=D0=B2?= =?UTF-8?q?=D0=BE=D0=B9=D1=81=D1=82=D0=B2=D0=B0=C2=BB=20(#219)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/PlatformSeacher.ts | 12 ++-- src/main/file-handlers.ts | 6 ++ src/main/index.ts | 5 ++ .../src/components/FilePropertiesModal.tsx | 60 +++++++++++++++++++ src/renderer/src/components/Sidebar/Menu.tsx | 14 ++++- 5 files changed, 90 insertions(+), 7 deletions(-) create mode 100644 src/renderer/src/components/FilePropertiesModal.tsx diff --git a/src/main/PlatformSeacher.ts b/src/main/PlatformSeacher.ts index e4f22268a..16eb39e4f 100644 --- a/src/main/PlatformSeacher.ts +++ b/src/main/PlatformSeacher.ts @@ -1,20 +1,20 @@ import { app } from 'electron'; -import path from 'path'; import settings from 'electron-settings'; + +import path from 'path'; + import { handleGetPlatforms } from './file-handlers'; const basePath = path.join(__dirname, '../../resources').replace('app.asar', 'app.asar.unpacked'); const DEFAULT_PATH = [basePath + '/platform', app.getPath('userData') + '/platform']; - - export async function searchPlatforms() { return new Promise(async (resolve, _reject) => { const platformsPaths = new Array(); const userPath: any = await settings.get('PlatformsPath'); - let platformFound = false - if (userPath.path != "") { + let platformFound = false; + if (userPath.path != '') { DEFAULT_PATH.push(userPath!.path); } for (const path of DEFAULT_PATH) { @@ -22,7 +22,7 @@ export async function searchPlatforms() { if (response[0]) { if (response[1].length > 0) { platformsPaths.push(...response[1]); - platformFound = true + platformFound = true; } } } diff --git a/src/main/file-handlers.ts b/src/main/file-handlers.ts index b435591f8..5de24aaff 100644 --- a/src/main/file-handlers.ts +++ b/src/main/file-handlers.ts @@ -199,3 +199,9 @@ export async function handleBinFileOpen() { } }); } + +// получить метаданные о файле (дата создания, последней модификации, размер и т.д.) +export function handleGetFileMetadata(absolute_path: string) { + //const stat = fs.statSync(absolute_path); + return fs.statSync(absolute_path); +} diff --git a/src/main/index.ts b/src/main/index.ts index 1de751b70..dc76d68f5 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -20,6 +20,7 @@ import { handleSaveIntoFolder, handleBinFileOpen, handleOpenPlatformFile, + handleGetFileMetadata, } from './file-handlers'; import { FLASHER_LOCAL_PORT, @@ -212,6 +213,10 @@ app.whenReady().then(() => { ipcMain.handle('checkForUpdates', checkForUpdates(app.getVersion())); + ipcMain.handle('File:getMetadata', (_event, absolute_path: string) => { + return handleGetFileMetadata(absolute_path); + }); + // Горячие клавиши для режима разрабочика: // - F12 – инструменты разработки // - CmdOrCtrl + R – перезагрузить страницу diff --git a/src/renderer/src/components/FilePropertiesModal.tsx b/src/renderer/src/components/FilePropertiesModal.tsx new file mode 100644 index 000000000..2158d39bb --- /dev/null +++ b/src/renderer/src/components/FilePropertiesModal.tsx @@ -0,0 +1,60 @@ +import React, { useState } from 'react'; + +import { Modal } from '@renderer/components/UI'; +import { EditorManager } from '@renderer/lib/data/EditorManager'; +import { getPlatform } from '@renderer/lib/data/PlatformLoader'; +import { Platform } from '@renderer/types/platform'; +interface FilePropertiesModalProps { + isOpen: boolean; + onClose: () => void; + manager: EditorManager; +} + +export const FilePropertiesModal: React.FC = ({ + onClose, + manager, + ...props +}) => { + const [fileSize, setFileSize] = useState(0); + const [fileLastModified, setFileLastModified] = useState(); + const [fileBirthDate, setFileBirthDate] = useState(); + const [platform, setPlatform] = useState(undefined); + // получение метаданных о файле + const onAfterOpen = () => { + window.electron.ipcRenderer.invoke('File:getMetadata', manager.data?.basename).then((stat) => { + setFileBirthDate(stat['birthtime']); + setFileLastModified(stat['mtime']); + setFileSize(stat['size']); + }); + + setPlatform(getPlatform(manager.data.elements.platform)); + //setPlatform(getPlatform(manager.data.elements.platform)); + }; + // получить строку, предназначенную для чтения пользователем + function dateFormat(date: Date | undefined): string { + if (!date) { + return ''; + } + return `${date.getDate()}.${ + date.getMonth() + 1 + }.${date.getFullYear()}, ${date.getHours()}:${date.getMinutes()}`; + } + return ( + +
+ Название: {manager.data.name} +
+ Платформа: {platform?.name} +
+ Путь к файлу: {manager.data.basename} +
+ Дата и время последнего изменения файла: {dateFormat(fileLastModified)} +
+ Дата и время создания файла: {dateFormat(fileBirthDate)} +
+ Размер файла: {`${fileSize} байтов`} +
+
+
+ ); +}; diff --git a/src/renderer/src/components/Sidebar/Menu.tsx b/src/renderer/src/components/Sidebar/Menu.tsx index 1ca9e3087..424328ed7 100644 --- a/src/renderer/src/components/Sidebar/Menu.tsx +++ b/src/renderer/src/components/Sidebar/Menu.tsx @@ -1,7 +1,9 @@ -import React, { useLayoutEffect } from 'react'; +import React, { useLayoutEffect, useState } from 'react'; import { EditorManager } from '@renderer/lib/data/EditorManager'; +import { FilePropertiesModal } from '../FilePropertiesModal'; + export interface MenuProps { onRequestNewFile: () => void; onRequestOpenFile: () => void; @@ -43,6 +45,13 @@ export const Menu: React.FC = (props: MenuProps) => { }, disabled: props.compilerStatus !== 'Подключен', }, + { + text: 'Свойства', + onClick: () => { + setIsModalOpen(true); + }, + disabled: !isInitialized, + }, // { // text: 'Примеры', // TODO: модальное окно с выбором примера @@ -68,6 +77,8 @@ export const Menu: React.FC = (props: MenuProps) => { } }; + const [isModalOpen, setIsModalOpen] = useState(false); + const closeModal = () => setIsModalOpen(false); return (

Меню

@@ -82,6 +93,7 @@ export const Menu: React.FC = (props: MenuProps) => { {text} ))} +
); };