fix throwing error screen before loading update
This commit is contained in:
@@ -108,22 +108,29 @@ export function foundationIpcRegistration(mainWindow: BrowserWindow) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
ipcMain.on('window-resize', (_, { width, height }) => {
|
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 display = screen.getDisplayMatching(mainWindow.getBounds());
|
||||||
const newY = currentY + (currentHeight - height) / 2;
|
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));
|
if (currentX + width > displayBounds.x + displayBounds.width) {
|
||||||
//const clampedY = Math.max(0, Math.min(newY, screenHeight - height));
|
newX = displayBounds.x + displayBounds.width - width;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (currentY + height > displayBounds.y + displayBounds.height) {
|
||||||
|
newY = displayBounds.y + displayBounds.height - height;
|
||||||
|
}
|
||||||
|
|
||||||
mainWindow.setBounds({
|
mainWindow.setBounds({
|
||||||
x: Math.round(clampedX),
|
x: newX,
|
||||||
//y: Math.round(clampedY),
|
y: newY,
|
||||||
width,
|
width: width,
|
||||||
height,
|
height: height
|
||||||
});
|
});
|
||||||
|
mainWindow.webContents.send('window-state-changed');
|
||||||
});
|
});
|
||||||
|
|
||||||
ipcMain.on('window-resizeble', (_, isResizeble) => {
|
ipcMain.on('window-resizeble', (_, isResizeble) => {
|
||||||
|
|||||||
@@ -15,6 +15,13 @@ ipcMain.handleOnce('report-boot-process-failed', async () => {
|
|||||||
* приложение попыталось загрузиться в режиме разработки.
|
* приложение попыталось загрузиться в режиме разработки.
|
||||||
*/
|
*/
|
||||||
let filePath = path.join(WORKING_DIR, 'b');
|
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 });
|
await fs.rmdir(filePath, { recursive: true });
|
||||||
logger.log("Boot process failed, removed compiled files");
|
logger.log("Boot process failed, removed compiled files");
|
||||||
logger.log(`Removed compiled files at ${filePath}`);
|
logger.log(`Removed compiled files at ${filePath}`);
|
||||||
|
|||||||
@@ -84,61 +84,76 @@ const applicationError = `
|
|||||||
|
|
||||||
|
|
||||||
const exposeContext = async () => {
|
const exposeContext = async () => {
|
||||||
let version = await ipcRenderer.invoke("get-core-version");
|
let version = await ipcRenderer.invoke("get-core-version");
|
||||||
let appPath = await ipcRenderer.invoke("get-app-path");
|
let appPath = await ipcRenderer.invoke("get-app-path");
|
||||||
let arch = await ipcRenderer.invoke("get-arch");
|
let arch = await ipcRenderer.invoke("get-arch");
|
||||||
let deviceName = await ipcRenderer.invoke("device:name");
|
let deviceName = await ipcRenderer.invoke("device:name");
|
||||||
let deviceId = await ipcRenderer.invoke("device:id");
|
let deviceId = await ipcRenderer.invoke("device:id");
|
||||||
|
let interval : any = 0;
|
||||||
|
|
||||||
setTimeout(() => {
|
interval = setInterval(() => {
|
||||||
/**
|
/**
|
||||||
* Если после определенного таймаута приложение так и
|
* Если после определенного таймаута приложение так и
|
||||||
* не загрузилось, то считаем, что процесс завис,
|
* не загрузилось, то считаем, что процесс завис,
|
||||||
* и показываем экран ошибки. Так же отправляем
|
* и показываем экран ошибки. Так же отправляем
|
||||||
* сигнал в main процесс, чтобы тот мог попытаться
|
* сигнал в main процесс, чтобы тот мог попытаться
|
||||||
* откатить обновление.
|
* откатить обновление
|
||||||
*/
|
*/
|
||||||
if(document.body.innerHTML.length < 100){
|
if (document.body.innerHTML.indexOf("preloadersignature") !== -1) {
|
||||||
document.body.innerHTML = applicationError;
|
/**
|
||||||
ipcRenderer.invoke("report-boot-process-failed");
|
* Если сейчас показывается прелоадер, то не считаем
|
||||||
}
|
* что обновление битое, так как само обновление еще не
|
||||||
}, 5000);
|
* загрузилось в приложение
|
||||||
|
*/
|
||||||
|
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");
|
let downloadsPath = await ipcRenderer.invoke("get-downloads-path");
|
||||||
if (process.contextIsolated) {
|
if (process.contextIsolated) {
|
||||||
try {
|
try {
|
||||||
contextBridge.exposeInMainWorld('electron', electronAPI)
|
contextBridge.exposeInMainWorld('electron', electronAPI)
|
||||||
contextBridge.exposeInMainWorld('api', api)
|
contextBridge.exposeInMainWorld('api', api)
|
||||||
contextBridge.exposeInMainWorld('version', version);
|
contextBridge.exposeInMainWorld('version', version);
|
||||||
contextBridge.exposeInMainWorld('platform', process.platform);
|
contextBridge.exposeInMainWorld('platform', process.platform);
|
||||||
contextBridge.exposeInMainWorld('appPath', appPath);
|
contextBridge.exposeInMainWorld('appPath', appPath);
|
||||||
contextBridge.exposeInMainWorld('arch', arch);
|
contextBridge.exposeInMainWorld('arch', arch);
|
||||||
contextBridge.exposeInMainWorld('deviceName', deviceName);
|
contextBridge.exposeInMainWorld('deviceName', deviceName);
|
||||||
contextBridge.exposeInMainWorld('deviceId', deviceId);
|
contextBridge.exposeInMainWorld('deviceId', deviceId);
|
||||||
contextBridge.exposeInMainWorld('shell', {
|
contextBridge.exposeInMainWorld('shell', {
|
||||||
openExternal: (url: string) => {
|
openExternal: (url: string) => {
|
||||||
ipcRenderer.invoke('openExternal', url);
|
ipcRenderer.invoke('openExternal', url);
|
||||||
},
|
},
|
||||||
showItemInFolder: (fullPath: string) => {
|
showItemInFolder: (fullPath: string) => {
|
||||||
ipcRenderer.invoke('showItemInFolder', fullPath);
|
ipcRenderer.invoke('showItemInFolder', fullPath);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
contextBridge.exposeInMainWorld('downloadsPath', downloadsPath)
|
contextBridge.exposeInMainWorld('downloadsPath', downloadsPath)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error)
|
console.error(error)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
window.electron = electronAPI
|
window.electron = electronAPI
|
||||||
window.api = api
|
window.api = api
|
||||||
window.version = version;
|
window.version = version;
|
||||||
window.platform = process.platform;
|
window.platform = process.platform;
|
||||||
window.appPath = appPath;
|
window.appPath = appPath;
|
||||||
window.arch = arch;
|
window.arch = arch;
|
||||||
window.shell = shell;
|
window.shell = shell;
|
||||||
window.downloadsPath = downloadsPath;
|
window.downloadsPath = downloadsPath;
|
||||||
window.deviceName = deviceName;
|
window.deviceName = deviceName;
|
||||||
window.deviceId = deviceId;
|
window.deviceId = deviceId;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
exposeContext();
|
exposeContext();
|
||||||
@@ -1,26 +1,35 @@
|
|||||||
<html lang="en">
|
<html lang="en">
|
||||||
|
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
|
<!--
|
||||||
|
Нужно чтобы точно определить, что сейчас показывается preload
|
||||||
|
И при старте начинать проверять boot только после того, как этот файл загрузится
|
||||||
|
-->
|
||||||
|
<meta key="preloadersignature">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<title>Rosetta</title>
|
<title>Rosetta</title>
|
||||||
<style>
|
<style>
|
||||||
.pulse {
|
.pulse {
|
||||||
animation: pulse 1s infinite;
|
animation: pulse 1s infinite;
|
||||||
}
|
|
||||||
@keyframes pulse {
|
|
||||||
0% {
|
|
||||||
transform: scale(1);
|
|
||||||
}
|
}
|
||||||
50% {
|
|
||||||
transform: scale(1.15);
|
@keyframes pulse {
|
||||||
|
0% {
|
||||||
|
transform: scale(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
50% {
|
||||||
|
transform: scale(1.15);
|
||||||
|
}
|
||||||
|
|
||||||
|
100% {
|
||||||
|
transform: scale(1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
100% {
|
|
||||||
transform: scale(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</style>
|
</style>
|
||||||
<style>
|
<style>
|
||||||
*{
|
* {
|
||||||
padding: 0px;
|
padding: 0px;
|
||||||
margin: 0px;
|
margin: 0px;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
@@ -31,7 +40,8 @@
|
|||||||
-webkit-user-select: none;
|
-webkit-user-select: none;
|
||||||
-webkit-app-region: no-drag;
|
-webkit-app-region: no-drag;
|
||||||
}
|
}
|
||||||
body{
|
|
||||||
|
body {
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
@@ -41,7 +51,9 @@
|
|||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
<img src="R.png" width="100" height="100" class="pulse">
|
<img src="R.png" width="100" height="100" class="pulse">
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
||||||
Reference in New Issue
Block a user