Skip to content

Commit

Permalink
Окно «Свойства» (#219)
Browse files Browse the repository at this point in the history
  • Loading branch information
Roundabout1 authored Feb 12, 2024
1 parent e15c6f3 commit 59f2e9a
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 7 deletions.
12 changes: 6 additions & 6 deletions src/main/PlatformSeacher.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
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<string>();
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) {
const response = await handleGetPlatforms(path);
if (response[0]) {
if (response[1].length > 0) {
platformsPaths.push(...response[1]);
platformFound = true
platformFound = true;
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions src/main/file-handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
5 changes: 5 additions & 0 deletions src/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
handleSaveIntoFolder,
handleBinFileOpen,
handleOpenPlatformFile,
handleGetFileMetadata,
} from './file-handlers';
import {
FLASHER_LOCAL_PORT,
Expand Down Expand Up @@ -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 – перезагрузить страницу
Expand Down
60 changes: 60 additions & 0 deletions src/renderer/src/components/FilePropertiesModal.tsx
Original file line number Diff line number Diff line change
@@ -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<FilePropertiesModalProps> = ({
onClose,
manager,
...props
}) => {
const [fileSize, setFileSize] = useState<number>(0);
const [fileLastModified, setFileLastModified] = useState<Date>();
const [fileBirthDate, setFileBirthDate] = useState<Date>();
const [platform, setPlatform] = useState<Platform | undefined>(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 (
<Modal {...props} onRequestClose={onClose} onAfterOpen={onAfterOpen} title="Свойства">
<div>
<b>Название:</b> {manager.data.name}
<br />
<b>Платформа:</b> {platform?.name}
<br />
<b>Путь к файлу:</b> {manager.data.basename}
<br />
<b>Дата и время последнего изменения файла:</b> {dateFormat(fileLastModified)}
<br />
<b>Дата и время создания файла:</b> {dateFormat(fileBirthDate)}
<br />
<b>Размер файла:</b> {`${fileSize} байтов`}
<br />
</div>
</Modal>
);
};
14 changes: 13 additions & 1 deletion src/renderer/src/components/Sidebar/Menu.tsx
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -43,6 +45,13 @@ export const Menu: React.FC<MenuProps> = (props: MenuProps) => {
},
disabled: props.compilerStatus !== 'Подключен',
},
{
text: 'Свойства',
onClick: () => {
setIsModalOpen(true);
},
disabled: !isInitialized,
},
// {
// text: 'Примеры',
// TODO: модальное окно с выбором примера
Expand All @@ -68,6 +77,8 @@ export const Menu: React.FC<MenuProps> = (props: MenuProps) => {
}
};

const [isModalOpen, setIsModalOpen] = useState(false);
const closeModal = () => setIsModalOpen(false);
return (
<section className="flex flex-col">
<h3 className="mx-4 mb-3 border-b border-border-primary py-2 text-center text-lg">Меню</h3>
Expand All @@ -82,6 +93,7 @@ export const Menu: React.FC<MenuProps> = (props: MenuProps) => {
{text}
</button>
))}
<FilePropertiesModal isOpen={isModalOpen} manager={props.manager} onClose={closeModal} />
</section>
);
};

0 comments on commit 59f2e9a

Please sign in to comment.