Skip to content

Commit

Permalink
fix: 修复托盘启动窗口不一致
Browse files Browse the repository at this point in the history
  • Loading branch information
Pylogmon committed Mar 23, 2023
1 parent 670a742 commit d8c206b
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 47 deletions.
2 changes: 0 additions & 2 deletions src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ arboard = "3.2.0"
window-shadows = "0.2"

[target.'cfg(target_os = "macos")'.dependencies ]
enigo = {git = "https://github.com/enigo-rs/enigo"}
arboard = "3.2.0"
window-shadows = "0.2"
core-graphics = "0.22.3"

Expand Down
47 changes: 3 additions & 44 deletions src-tauri/src/trayicon.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
use tauri::{AppHandle, CustomMenuItem, Manager, PhysicalSize, SystemTray, SystemTrayMenu};
#[cfg(target_os = "windows")]
use window_shadows::set_shadow;
#[cfg(target_os = "macos")]
use window_shadows::set_shadow;
use crate::window::build_window;
use tauri::{AppHandle, CustomMenuItem, Manager, SystemTray, SystemTrayMenu};

pub const CONFIG_TRAY_ITEM: &str = "config";
pub const QUIT_TRAY_ITEM: &str = "quit";
Expand All @@ -27,45 +24,7 @@ pub fn on_persistent_click(app: &AppHandle) {
window.close().unwrap();
}
None => {
let builder = tauri::WindowBuilder::new(
app,
"persistent",
tauri::WindowUrl::App("index_translator.html".into()),
)
.inner_size(400.0, 500.0)
.min_inner_size(400.0, 400.0)
.always_on_top(true)
.decorations(false)
.center()
.title("Translator");
#[cfg(target_os = "macos")]
{
let window = builder.build().unwrap();
window.set_size(PhysicalSize::new(400, 500)).unwrap();
window
.set_min_size(Some(PhysicalSize::new(400, 400)))
.unwrap();
set_shadow(&window, true).unwrap_or_default();
}

#[cfg(target_os = "windows")]
{
let window = builder.build().unwrap();
window.set_size(PhysicalSize::new(400, 500)).unwrap();
window
.set_min_size(Some(PhysicalSize::new(400, 400)))
.unwrap();
set_shadow(&window, true).unwrap_or_default();
}

#[cfg(target_os = "linux")]
{
let window = builder.transparent(true).build().unwrap();
window.set_size(PhysicalSize::new(400, 500)).unwrap();
window
.set_min_size(Some(PhysicalSize::new(400, 400)))
.unwrap();
}
let _window = build_window("persistent", "Persistent", app).unwrap();
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src-tauri/src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use toml::Value;
#[cfg(any(target_os = "macos", target_os = "windows"))]
use window_shadows::set_shadow;

fn build_window(label: &str, title: &str, handle: &AppHandle) -> Result<Window, String> {
pub fn build_window(label: &str, title: &str, handle: &AppHandle) -> Result<Window, String> {
let (width, height) = get_window_size();
let (x, y) = get_mouse_location().unwrap();
let builder = tauri::WindowBuilder::new(
Expand Down

0 comments on commit d8c206b

Please sign in to comment.