Skip to content

Commit

Permalink
fix: Give the user some prompts when the Node process is occupied and…
Browse files Browse the repository at this point in the history
… the execution of the upgrade script cannot be completed.

Signed-off-by: The1111mp <[email protected]>
  • Loading branch information
1111mp committed Oct 16, 2023
1 parent b61170c commit 6b06a9a
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 26 deletions.
4 changes: 4 additions & 0 deletions _locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -366,5 +366,9 @@
"Command-tools-intro": {
"message": "Command tools intro",
"description": "The text of the Command-tools-intro"
},
"Migration-error": {
"message": "Please close all Node processes and restart the application to complete the update",
"description": "The text of the Migration-error"
}
}
4 changes: 4 additions & 0 deletions _locales/zh_CN/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -366,5 +366,9 @@
"Command-tools-intro": {
"message": "命令行工具介绍",
"description": "The text of the Command-tools-intro"
},
"Migration-error": {
"message": "请关闭所有 Node 进程之后重启应用以完成更新",
"description": "The text of the Migration-error"
}
}
44 changes: 24 additions & 20 deletions src/main/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ nativeTheme.on('updated', () => {
);
});

const createWindow = async () => {
const createWindow = async (code?: number) => {
if (isDebug) {
await installExtensions();
}
Expand Down Expand Up @@ -146,6 +146,12 @@ const createWindow = async () => {
mainWindow.minimize();
} else {
mainWindow.show();

if (code !== void 0) {
setTimeout(() => {
mainWindow?.webContents.send('migration-error');
}, 800);
}
}
});

Expand Down Expand Up @@ -186,24 +192,22 @@ app.on('window-all-closed', () => {
app
.whenReady()
.then(async () => {
try {
const [, settingFromCache, iVersions] = await Promise.all([
updateSchema(),
getSetting(),
allInstalledNodeVersions(),
]);

if (!setting) setting = settingFromCache;
if (!installedVersions)
installedVersions = iVersions.sort((version1, version2) =>
gt(version2, version1) ? 1 : -1,
);

if (!locale) {
const appLocale = setting.locale;
locale = loadLocale({ appLocale });
}
} catch (err) {}
const [code, settingFromCache, iVersions] = await Promise.all([
updateSchema(),
getSetting(),
allInstalledNodeVersions(),
]);

if (!setting) setting = settingFromCache;
if (!installedVersions)
installedVersions = iVersions.sort((version1, version2) =>
gt(version2, version1) ? 1 : -1,
);

if (!locale) {
const appLocale = setting.locale;
locale = loadLocale({ appLocale });
}

ipcMain.on('setting-data-get', (event) => {
event.returnValue = { ...setting, localeMessages: locale.messages };
Expand Down Expand Up @@ -231,7 +235,7 @@ app
event.returnValue = locale.messages;
});

createWindow();
createWindow(code);
app.on('activate', () => {
// On macOS it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
Expand Down
12 changes: 11 additions & 1 deletion src/main/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@ type OnProgressCallback = (id: string, data: Nvmd.ProgressData) => void;
type OnThemeChangedCallback = (theme: string) => void;
type OnCurVersionChange = (version: string) => void;
type OnProjectUpdate = (projects: Nvmd.Project[], version: string) => void;
type OnMigrationError = () => void;

let onCheckUpdateResult: OnCheckUpdateResultCallback | null = null,
onUpdateProgress: OnUpdateProgressCallback | null = null,
onProgress: OnProgressCallback | null = null,
onThemeChanged: OnThemeChangedCallback | null = null,
onCurVersionChange: OnCurVersionChange | null = null,
onProjectUpdate: OnProjectUpdate | null = null;
onProjectUpdate: OnProjectUpdate | null = null,
onMigrationError: OnMigrationError | null = null;

ipcRenderer.on('update-available', (_event, info: UpdateInfo) => {
onCheckUpdateResult?.(info);
Expand Down Expand Up @@ -62,6 +64,10 @@ ipcRenderer.on(
},
);

ipcRenderer.on('migration-error', (_evnet) => {
onMigrationError?.();
});

const electronHandler = {
platform: process.platform,
arch: process.arch,
Expand Down Expand Up @@ -143,6 +149,10 @@ const electronHandler = {
onRegistProjectUpdate: (callback: OnProjectUpdate | null) => {
onProjectUpdate = callback;
},

onRegistMigrationError: (callback: OnMigrationError) => {
onMigrationError = callback;
},
};

contextBridge.exposeInMainWorld('Context', electronHandler);
Expand Down
10 changes: 7 additions & 3 deletions src/main/utils/migration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,14 @@ export async function updateSchema() {
const maxUserVersion = SCHEMA_VERSIONS.length;
const shellVersion = await getSchemaVersion();

for (let index = 0; index < maxUserVersion; index++) {
const runSchemaUpdate = SCHEMA_VERSIONS[index];
try {
for (let index = 0; index < maxUserVersion; index++) {
const runSchemaUpdate = SCHEMA_VERSIONS[index];

await runSchemaUpdate(shellVersion);
await runSchemaUpdate(shellVersion);
}
} catch (err) {
return 408;
}
return;
}
Expand Down
20 changes: 18 additions & 2 deletions src/renderer/pages/home/index.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
import './styles.scss';

import { useState, useRef, lazy, Suspense } from 'react';
import { useState, useRef, lazy, Suspense, useEffect } from 'react';
import { Outlet, Link, useLocation } from 'react-router-dom';
import { Button, Layout, Menu, Space, Tour, Typography } from 'antd';
import {
App,
Button,
Layout,
Menu,
Space,
Tour,
Typography,
message,
} from 'antd';
import {
InfoCircleOutlined,
SettingOutlined,
Expand All @@ -28,6 +37,7 @@ const Home: React.FC = () => {
);
const { pathname } = useLocation();

const { message } = App.useApp();
const tip = useRef(null);
const projectsMenu = useRef(null);
const { locale } = useAppContext();
Expand All @@ -38,6 +48,12 @@ const Home: React.FC = () => {

const platform = window.Context.platform;

useEffect(() => {
window.Context.onRegistMigrationError(() => {
message.warning(i18n('Migration-error'), 5);
});
}, []);

const steps: TourProps['steps'] = [
{
title: i18n('Welcome'),
Expand Down

0 comments on commit 6b06a9a

Please sign in to comment.