Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: ✨ 添加关闭窗口选项 #283

Merged
merged 1 commit into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/main/src/main.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ declare interface AppStore {
autoUpgrade: boolean;
// 允许使用beta版本
allowBeta: boolean;
// 关闭主窗口
closeMainWindow: boolean;
}

declare interface BrowserStore {
Expand Down
1 change: 1 addition & 0 deletions packages/main/src/vendor/ElectronStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export default class StoreService extends Store<AppStore> implements Vendor {
downloadProxySwitch: false,
autoUpgrade: true,
allowBeta: false,
closeMainWindow: false,
},
});
}
Expand Down
8 changes: 8 additions & 0 deletions packages/main/src/windows/MainWindow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@ export default class MainWindow extends Window {
app.on("second-instance", this.secondInstance);
}

closeMainWindow = () => {
const { closeMainWindow } = this.store.store;
if (closeMainWindow) {
app.quit();
}
};

onDownloadReadyStart = async ({ id, isLive }: DownloadProgress) => {
if (isLive) {
await this.videoRepository.changeVideoIsLive(id);
Expand All @@ -74,6 +81,7 @@ export default class MainWindow extends Window {

// 处理当前窗口改变大小
this.window.on("resized", this.handleResize);
this.window.on("close", this.closeMainWindow);
}

handleResize = () => {
Expand Down
10 changes: 10 additions & 0 deletions packages/renderer/src/i18n/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,11 @@ Referer: http://www.example.com`,
updateModal: "Update",
update: "Update",
install: "Install",
checkingForUpdates: "Checking for updates",
updateAvailable: "Update available",
updateNotAvailable: "Update not available",
closeMainWindow: "Close Main Window",
minimizeToTray: "Minimize to tray",
},
},
zh: {
Expand Down Expand Up @@ -312,6 +317,11 @@ Referer: http://www.example.com`,
updateModal: "更新",
update: "更新",
install: "安装",
checkingForUpdates: "正在检查更新",
updateAvailable: "发现新版本",
updateNotAvailable: "当前已是最新版本",
closeMainWindow: "关闭主窗口",
minimizeToTray: "最小化到托盘",
},
},
},
Expand Down
13 changes: 10 additions & 3 deletions packages/renderer/src/pages/SettingPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
message,
Modal,
Progress,
Radio,
Select,
Space,
Switch,
Expand Down Expand Up @@ -265,6 +266,12 @@ const SettingPage: React.FC = () => {
>
<Switch />
</Form.Item>
<Form.Item label={t("closeMainWindow")} name="closeMainWindow">
<Radio.Group>
<Radio value={true}>{t("close")}</Radio>
<Radio value={false}>{t("minimizeToTray")}</Radio>
</Radio.Group>
</Form.Item>
</GroupWrapper>
<GroupWrapper title={t("browserSetting")}>
<Form.Item name="proxy" label={t("proxySetting")}>
Expand Down Expand Up @@ -423,10 +430,10 @@ const SettingPage: React.FC = () => {
>
<div className="flex min-h-28 flex-col justify-center">
{updateChecking
? "正在检查更新"
? t("checkingForUpdates")
: updateAvailable
? "有新版本"
: "当前已是最新版本"}
? t("updateAvailable")
: t("updateNotAvailable")}
{!updateChecking && updateAvailable && (
<Progress percent={updateDownloaded ? 100 : downloadProgress} />
)}
Expand Down