fix: close (#349)

This commit is contained in:
lencx
2023-02-12 23:33:23 +08:00
parent 522f7b86b8
commit 7479ee905f
3 changed files with 43 additions and 4 deletions

View File

@@ -34,6 +34,8 @@ pub_struct!(AppConf {
// macOS and Windows: light / dark / system
theme: String,
// auto update policy: prompt / silent / disable
isinit: bool,
main_close: bool,
auto_update: String,
tray: bool,
popup_search: bool,
@@ -58,6 +60,8 @@ impl AppConf {
auto_update: "prompt".into(),
tray: true,
popup_search: false,
isinit: true,
main_close: false,
stay_on_top: false,
main_dashboard: false,
tray_dashboard: false,

View File

@@ -91,13 +91,34 @@ async fn main() {
builder
.on_menu_event(menu::menu_handler)
.on_system_tray_event(menu::tray_handler)
.on_window_event(|event| {
.on_window_event(move |event| {
if let tauri::WindowEvent::CloseRequested { api, .. } = event.event() {
let win = event.window();
let win = event.window().clone();
let app_conf = AppConf::read();
if win.label() == "core" {
event.window().minimize().unwrap();
if app_conf.isinit {
tauri::api::dialog::ask(
Some(event.window()),
"",
"Do you want to exit the application when you click the [x] button?",
move |is_ok| {
app_conf
.amend(serde_json::json!({ "isinit" : false, "main_close": is_ok }))
.write();
if is_ok {
std::process::exit(0);
} else {
win.minimize().unwrap();
}
},
);
} else if app_conf.main_close {
std::process::exit(0);
} else {
win.minimize().unwrap();
}
} else {
win.close().unwrap();
event.window().close().unwrap();
}
api.prevent_close();
}

View File

@@ -30,12 +30,26 @@ const PopupSearchLabel = () => {
);
};
const MainCloseLabel = () => {
return (
<span>
Close Exit{' '}
<Tooltip title="Click the close button whether to exit directly, the default minimized.">
<QuestionCircleOutlined style={{ color: '#1677ff' }} />
</Tooltip>
</span>
);
};
export default function MainWindow() {
return (
<>
<Form.Item label={<PopupSearchLabel />} name="popup_search" valuePropName="checked">
<Switch />
</Form.Item>
<Form.Item label={<MainCloseLabel />} name="main_close" valuePropName="checked">
<Switch />
</Form.Item>
<SwitchOrigin name="main" />
<Form.Item label="User Agent (Main)" name="ua_window">
<Input.TextArea