From b23d0096bdd6e680e358e11778a1bf38a8c4e86f Mon Sep 17 00:00:00 2001 From: Roundabout1 Date: Fri, 9 Feb 2024 19:51:59 +0800 Subject: [PATCH 1/7] =?UTF-8?q?=D0=9A=D0=BD=D0=BE=D0=BF=D0=BA=D0=B0=20?= =?UTF-8?q?=D0=B8=20=D0=BE=D0=BA=D0=BD=D0=BE=20=D0=BE=D1=82=D0=BE=D0=B1?= =?UTF-8?q?=D1=80=D0=B0=D0=B6=D0=B5=D0=BD=D0=B8=D1=8F=20=D1=81=D0=B2=D0=BE?= =?UTF-8?q?=D0=B9=D1=81=D1=82=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/components/FilePropertiesModal.tsx | 25 +++++++++++++++++++ src/renderer/src/components/Sidebar/Menu.tsx | 14 ++++++++++- 2 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 src/renderer/src/components/FilePropertiesModal.tsx diff --git a/src/renderer/src/components/FilePropertiesModal.tsx b/src/renderer/src/components/FilePropertiesModal.tsx new file mode 100644 index 000000000..991bbfe58 --- /dev/null +++ b/src/renderer/src/components/FilePropertiesModal.tsx @@ -0,0 +1,25 @@ +import React, { useEffect, useState } from 'react'; + +import { Modal } from '@renderer/components/UI'; + +interface FilePropertiesModalProps { + isOpen: boolean; + onClose: () => void; +} + +export const FilePropertiesModal: React.FC = ({ onClose, ...props }) => { + return ( + +
+ Название: +
+ Платформа: +
+ Последняя дата изменения файла: +
+ Путь к файлу : +
+
+
+ ); +}; diff --git a/src/renderer/src/components/Sidebar/Menu.tsx b/src/renderer/src/components/Sidebar/Menu.tsx index 1ca9e3087..dba37ae06 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} ))} +
); }; From 40bc2e90dfa651429c0ddd528491634535e5a95f Mon Sep 17 00:00:00 2001 From: Roundabout1 Date: Sun, 11 Feb 2024 21:08:27 +0800 Subject: [PATCH 2/7] =?UTF-8?q?=D0=B0=D0=B2=D1=82=D0=BE-=D1=84=D0=BE=D1=80?= =?UTF-8?q?=D0=BC=D0=B0=D1=82=D0=B8=D1=80=D0=BE=D0=B2=D0=B0=D0=BD=D0=B8?= =?UTF-8?q?=D0=B5=20=D1=82=D0=B5=D0=BA=D1=81=D1=82=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/PlatformSeacher.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) 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; } } } From 2ea683113ef18a758b217382f30089397ee4a501 Mon Sep 17 00:00:00 2001 From: Roundabout1 Date: Sun, 11 Feb 2024 21:09:08 +0800 Subject: [PATCH 3/7] =?UTF-8?q?=D0=A4=D1=83=D0=BD=D0=BA=D1=86=D0=B8=D1=8F?= =?UTF-8?q?=20=D0=B4=D0=BB=D1=8F=20=D0=BF=D0=BE=D0=BB=D1=83=D1=87=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D1=8F=20=D0=BC=D0=B5=D1=82=D0=B0=D0=B4=D0=B0=D0=BD?= =?UTF-8?q?=D0=BD=D1=8B=D1=85=20=D0=BE=20=D1=84=D0=B0=D0=B9=D0=BB=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/file-handlers.ts | 6 ++++++ src/main/index.ts | 8 ++++++++ 2 files changed, 14 insertions(+) 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..0c37b163f 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -20,6 +20,10 @@ import { handleSaveIntoFolder, handleBinFileOpen, handleOpenPlatformFile, + handleGetFileSize, + handleGetLastModified, + handleGetBirthTime, + handleGetFileMetadata, } from './file-handlers'; import { FLASHER_LOCAL_PORT, @@ -212,6 +216,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 – перезагрузить страницу From 233e46d11200de42d52de4f84398c29aad028602 Mon Sep 17 00:00:00 2001 From: Roundabout1 Date: Sun, 11 Feb 2024 21:09:50 +0800 Subject: [PATCH 4/7] =?UTF-8?q?=D0=98=D0=B7=D0=B2=D0=BB=D0=B5=D1=87=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D0=B8=20=D0=BF=D0=BE=D0=BA=D0=B0=D0=B7=20?= =?UTF-8?q?=D1=81=D0=B2=D0=BE=D0=B9=D1=81=D1=82=D0=B2=20=D0=BF=D0=BE=D0=BB?= =?UTF-8?q?=D1=8C=D0=B7=D0=BE=D0=B2=D0=B0=D1=82=D0=B5=D0=BB=D1=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/components/FilePropertiesModal.tsx | 51 ++++++++++++++++--- src/renderer/src/components/Sidebar/Menu.tsx | 2 +- 2 files changed, 45 insertions(+), 8 deletions(-) diff --git a/src/renderer/src/components/FilePropertiesModal.tsx b/src/renderer/src/components/FilePropertiesModal.tsx index 991bbfe58..3160ddee7 100644 --- a/src/renderer/src/components/FilePropertiesModal.tsx +++ b/src/renderer/src/components/FilePropertiesModal.tsx @@ -1,23 +1,60 @@ import React, { useEffect, 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, ...props }) => { +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} +
+ Описание платформы: {platform?.description || 'Пока что нет описания'} +
+ Путь к файлу: {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 dba37ae06..424328ed7 100644 --- a/src/renderer/src/components/Sidebar/Menu.tsx +++ b/src/renderer/src/components/Sidebar/Menu.tsx @@ -93,7 +93,7 @@ export const Menu: React.FC = (props: MenuProps) => { {text} ))} - + ); }; From b5c4ff023d09a7e8aea39571132237ba5dc65104 Mon Sep 17 00:00:00 2001 From: Roundabout1 Date: Sun, 11 Feb 2024 21:18:43 +0800 Subject: [PATCH 5/7] =?UTF-8?q?=D1=83=D0=B4=D0=B0=D0=BB=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D0=B5=20=D0=BD=D0=B5=D0=B8=D1=81=D0=BF=D0=BE=D0=BB=D1=8C=D0=B7?= =?UTF-8?q?=D1=83=D0=B5=D0=BC=D1=8B=D1=85=20=D1=84=D1=83=D0=BD=D0=BA=D1=86?= =?UTF-8?q?=D0=B8=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/index.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/main/index.ts b/src/main/index.ts index 0c37b163f..dc76d68f5 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -20,9 +20,6 @@ import { handleSaveIntoFolder, handleBinFileOpen, handleOpenPlatformFile, - handleGetFileSize, - handleGetLastModified, - handleGetBirthTime, handleGetFileMetadata, } from './file-handlers'; import { From 11d59982d2128a0615bb2bebc6b55861859d0056 Mon Sep 17 00:00:00 2001 From: Roundabout1 Date: Sun, 11 Feb 2024 21:20:23 +0800 Subject: [PATCH 6/7] =?UTF-8?q?=D1=83=D0=B4=D0=B0=D0=BB=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D0=B5=20useEffect?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/renderer/src/components/FilePropertiesModal.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/renderer/src/components/FilePropertiesModal.tsx b/src/renderer/src/components/FilePropertiesModal.tsx index 3160ddee7..aa338b409 100644 --- a/src/renderer/src/components/FilePropertiesModal.tsx +++ b/src/renderer/src/components/FilePropertiesModal.tsx @@ -1,4 +1,4 @@ -import React, { useEffect, useState } from 'react'; +import React, { useState } from 'react'; import { Modal } from '@renderer/components/UI'; import { EditorManager } from '@renderer/lib/data/EditorManager'; From 81f36555f743b112a92f2588f3dd8664bc0c86ad Mon Sep 17 00:00:00 2001 From: Roundabout1 Date: Mon, 12 Feb 2024 13:21:38 +0800 Subject: [PATCH 7/7] =?UTF-8?q?=D0=A3=D0=B4=D0=B0=D0=BB=D0=B5=D0=BD=D0=BE?= =?UTF-8?q?=20=D0=BE=D0=BF=D0=B8=D1=81=D0=B0=D0=BD=D0=B8=D0=B5=20=D0=BF?= =?UTF-8?q?=D0=BB=D0=B0=D1=82=D1=84=D0=BE=D1=80=D0=BC=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/renderer/src/components/FilePropertiesModal.tsx | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/renderer/src/components/FilePropertiesModal.tsx b/src/renderer/src/components/FilePropertiesModal.tsx index aa338b409..2158d39bb 100644 --- a/src/renderer/src/components/FilePropertiesModal.tsx +++ b/src/renderer/src/components/FilePropertiesModal.tsx @@ -46,8 +46,6 @@ export const FilePropertiesModal: React.FC = ({
Платформа: {platform?.name}
- Описание платформы: {platform?.description || 'Пока что нет описания'} -
Путь к файлу: {manager.data.basename}
Дата и время последнего изменения файла: {dateFormat(fileLastModified)}