diff --git a/@types/index.d.ts b/@types/index.d.ts index 3bb9b18..600b7d7 100644 --- a/@types/index.d.ts +++ b/@types/index.d.ts @@ -1,4 +1,4 @@ -import { Themes } from 'types'; +import { Closer, Themes } from 'types'; import type { UpdateInfo as ElectronUpdateInfo } from 'electron-updater'; declare global { @@ -23,6 +23,7 @@ declare global { interface Setting { locale: string; theme: Themes; + closer: Closer; directory: string; mirror: string; } diff --git a/_locales/en/messages.json b/_locales/en/messages.json index e252a7d..11a9188 100644 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -382,5 +382,17 @@ "Migration-error": { "message": "Please close all Node processes and restart the application to complete the update", "description": "The text of the Migration-error" + }, + "When-Closing": { + "message": "When Closing", + "description": "The text of the When-Closing" + }, + "Minimize-Window": { + "message": "Minimize To System Tray", + "description": "The text of the Minimize-Window" + }, + "Quit-App": { + "message": "Quit App", + "description": "The text of the Quit-App" } } diff --git a/_locales/zh_CN/messages.json b/_locales/zh_CN/messages.json index 0957553..45d6f0a 100644 --- a/_locales/zh_CN/messages.json +++ b/_locales/zh_CN/messages.json @@ -382,5 +382,17 @@ "Migration-error": { "message": "请关闭所有 Node 进程之后重启应用以完成更新", "description": "The text of the Migration-error" + }, + "When-Closing": { + "message": "关闭时", + "description": "The text of the When-Closing" + }, + "Minimize-Window": { + "message": "最小化到系统托盘", + "description": "The text of the Minimize-Window" + }, + "Quit-App": { + "message": "退出应用", + "description": "The text of the Quit-App" } } diff --git a/src/main/main.ts b/src/main/main.ts index a733746..a182cbc 100644 --- a/src/main/main.ts +++ b/src/main/main.ts @@ -43,7 +43,7 @@ import { } from './utils/projects'; import { gt } from 'semver'; import loadLocale from './locale'; -import { Themes } from '../types'; +import { Closer, Themes } from '../types'; import type { MenuItemConstructorOptions } from 'electron'; @@ -182,9 +182,7 @@ const createWindow = async (code?: number) => { */ app.on('window-all-closed', () => { - // Respect the OSX convention of having the application in memory even - // after all windows have been closed - if (process.platform !== 'darwin') { + if (setting.closer === Closer.Close) { app.quit(); } }); diff --git a/src/main/utils/setting.ts b/src/main/utils/setting.ts index 10eef23..90e1ad2 100644 --- a/src/main/utils/setting.ts +++ b/src/main/utils/setting.ts @@ -1,23 +1,26 @@ import { pathExists, readJson, writeJson } from 'fs-extra'; import { app } from 'electron'; import { INSTALL_DIR, SETTING_JSONFILE } from '../constants'; -import { Themes } from '../../types'; +import { Closer, Themes } from '../../types'; export async function getSetting(): Promise { if (!(await pathExists(SETTING_JSONFILE))) return { locale: app.getLocale().startsWith('en') ? 'en' : 'zh-CN', theme: Themes.System, + closer: Closer.Minimize, directory: INSTALL_DIR, mirror: 'https://nodejs.org/dist', }; const setting = await readJson(SETTING_JSONFILE, { throws: false }); if (!setting.directory) setting.directory = INSTALL_DIR; + if (!setting.closer) setting.closer = Closer.Minimize; return ( setting || { locale: app.getLocale().startsWith('en') ? 'en' : 'zh-CN', theme: Themes.System, + closer: Closer.Minimize, directory: INSTALL_DIR, mirror: 'https://nodejs.org/dist', } diff --git a/src/renderer/App.tsx b/src/renderer/App.tsx index 2b75008..7b35b37 100644 --- a/src/renderer/App.tsx +++ b/src/renderer/App.tsx @@ -9,11 +9,12 @@ import en from 'antd/locale/en_US'; import zhCN from 'antd/locale/zh_CN'; import { applyTheme } from './util'; -import { Themes } from 'types'; +import { Closer, Themes } from 'types'; type StateType = { locale: string; theme: Themes; // from setting + closer: Closer; directory: string; // node installation directory sysTheme: Themes; // system real theme mirror: string; @@ -31,7 +32,7 @@ type StateAction = { }; export default function App() { - const { locale, theme, directory, mirror, localeMessages } = + const { locale, theme, closer, directory, mirror, localeMessages } = window.Context.getSettingData(); const [state, dispatch] = useReducer( @@ -50,6 +51,7 @@ export default function App() { { locale, theme: theme, + closer, directory, sysTheme: window.Context.getSystemTheme() as Themes, mirror, @@ -179,6 +181,7 @@ export default function App() { value={{ locale: state.locale, theme: state.theme, + closer: state.closer, direction: state.directory, mirror: state.mirror, getMessage, diff --git a/src/renderer/appContext.ts b/src/renderer/appContext.ts index 3c8f6e2..5fd3616 100644 --- a/src/renderer/appContext.ts +++ b/src/renderer/appContext.ts @@ -1,9 +1,10 @@ import { createContext, useContext } from 'react'; -import { Themes } from 'types'; +import { Closer, Themes } from 'types'; type AppContextType = { locale: string; theme: Themes; + closer: Closer; direction: string; mirror: string; getMessage: I18nFn; diff --git a/src/renderer/pages/home/setting.tsx b/src/renderer/pages/home/setting.tsx index 8f5a1e4..0414eb5 100644 --- a/src/renderer/pages/home/setting.tsx +++ b/src/renderer/pages/home/setting.tsx @@ -12,7 +12,7 @@ import { } from 'antd'; import { EditOutlined, ExclamationCircleOutlined } from '@ant-design/icons'; import { useAppContext, useI18n } from 'renderer/appContext'; -import { Themes } from 'types'; +import { Closer, Themes } from 'types'; export type Ref = { show: () => void; @@ -86,6 +86,7 @@ const Content = forwardRef(({}, ref) => { const { locale, theme: ctxTheme, + closer: ctxCloser, direction: ctxDirection, mirror: ctxMirror, onUpdateSetting, @@ -94,6 +95,7 @@ const Content = forwardRef(({}, ref) => { const [language, setLanguage] = useState(() => locale); const [theme, setTheme] = useState(() => ctxTheme); + const [closer, setCloser] = useState(() => ctxCloser); const [directory, setDirectory] = useState(() => ctxDirection); const [mirror, setMirror] = useState(() => ctxMirror); @@ -116,6 +118,7 @@ const Content = forwardRef(({}, ref) => { if ( language === locale && theme === ctxTheme && + closer === ctxCloser && directory === ctxDirection && mirror === ctxMirror ) @@ -124,6 +127,7 @@ const Content = forwardRef(({}, ref) => { onUpdateSetting({ locale: language, theme, + closer, directory, mirror, }); @@ -161,6 +165,19 @@ const Content = forwardRef(({}, ref) => { /> + + { + setCloser(evt.target.value as Closer); + }} + /> + + diff --git a/src/types.ts b/src/types.ts index 3f27fbe..b6cf6cb 100644 --- a/src/types.ts +++ b/src/types.ts @@ -3,3 +3,8 @@ export enum Themes { Light = 'light', Dark = 'dark', } + +export enum Closer { + Minimize = 'minimize', + Close = 'close', +}