2024-11-30 15:29:00 +08:00
|
|
|
use std::{fs::create_dir, io::Read};
|
|
|
|
|
|
2024-12-26 10:08:55 +08:00
|
|
|
use tauri::{AppHandle, Emitter, Listener, Manager, Runtime, WebviewWindow};
|
2025-01-02 14:41:54 +08:00
|
|
|
use tauri_nspanel::{panel_delegate, ManagerExt, WebviewWindowExt};
|
2024-12-11 09:07:27 +08:00
|
|
|
use tauri_plugin_autostart::MacosLauncher;
|
2024-12-11 10:45:54 +08:00
|
|
|
use tauri_plugin_global_shortcut::{GlobalShortcutExt, Shortcut};
|
2024-11-30 15:29:00 +08:00
|
|
|
|
2024-12-14 15:38:32 +08:00
|
|
|
mod autostart;
|
|
|
|
|
use autostart::{change_autostart, enable_autostart};
|
|
|
|
|
|
2024-12-22 15:35:05 +08:00
|
|
|
#[cfg(target_os = "macos")]
|
|
|
|
|
use tauri::ActivationPolicy;
|
|
|
|
|
|
2024-12-14 15:38:32 +08:00
|
|
|
#[cfg(target_os = "macos")]
|
2024-11-30 15:29:00 +08:00
|
|
|
const DEFAULT_SHORTCUT: &str = "command+shift+space";
|
|
|
|
|
|
2024-12-14 15:38:32 +08:00
|
|
|
#[cfg(any(target_os = "windows", target_os = "linux"))]
|
|
|
|
|
const DEFAULT_SHORTCUT: &str = "ctrl+shift+space";
|
|
|
|
|
|
2024-10-13 17:41:16 +08:00
|
|
|
// Learn more about Tauri commands at https://tauri.app/v1/guides/features/command
|
|
|
|
|
#[tauri::command]
|
|
|
|
|
fn greet(name: &str) -> String {
|
|
|
|
|
format!("Hello, {}! You've been greeted from Rust!", name)
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-30 15:29:00 +08:00
|
|
|
#[tauri::command]
|
|
|
|
|
fn change_window_height(handle: AppHandle, height: u32) {
|
|
|
|
|
let window: WebviewWindow = handle.get_webview_window("main").unwrap();
|
|
|
|
|
|
|
|
|
|
let mut size = window.outer_size().unwrap();
|
|
|
|
|
size.height = height;
|
|
|
|
|
window.set_size(size).unwrap();
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-02 14:41:54 +08:00
|
|
|
#[tauri::command]
|
|
|
|
|
fn show_panel(handle: AppHandle) {
|
|
|
|
|
let panel = handle.get_webview_panel("main").unwrap();
|
|
|
|
|
|
|
|
|
|
panel.show();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[tauri::command]
|
|
|
|
|
fn hide_panel(handle: AppHandle) {
|
|
|
|
|
let panel = handle.get_webview_panel("main").unwrap();
|
|
|
|
|
|
|
|
|
|
panel.order_out(None);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[tauri::command]
|
|
|
|
|
fn close_panel(handle: AppHandle) {
|
|
|
|
|
let panel = handle.get_webview_panel("main").unwrap();
|
|
|
|
|
|
|
|
|
|
panel.released_when_closed(true);
|
|
|
|
|
|
|
|
|
|
panel.close();
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-26 10:08:55 +08:00
|
|
|
#[derive(serde::Deserialize)]
|
|
|
|
|
struct ThemeChangedPayload {
|
|
|
|
|
is_dark_mode: bool,
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-13 17:41:16 +08:00
|
|
|
#[cfg_attr(mobile, tauri::mobile_entry_point)]
|
|
|
|
|
pub fn run() {
|
2024-12-19 12:06:40 +08:00
|
|
|
let mut ctx = tauri::generate_context!();
|
|
|
|
|
|
2024-10-13 17:41:16 +08:00
|
|
|
tauri::Builder::default()
|
2025-01-02 14:41:54 +08:00
|
|
|
.plugin(tauri_nspanel::init())
|
2024-10-28 17:34:48 +08:00
|
|
|
.plugin(tauri_plugin_http::init())
|
2024-10-13 17:41:16 +08:00
|
|
|
.plugin(tauri_plugin_shell::init())
|
2024-12-11 10:45:54 +08:00
|
|
|
.plugin(tauri_plugin_autostart::init(
|
|
|
|
|
MacosLauncher::AppleScript,
|
|
|
|
|
None,
|
|
|
|
|
))
|
2024-12-19 12:06:40 +08:00
|
|
|
.plugin(tauri_plugin_theme::init(ctx.config_mut()))
|
2024-11-30 15:29:00 +08:00
|
|
|
.invoke_handler(tauri::generate_handler![
|
|
|
|
|
greet,
|
|
|
|
|
change_window_height,
|
|
|
|
|
change_shortcut,
|
2024-12-16 14:31:03 +08:00
|
|
|
get_current_shortcut,
|
2024-12-14 15:38:32 +08:00
|
|
|
change_autostart,
|
2024-12-24 18:24:53 +08:00
|
|
|
hide_coco,
|
2024-12-26 14:22:20 +08:00
|
|
|
switch_tray_icon,
|
2025-01-02 14:41:54 +08:00
|
|
|
show_panel,
|
|
|
|
|
hide_panel,
|
|
|
|
|
close_panel
|
2024-11-30 15:29:00 +08:00
|
|
|
])
|
|
|
|
|
.setup(|app| {
|
|
|
|
|
init(app.app_handle());
|
|
|
|
|
|
|
|
|
|
enable_shortcut(app);
|
2024-11-30 20:41:47 +08:00
|
|
|
enable_tray(app);
|
2024-12-14 15:38:32 +08:00
|
|
|
enable_autostart(app);
|
2024-11-30 15:29:00 +08:00
|
|
|
|
2024-12-17 11:20:50 +08:00
|
|
|
#[cfg(target_os = "macos")]
|
|
|
|
|
app.set_activation_policy(ActivationPolicy::Accessory);
|
|
|
|
|
|
2024-12-26 10:08:55 +08:00
|
|
|
app.listen("theme-changed", move |event| {
|
|
|
|
|
if let Ok(payload) = serde_json::from_str::<ThemeChangedPayload>(&event.payload()) {
|
|
|
|
|
// switch_tray_icon(app.app_handle(), payload.is_dark_mode);
|
|
|
|
|
println!("Theme changed: is_dark_mode = {}", payload.is_dark_mode);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2024-11-30 15:29:00 +08:00
|
|
|
Ok(())
|
|
|
|
|
})
|
2024-12-19 12:06:40 +08:00
|
|
|
.run(ctx)
|
2024-10-13 17:41:16 +08:00
|
|
|
.expect("error while running tauri application");
|
|
|
|
|
}
|
2024-11-30 15:29:00 +08:00
|
|
|
|
2025-01-02 14:41:54 +08:00
|
|
|
fn init(app_handle: &AppHandle) {
|
|
|
|
|
let window: WebviewWindow = app_handle.get_webview_window("main").unwrap();
|
|
|
|
|
|
|
|
|
|
let panel = window.to_panel().unwrap();
|
|
|
|
|
|
|
|
|
|
let delegate = panel_delegate!(MyPanelDelegate {
|
|
|
|
|
window_did_become_key,
|
|
|
|
|
window_did_resign_key
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
let handle = app_handle.to_owned();
|
|
|
|
|
|
|
|
|
|
delegate.set_listener(Box::new(move |delegate_name: String| {
|
|
|
|
|
match delegate_name.as_str() {
|
|
|
|
|
"window_did_become_key" => {
|
|
|
|
|
let app_name = handle.package_info().name.to_owned();
|
|
|
|
|
|
|
|
|
|
println!("[info]: {:?} panel becomes key window!", app_name);
|
|
|
|
|
}
|
|
|
|
|
"window_did_resign_key" => {
|
|
|
|
|
println!("[info]: panel resigned from key window!");
|
|
|
|
|
}
|
|
|
|
|
_ => (),
|
|
|
|
|
}
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
panel.set_delegate(delegate);
|
|
|
|
|
}
|
2024-11-30 15:29:00 +08:00
|
|
|
|
|
|
|
|
fn enable_shortcut(app: &mut tauri::App) {
|
|
|
|
|
use tauri_plugin_global_shortcut::{GlobalShortcutExt, Shortcut, ShortcutState};
|
|
|
|
|
|
|
|
|
|
let window = app.get_webview_window("main").unwrap();
|
|
|
|
|
|
|
|
|
|
let command_shortcut: Shortcut = current_shortcut(app.app_handle()).unwrap();
|
|
|
|
|
|
|
|
|
|
app.handle()
|
|
|
|
|
.plugin(
|
|
|
|
|
tauri_plugin_global_shortcut::Builder::new()
|
|
|
|
|
.with_handler(move |_app, shortcut, event| {
|
|
|
|
|
//println!("{:?}", shortcut);
|
|
|
|
|
if shortcut == &command_shortcut {
|
|
|
|
|
if let ShortcutState::Pressed = event.state() {
|
2024-12-22 15:35:05 +08:00
|
|
|
if window.is_visible().unwrap() {
|
2024-11-30 15:29:00 +08:00
|
|
|
window.hide().unwrap();
|
|
|
|
|
} else {
|
|
|
|
|
window.show().unwrap();
|
|
|
|
|
window.set_focus().unwrap();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.build(),
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
|
|
app.global_shortcut().register(command_shortcut).unwrap();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[tauri::command]
|
|
|
|
|
fn change_shortcut<R: Runtime>(
|
|
|
|
|
app: tauri::AppHandle<R>,
|
2024-12-13 14:49:47 +08:00
|
|
|
_window: tauri::Window<R>,
|
2024-11-30 15:29:00 +08:00
|
|
|
key: String,
|
|
|
|
|
) -> Result<(), String> {
|
|
|
|
|
use std::fs::File;
|
|
|
|
|
use std::io::Write;
|
|
|
|
|
use tauri_plugin_global_shortcut::ShortcutState;
|
|
|
|
|
|
2024-12-13 14:49:47 +08:00
|
|
|
if let Err(e) = remove_shortcut(&app) {
|
|
|
|
|
eprintln!("Failed to remove old shortcut: {}", e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let main_window = app.get_webview_window("main").unwrap();
|
2024-11-30 15:29:00 +08:00
|
|
|
|
2024-12-10 13:38:31 +08:00
|
|
|
let shortcut: Shortcut = key
|
|
|
|
|
.parse()
|
|
|
|
|
.map_err(|_| "The format of the shortcut key is incorrect".to_owned())?;
|
2024-11-30 15:29:00 +08:00
|
|
|
app.global_shortcut()
|
|
|
|
|
.on_shortcut(shortcut, move |_app, scut, event| {
|
|
|
|
|
if scut == &shortcut {
|
|
|
|
|
if let ShortcutState::Pressed = event.state() {
|
2024-12-20 18:53:41 +08:00
|
|
|
if main_window.is_visible().unwrap() {
|
2024-12-13 14:49:47 +08:00
|
|
|
main_window.hide().unwrap();
|
2024-11-30 15:29:00 +08:00
|
|
|
} else {
|
2024-12-13 14:49:47 +08:00
|
|
|
main_window.show().unwrap();
|
|
|
|
|
main_window.set_focus().unwrap();
|
2024-11-30 15:29:00 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
})
|
2024-12-06 10:05:23 +08:00
|
|
|
.map_err(|_| "Failed to register new shortcut key".to_owned())?;
|
2024-11-30 15:29:00 +08:00
|
|
|
|
|
|
|
|
let path = app.path().app_config_dir().unwrap();
|
|
|
|
|
if path.exists() == false {
|
|
|
|
|
create_dir(&path).unwrap();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let file_path = path.join("shortcut.txt");
|
|
|
|
|
let mut file = File::create(file_path).unwrap();
|
|
|
|
|
file.write_all(key.as_bytes()).unwrap();
|
|
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-16 14:31:03 +08:00
|
|
|
#[tauri::command]
|
|
|
|
|
fn get_current_shortcut<R: Runtime>(app: tauri::AppHandle<R>) -> Result<String, String> {
|
|
|
|
|
let res = current_shortcut(&app)?;
|
|
|
|
|
|
|
|
|
|
Ok(res.into_string())
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-24 18:24:53 +08:00
|
|
|
#[tauri::command]
|
|
|
|
|
fn hide_coco(app: tauri::AppHandle) {
|
|
|
|
|
if let Some(window) = app.get_window("main") {
|
|
|
|
|
match window.is_visible() {
|
|
|
|
|
Ok(true) => {
|
|
|
|
|
if let Err(err) = window.hide() {
|
|
|
|
|
eprintln!("Failed to hide the window: {}", err);
|
|
|
|
|
} else {
|
|
|
|
|
println!("Window successfully hidden.");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Ok(false) => {
|
|
|
|
|
println!("Window is already hidden.");
|
|
|
|
|
}
|
|
|
|
|
Err(err) => {
|
|
|
|
|
eprintln!("Failed to check window visibility: {}", err);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
eprintln!("Main window not found.");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-30 15:29:00 +08:00
|
|
|
fn current_shortcut<R: Runtime>(app: &tauri::AppHandle<R>) -> Result<Shortcut, String> {
|
|
|
|
|
use std::fs::File;
|
|
|
|
|
|
|
|
|
|
let path = app.path().app_config_dir().unwrap();
|
2024-12-04 16:58:32 +08:00
|
|
|
let mut old_value = DEFAULT_SHORTCUT.to_owned();
|
|
|
|
|
|
|
|
|
|
if path.exists() {
|
2024-11-30 15:29:00 +08:00
|
|
|
let file_path = path.join("shortcut.txt");
|
2024-12-04 16:58:32 +08:00
|
|
|
if file_path.exists() {
|
|
|
|
|
let mut file = File::open(file_path).unwrap();
|
|
|
|
|
let mut data = String::new();
|
|
|
|
|
if let Ok(_) = file.read_to_string(&mut data) {
|
|
|
|
|
if data.is_empty() == false {
|
|
|
|
|
old_value = data
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-11-30 15:29:00 +08:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
let short: Shortcut = old_value.parse().unwrap();
|
|
|
|
|
|
|
|
|
|
Ok(short)
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-14 15:38:32 +08:00
|
|
|
#[allow(dead_code)]
|
2024-11-30 15:29:00 +08:00
|
|
|
fn remove_shortcut<R: Runtime>(app: &tauri::AppHandle<R>) -> Result<(), String> {
|
|
|
|
|
let short = current_shortcut(app)?;
|
|
|
|
|
|
|
|
|
|
app.global_shortcut().unregister(short).unwrap();
|
|
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
2024-11-30 20:41:47 +08:00
|
|
|
|
2024-12-17 11:20:50 +08:00
|
|
|
fn handle_open_coco(app: &AppHandle) {
|
|
|
|
|
println!("Open Coco menu clicked!");
|
|
|
|
|
|
|
|
|
|
if let Some(window) = app.get_window("main") {
|
|
|
|
|
window.show().unwrap();
|
|
|
|
|
window.set_focus().unwrap();
|
|
|
|
|
} else {
|
|
|
|
|
eprintln!("Failed to get main window.");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-24 18:24:53 +08:00
|
|
|
fn handle_hide_coco(app: &AppHandle) {
|
|
|
|
|
println!("Hide Coco menu clicked!");
|
|
|
|
|
|
|
|
|
|
if let Some(window) = app.get_window("main") {
|
|
|
|
|
if let Err(err) = window.hide() {
|
|
|
|
|
eprintln!("Failed to hide the window: {}", err);
|
|
|
|
|
} else {
|
|
|
|
|
println!("Window successfully hidden.");
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
eprintln!("Main window not found.");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-26 14:22:20 +08:00
|
|
|
#[tauri::command]
|
|
|
|
|
fn switch_tray_icon(app: tauri::AppHandle, is_dark_mode: bool) {
|
|
|
|
|
let app_handle = app.app_handle();
|
|
|
|
|
|
|
|
|
|
println!("is_dark_mode: {}", is_dark_mode);
|
|
|
|
|
|
|
|
|
|
const DARK_ICON_PATH: &[u8] = include_bytes!("../icons/dark@2x.png");
|
|
|
|
|
const LIGHT_ICON_PATH: &[u8] = include_bytes!("../icons/light@2x.png");
|
|
|
|
|
|
|
|
|
|
let icon_path: &[u8] = if is_dark_mode {
|
|
|
|
|
DARK_ICON_PATH
|
2024-12-26 10:08:55 +08:00
|
|
|
} else {
|
2024-12-26 14:22:20 +08:00
|
|
|
LIGHT_ICON_PATH
|
2024-12-26 10:08:55 +08:00
|
|
|
};
|
|
|
|
|
|
2024-12-26 14:22:20 +08:00
|
|
|
let tray = match app_handle.tray_by_id("tray") {
|
|
|
|
|
Some(tray) => tray,
|
|
|
|
|
None => {
|
|
|
|
|
eprintln!("Tray with ID 'tray' not found");
|
|
|
|
|
return;
|
|
|
|
|
}
|
2024-12-26 10:08:55 +08:00
|
|
|
};
|
2024-12-26 14:22:20 +08:00
|
|
|
|
|
|
|
|
if let Err(e) = tray.set_icon(Some(
|
|
|
|
|
tauri::image::Image::from_bytes(icon_path)
|
|
|
|
|
.unwrap_or_else(|e| panic!("Failed to load icon from bytes: {}", e)),
|
|
|
|
|
)) {
|
|
|
|
|
eprintln!("Failed to set tray icon: {}", e);
|
|
|
|
|
}
|
2024-12-26 10:08:55 +08:00
|
|
|
}
|
|
|
|
|
|
2024-11-30 20:41:47 +08:00
|
|
|
fn enable_tray(app: &mut tauri::App) {
|
|
|
|
|
use tauri::{
|
2024-12-25 17:43:56 +08:00
|
|
|
image::Image,
|
2024-12-11 16:52:13 +08:00
|
|
|
menu::{MenuBuilder, MenuItem},
|
2024-11-30 20:41:47 +08:00
|
|
|
tray::TrayIconBuilder,
|
|
|
|
|
};
|
|
|
|
|
|
2024-12-11 16:52:13 +08:00
|
|
|
let quit_i = MenuItem::with_id(app, "quit", "Quit Coco", true, None::<&str>).unwrap();
|
2024-12-17 16:25:45 +08:00
|
|
|
let settings_i = MenuItem::with_id(app, "settings", "Settings...", true, None::<&str>).unwrap();
|
2024-12-11 10:45:54 +08:00
|
|
|
let open_i = MenuItem::with_id(app, "open", "Open Coco", true, None::<&str>).unwrap();
|
2024-12-17 16:25:45 +08:00
|
|
|
let about_i = MenuItem::with_id(app, "about", "About Coco", true, None::<&str>).unwrap();
|
2024-12-24 18:24:53 +08:00
|
|
|
let hide_i = MenuItem::with_id(app, "hide", "Hide Coco", true, None::<&str>).unwrap();
|
2024-12-11 10:45:54 +08:00
|
|
|
|
2024-12-11 16:52:13 +08:00
|
|
|
let menu = MenuBuilder::new(app)
|
|
|
|
|
.item(&open_i)
|
2024-12-17 16:25:45 +08:00
|
|
|
.separator()
|
2024-12-24 18:24:53 +08:00
|
|
|
.item(&hide_i)
|
2024-12-17 16:25:45 +08:00
|
|
|
.item(&about_i)
|
2024-12-11 16:52:13 +08:00
|
|
|
.item(&settings_i)
|
|
|
|
|
.separator()
|
|
|
|
|
.item(&quit_i)
|
|
|
|
|
.build()
|
|
|
|
|
.unwrap();
|
|
|
|
|
|
2024-12-26 10:08:55 +08:00
|
|
|
let _tray = TrayIconBuilder::with_id("tray")
|
2024-12-25 17:43:56 +08:00
|
|
|
// .icon(app.default_window_icon().unwrap().clone())
|
|
|
|
|
.icon(Image::from_bytes(include_bytes!("../icons/light@2x.png")).expect("REASON"))
|
2024-11-30 20:41:47 +08:00
|
|
|
.menu(&menu)
|
|
|
|
|
.on_menu_event(|app, event| match event.id.as_ref() {
|
2024-12-17 16:25:45 +08:00
|
|
|
"open" => {
|
2024-12-17 11:20:50 +08:00
|
|
|
handle_open_coco(app);
|
2024-12-11 10:45:54 +08:00
|
|
|
}
|
2024-12-24 18:24:53 +08:00
|
|
|
"hide" => {
|
|
|
|
|
handle_hide_coco(app);
|
|
|
|
|
}
|
2024-12-17 16:25:45 +08:00
|
|
|
"about" => {
|
|
|
|
|
let _ = app.emit("open_settings", "about");
|
|
|
|
|
}
|
2024-12-10 13:38:31 +08:00
|
|
|
"settings" => {
|
2024-12-22 15:35:05 +08:00
|
|
|
// windows failed to open second window, issue: https://github.com/tauri-apps/tauri/issues/11144 https://github.com/tauri-apps/tauri/issues/8196
|
2024-12-14 15:38:32 +08:00
|
|
|
//#[cfg(windows)]
|
2024-12-15 21:06:23 +08:00
|
|
|
let _ = app.emit("open_settings", "");
|
2024-12-14 15:38:32 +08:00
|
|
|
|
|
|
|
|
// #[cfg(not(windows))]
|
2024-12-22 15:35:05 +08:00
|
|
|
// open_settings(&app);
|
2024-12-10 13:38:31 +08:00
|
|
|
}
|
2024-11-30 20:41:47 +08:00
|
|
|
"quit" => {
|
|
|
|
|
println!("quit menu item was clicked");
|
|
|
|
|
app.exit(0);
|
|
|
|
|
}
|
|
|
|
|
_ => {
|
|
|
|
|
println!("menu item {:?} not handled", event.id);
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.build(app)
|
|
|
|
|
.unwrap();
|
|
|
|
|
}
|
2024-12-14 15:38:32 +08:00
|
|
|
|
2024-12-15 21:06:23 +08:00
|
|
|
#[allow(dead_code)]
|
2024-12-22 15:35:05 +08:00
|
|
|
fn open_settings(app: &tauri::AppHandle) {
|
2024-12-15 21:06:23 +08:00
|
|
|
use tauri::webview::WebviewBuilder;
|
2024-12-14 15:38:32 +08:00
|
|
|
println!("settings menu item was clicked");
|
|
|
|
|
let window = app.get_webview_window("settings");
|
|
|
|
|
if let Some(window) = window {
|
|
|
|
|
window.show().unwrap();
|
|
|
|
|
window.set_focus().unwrap();
|
|
|
|
|
} else {
|
|
|
|
|
let window = tauri::window::WindowBuilder::new(app, "settings")
|
|
|
|
|
.title("Settings Window")
|
|
|
|
|
.fullscreen(false)
|
2024-12-17 16:25:45 +08:00
|
|
|
.resizable(false)
|
|
|
|
|
.minimizable(false)
|
|
|
|
|
.maximizable(false)
|
|
|
|
|
.inner_size(800.0, 600.0)
|
2024-12-14 15:38:32 +08:00
|
|
|
.build()
|
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
|
|
let webview_builder =
|
|
|
|
|
WebviewBuilder::new("settings", tauri::WebviewUrl::App("/ui/settings".into()));
|
|
|
|
|
let _webview = window
|
|
|
|
|
.add_child(
|
|
|
|
|
webview_builder,
|
|
|
|
|
tauri::LogicalPosition::new(0, 0),
|
|
|
|
|
window.inner_size().unwrap(),
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
|
|
|
|
}
|
|
|
|
|
}
|