feat: custom window decorations

This commit is contained in:
GyDi
2022-01-08 22:23:48 +08:00
parent ea8f1c52f9
commit e86d192db7
10 changed files with 194 additions and 648 deletions

View File

@@ -8,7 +8,7 @@ use crate::{
},
};
use serde_yaml::Mapping;
use tauri::State;
use tauri::{AppHandle, Manager, State};
/// get all profiles from `profiles.yaml`
/// do not acquire the lock of ProfileLock
@@ -246,3 +246,25 @@ pub async fn patch_verge_config(
verge.config.save_file()
}
/// start dragging window
#[tauri::command]
pub fn win_drag(app_handle: AppHandle) {
let window = app_handle.get_window("main").unwrap();
window.start_dragging().unwrap();
}
/// hide the window
#[tauri::command]
pub fn win_hide(app_handle: AppHandle) {
let window = app_handle.get_window("main").unwrap();
window.hide().unwrap();
}
/// mini the window
#[tauri::command]
pub fn win_mini(app_handle: AppHandle) {
let window = app_handle.get_window("main").unwrap();
// todo: these methods still has bug on Windows
window.minimize().unwrap();
}

View File

@@ -62,14 +62,21 @@ fn main() -> std::io::Result<()> {
_ => {}
})
.invoke_handler(tauri::generate_handler![
// common
cmds::restart_sidecar,
cmds::set_sys_proxy,
cmds::get_sys_proxy,
cmds::get_cur_proxy,
cmds::win_drag,
cmds::win_hide,
cmds::win_mini,
// clash
cmds::get_clash_info,
cmds::patch_clash_config,
// verge
cmds::get_verge_config,
cmds::patch_verge_config,
// profile
cmds::import_profile,
cmds::update_profile,
cmds::delete_profile,
@@ -86,10 +93,7 @@ fn main() -> std::io::Result<()> {
api.prevent_close();
app_handle.get_window(&label).unwrap().hide().unwrap();
}
tauri::Event::ExitRequested { api, .. } => {
api.prevent_exit();
}
tauri::Event::Exit => {
tauri::Event::ExitRequested { .. } => {
resolve::resolve_reset(app_handle);
api::process::kill_children();
}

View File

@@ -1,9 +1,14 @@
use super::{init, server};
use crate::{core::ProfilesConfig, states};
use tauri::{App, AppHandle, Manager};
use tauri_plugin_shadows::Shadows;
/// handle something when start app
pub fn resolve_setup(app: &App) {
// set shadow when window decorations
let window = app.get_window("main").unwrap();
window.set_shadow(true);
// setup a simple http server for singleton
server::embed_server(&app.handle());
@@ -34,7 +39,7 @@ pub fn resolve_setup(app: &App) {
/// reset system proxy
pub fn resolve_reset(app_handle: &AppHandle) {
let verge_state = app_handle.state::<states::VergeState>();
let mut verge_arc = verge_state.0.lock().unwrap();
let mut verge = verge_state.0.lock().unwrap();
verge_arc.reset_sysproxy();
verge.reset_sysproxy();
}