diff --git a/lib/main/app.ts b/lib/main/app.ts index 71f40bd..a5a5d65 100644 --- a/lib/main/app.ts +++ b/lib/main/app.ts @@ -108,22 +108,29 @@ export function foundationIpcRegistration(mainWindow: BrowserWindow) { }); ipcMain.on('window-resize', (_, { width, height }) => { - const { x: currentX, y: currentY, width: currentWidth, height: currentHeight } = mainWindow.getBounds(); + const { x: currentX, y: currentY } = mainWindow.getBounds(); - const newX = currentX + (currentWidth - width) / 2; - const newY = currentY + (currentHeight - height) / 2; + const display = screen.getDisplayMatching(mainWindow.getBounds()); + const displayBounds = display.workArea; - const { width: screenWidth, height: screenHeight } = screen.getPrimaryDisplay().workAreaSize; + let newX = currentX; + let newY = currentY; - const clampedX = Math.max(0, Math.min(newX, screenWidth - width)); - //const clampedY = Math.max(0, Math.min(newY, screenHeight - height)); + if (currentX + width > displayBounds.x + displayBounds.width) { + newX = displayBounds.x + displayBounds.width - width; + } + + if (currentY + height > displayBounds.y + displayBounds.height) { + newY = displayBounds.y + displayBounds.height - height; + } mainWindow.setBounds({ - x: Math.round(clampedX), - //y: Math.round(clampedY), - width, - height, + x: newX, + y: newY, + width: width, + height: height }); + mainWindow.webContents.send('window-state-changed'); }); ipcMain.on('window-resizeble', (_, isResizeble) => { diff --git a/lib/main/boot/bootloader.ts b/lib/main/boot/bootloader.ts index 835b420..531db5b 100644 --- a/lib/main/boot/bootloader.ts +++ b/lib/main/boot/bootloader.ts @@ -15,6 +15,13 @@ ipcMain.handleOnce('report-boot-process-failed', async () => { * приложение попыталось загрузиться в режиме разработки. */ let filePath = path.join(WORKING_DIR, 'b'); + if(!await existsFile(filePath)){ + /** + * Исправление ошибки когда директории нет. + */ + logger.log("No compiled files to remove"); + return; + } await fs.rmdir(filePath, { recursive: true }); logger.log("Boot process failed, removed compiled files"); logger.log(`Removed compiled files at ${filePath}`); diff --git a/lib/preload/preload.ts b/lib/preload/preload.ts index 70fb6e7..0fa6029 100644 --- a/lib/preload/preload.ts +++ b/lib/preload/preload.ts @@ -84,61 +84,76 @@ const applicationError = ` const exposeContext = async () => { - let version = await ipcRenderer.invoke("get-core-version"); - let appPath = await ipcRenderer.invoke("get-app-path"); - let arch = await ipcRenderer.invoke("get-arch"); - let deviceName = await ipcRenderer.invoke("device:name"); - let deviceId = await ipcRenderer.invoke("device:id"); - - setTimeout(() => { - /** - * Если после определенного таймаута приложение так и - * не загрузилось, то считаем, что процесс завис, - * и показываем экран ошибки. Так же отправляем - * сигнал в main процесс, чтобы тот мог попытаться - * откатить обновление. - */ - if(document.body.innerHTML.length < 100){ - document.body.innerHTML = applicationError; - ipcRenderer.invoke("report-boot-process-failed"); - } - }, 5000); - - let downloadsPath = await ipcRenderer.invoke("get-downloads-path"); - if (process.contextIsolated) { - try { - contextBridge.exposeInMainWorld('electron', electronAPI) - contextBridge.exposeInMainWorld('api', api) - contextBridge.exposeInMainWorld('version', version); - contextBridge.exposeInMainWorld('platform', process.platform); - contextBridge.exposeInMainWorld('appPath', appPath); - contextBridge.exposeInMainWorld('arch', arch); - contextBridge.exposeInMainWorld('deviceName', deviceName); - contextBridge.exposeInMainWorld('deviceId', deviceId); - contextBridge.exposeInMainWorld('shell', { - openExternal: (url: string) => { - ipcRenderer.invoke('openExternal', url); - }, - showItemInFolder: (fullPath: string) => { - ipcRenderer.invoke('showItemInFolder', fullPath); - } - }); - contextBridge.exposeInMainWorld('downloadsPath', downloadsPath) - } catch (error) { - console.error(error) - } - } else { - window.electron = electronAPI - window.api = api - window.version = version; - window.platform = process.platform; - window.appPath = appPath; - window.arch = arch; - window.shell = shell; - window.downloadsPath = downloadsPath; - window.deviceName = deviceName; - window.deviceId = deviceId; - } + let version = await ipcRenderer.invoke("get-core-version"); + let appPath = await ipcRenderer.invoke("get-app-path"); + let arch = await ipcRenderer.invoke("get-arch"); + let deviceName = await ipcRenderer.invoke("device:name"); + let deviceId = await ipcRenderer.invoke("device:id"); + let interval : any = 0; + + interval = setInterval(() => { + /** + * Если после определенного таймаута приложение так и + * не загрузилось, то считаем, что процесс завис, + * и показываем экран ошибки. Так же отправляем + * сигнал в main процесс, чтобы тот мог попытаться + * откатить обновление + */ + if (document.body.innerHTML.indexOf("preloadersignature") !== -1) { + /** + * Если сейчас показывается прелоадер, то не считаем + * что обновление битое, так как само обновление еще не + * загрузилось в приложение + */ + return; + } + if (document.body.innerHTML.length < 100) { + /** + * Приложение загружено, а прошло больше 5 секунд + * с момента прелоадера, значит что-то пошло не так + * и нужно показать экран ошибки + */ + document.body.innerHTML = applicationError; + ipcRenderer.invoke("report-boot-process-failed"); + } + clearInterval(interval); + }, 5000); + + let downloadsPath = await ipcRenderer.invoke("get-downloads-path"); + if (process.contextIsolated) { + try { + contextBridge.exposeInMainWorld('electron', electronAPI) + contextBridge.exposeInMainWorld('api', api) + contextBridge.exposeInMainWorld('version', version); + contextBridge.exposeInMainWorld('platform', process.platform); + contextBridge.exposeInMainWorld('appPath', appPath); + contextBridge.exposeInMainWorld('arch', arch); + contextBridge.exposeInMainWorld('deviceName', deviceName); + contextBridge.exposeInMainWorld('deviceId', deviceId); + contextBridge.exposeInMainWorld('shell', { + openExternal: (url: string) => { + ipcRenderer.invoke('openExternal', url); + }, + showItemInFolder: (fullPath: string) => { + ipcRenderer.invoke('showItemInFolder', fullPath); + } + }); + contextBridge.exposeInMainWorld('downloadsPath', downloadsPath) + } catch (error) { + console.error(error) + } + } else { + window.electron = electronAPI + window.api = api + window.version = version; + window.platform = process.platform; + window.appPath = appPath; + window.arch = arch; + window.shell = shell; + window.downloadsPath = downloadsPath; + window.deviceName = deviceName; + window.deviceId = deviceId; + } } exposeContext(); \ No newline at end of file diff --git a/resources/preload.html b/resources/preload.html index 1669c3e..09ca3e9 100644 --- a/resources/preload.html +++ b/resources/preload.html @@ -1,26 +1,35 @@ +
+ +
+
\ No newline at end of file