Skip to content

Commit

Permalink
Фикс: невозможно было закрыть приложение во время загрузки или ошибки (
Browse files Browse the repository at this point in the history
  • Loading branch information
bryzZz authored Dec 11, 2023
1 parent 83ce10d commit 2338c1d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
11 changes: 10 additions & 1 deletion src/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ function createWindow(): void {
},
});

let shouldClose = false; // Флаг для того чтобы можно было закрыть на крестик после открытия окна сохранения

mainWindow.webContents.on('before-input-event', (event, input) => {
if (input.control && input.code === 'KeyW') {
event.preventDefault();
Expand All @@ -68,10 +70,17 @@ function createWindow(): void {

//Запрос в область рендера
mainWindow.on('close', (e) => {
if (mainWindow) {
if (!mainWindow) return;

if (!shouldClose) {
e.preventDefault();
mainWindow.webContents.send('app-close');
}
shouldClose = true;
});

ipcMain.on('reset-close', () => {
shouldClose = false;
});

//Получаем ответ из рендера и закрываем приложение
Expand Down
5 changes: 4 additions & 1 deletion src/renderer/src/hooks/useFileOperations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ export const useFileOperations = (args: useFileOperationsArgs) => {
const [data, setData] = useState<SaveModalData | null>(null);
const [isOpen, setIsOpen] = useState(false);
const openSaveModal = () => setIsOpen(true);
const onClose = () => setIsOpen(false);
const onClose = () => {
window.electron.ipcRenderer.send('reset-close');
setIsOpen(false);
};

/*Открытие файла*/
const handleOpenFile = async (path?: string) => {
Expand Down

0 comments on commit 2338c1d

Please sign in to comment.