✨ 2.0 Upgrade Plan
This commit is contained in:
@@ -10,6 +10,7 @@ pub struct WindowConfig {
|
||||
pub resizable: bool,
|
||||
pub url_type: String,
|
||||
pub always_on_top: bool,
|
||||
pub dark_mode: bool,
|
||||
pub disabled_web_shortcuts: bool,
|
||||
pub activation_shortcut: String,
|
||||
}
|
||||
|
||||
@@ -3,8 +3,8 @@ use std::fs::{self, File};
|
||||
use std::io::Write;
|
||||
use std::str::FromStr;
|
||||
use tauri::http::Method;
|
||||
use tauri_plugin_http::reqwest::{ClientBuilder, Request};
|
||||
use tauri::{command, AppHandle, Manager, Url, WebviewWindow};
|
||||
use tauri_plugin_http::reqwest::{ClientBuilder, Request};
|
||||
|
||||
#[derive(serde::Deserialize)]
|
||||
pub struct DownloadFileParams {
|
||||
|
||||
@@ -1,14 +1,11 @@
|
||||
use tauri::{
|
||||
image::Image,
|
||||
menu::{MenuBuilder, MenuItemBuilder},
|
||||
tray::{MouseButton, MouseButtonState, TrayIconBuilder, TrayIconEvent},
|
||||
tray::TrayIconBuilder,
|
||||
AppHandle, Manager,
|
||||
};
|
||||
use tauri_plugin_window_state::{AppHandleExt, StateFlags};
|
||||
|
||||
use super::config::PakeConfig;
|
||||
|
||||
pub fn set_system_tray(app: &AppHandle, pake_config: &PakeConfig) -> tauri::Result<()> {
|
||||
pub fn set_system_tray(app: &AppHandle) -> tauri::Result<()> {
|
||||
let hide_app = MenuItemBuilder::with_id("hide_app", "Hide").build(app)?;
|
||||
let show_app = MenuItemBuilder::with_id("show_app", "Show").build(app)?;
|
||||
let quit = MenuItemBuilder::with_id("quit", "Quit").build(app)?;
|
||||
@@ -17,32 +14,7 @@ pub fn set_system_tray(app: &AppHandle, pake_config: &PakeConfig) -> tauri::Resu
|
||||
.build()?;
|
||||
app.app_handle().remove_tray_by_id("pake-tray");
|
||||
let tray = TrayIconBuilder::new()
|
||||
.icon(Image::from_path(pake_config.system_tray_path.as_str())?)
|
||||
.menu(&menu)
|
||||
.on_tray_icon_event(move |tray, event| {
|
||||
if let TrayIconEvent::Click {
|
||||
button: MouseButton::Left,
|
||||
button_state: MouseButtonState::Up,
|
||||
..
|
||||
} = event
|
||||
{
|
||||
println!("click");
|
||||
|
||||
let app = tray.app_handle();
|
||||
|
||||
#[cfg(not(target_os = "macos"))]
|
||||
{
|
||||
if let Some(webview_window) = app.get_webview_window("pake") {
|
||||
let _ = webview_window.show();
|
||||
let _ = webview_window.set_focus();
|
||||
}
|
||||
}
|
||||
#[cfg(target_os = "macos")]
|
||||
{
|
||||
tauri::AppHandle::show(&app.app_handle()).unwrap();
|
||||
}
|
||||
}
|
||||
})
|
||||
.on_menu_event(move |app, event| match event.id().as_ref() {
|
||||
"hide_app" => {
|
||||
app.get_webview_window("pake").unwrap().minimize().unwrap();
|
||||
|
||||
@@ -3,7 +3,7 @@ use std::{path::PathBuf, str::FromStr};
|
||||
use tauri::{App, Url, WebviewUrl, WebviewWindow, WebviewWindowBuilder};
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
use tauri::TitleBarStyle;
|
||||
use tauri::{Theme, TitleBarStyle};
|
||||
|
||||
pub fn get_window(app: &mut App, config: &PakeConfig, _data_dir: PathBuf) -> WebviewWindow {
|
||||
let window_config = config
|
||||
@@ -31,7 +31,6 @@ pub fn get_window(app: &mut App, config: &PakeConfig, _data_dir: PathBuf) -> Web
|
||||
.resizable(window_config.resizable)
|
||||
.fullscreen(window_config.fullscreen)
|
||||
.inner_size(window_config.width, window_config.height)
|
||||
.disable_drag_drop_handler()
|
||||
.always_on_top(window_config.always_on_top)
|
||||
.initialization_script(&config_script)
|
||||
.initialization_script(include_str!("../inject/component.js"))
|
||||
@@ -41,7 +40,6 @@ pub fn get_window(app: &mut App, config: &PakeConfig, _data_dir: PathBuf) -> Web
|
||||
.initialization_script(include_str!("../inject/custom.js"));
|
||||
|
||||
if config.proxy_url != "" {
|
||||
println!("{}", &config.proxy_url);
|
||||
window_builder =
|
||||
window_builder.proxy_url(Url::from_str(&config.proxy_url.as_str()).unwrap());
|
||||
}
|
||||
@@ -53,12 +51,18 @@ pub fn get_window(app: &mut App, config: &PakeConfig, _data_dir: PathBuf) -> Web
|
||||
} else {
|
||||
TitleBarStyle::Visible
|
||||
};
|
||||
window_builder = window_builder.title_bar_style(title_bar_style)
|
||||
window_builder = window_builder.title_bar_style(title_bar_style);
|
||||
|
||||
if window_config.dark_mode {
|
||||
window_builder = window_builder.theme(Some(Theme::Dark));
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "macos"))]
|
||||
{
|
||||
window_builder = window_builder.data_directory(_data_dir);
|
||||
window_builder = window_builder
|
||||
.data_directory(_data_dir)
|
||||
.title(app.package_info().name.clone());
|
||||
}
|
||||
|
||||
window_builder.build().expect("Failed to build window")
|
||||
|
||||
Reference in New Issue
Block a user