fix: build on linux and windows

This commit is contained in:
reya
2024-07-03 14:09:07 +07:00
parent 4c323b9daa
commit 72b59020b4
7 changed files with 117 additions and 78 deletions

56
src-tauri/Cargo.lock generated
View File

@@ -3482,9 +3482,9 @@ checksum = "c08d65885ee38876c4f86fa503fb49d7b507c2b62552df7c70b2fce627e06381"
[[package]] [[package]]
name = "open" name = "open"
version = "5.1.4" version = "5.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b5ca541f22b1c46d4bb9801014f234758ab4297e7870b904b6a8415b980a7388" checksum = "9d2c909a3fce3bd80efef4cd1c6c056bd9376a8fe06fcfdbebaf32cb485a7e37"
dependencies = [ dependencies = [
"is-wsl", "is-wsl",
"libc", "libc",
@@ -5390,8 +5390,8 @@ dependencies = [
[[package]] [[package]]
name = "tauri-plugin-clipboard-manager" name = "tauri-plugin-clipboard-manager"
version = "2.1.0-beta.4" version = "2.1.0-beta.5"
source = "git+https://github.com/tauri-apps/plugins-workspace?branch=v2#955ed6aec6420d6a98337e2a3f33590d9d8fbdcf" source = "git+https://github.com/tauri-apps/plugins-workspace?branch=v2#8f6d341e45865c852170e8bbf2c8ffa9aca907d6"
dependencies = [ dependencies = [
"arboard", "arboard",
"image 0.24.9", "image 0.24.9",
@@ -5421,8 +5421,8 @@ dependencies = [
[[package]] [[package]]
name = "tauri-plugin-dialog" name = "tauri-plugin-dialog"
version = "2.0.0-beta.9" version = "2.0.0-beta.10"
source = "git+https://github.com/tauri-apps/plugins-workspace?branch=v2#955ed6aec6420d6a98337e2a3f33590d9d8fbdcf" source = "git+https://github.com/tauri-apps/plugins-workspace?branch=v2#8f6d341e45865c852170e8bbf2c8ffa9aca907d6"
dependencies = [ dependencies = [
"dunce", "dunce",
"log", "log",
@@ -5438,8 +5438,8 @@ dependencies = [
[[package]] [[package]]
name = "tauri-plugin-fs" name = "tauri-plugin-fs"
version = "2.0.0-beta.9" version = "2.0.0-beta.10"
source = "git+https://github.com/tauri-apps/plugins-workspace?branch=v2#955ed6aec6420d6a98337e2a3f33590d9d8fbdcf" source = "git+https://github.com/tauri-apps/plugins-workspace?branch=v2#8f6d341e45865c852170e8bbf2c8ffa9aca907d6"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"glob", "glob",
@@ -5456,8 +5456,8 @@ dependencies = [
[[package]] [[package]]
name = "tauri-plugin-http" name = "tauri-plugin-http"
version = "2.0.0-beta.10" version = "2.0.0-beta.11"
source = "git+https://github.com/tauri-apps/plugins-workspace?branch=v2#955ed6aec6420d6a98337e2a3f33590d9d8fbdcf" source = "git+https://github.com/tauri-apps/plugins-workspace?branch=v2#8f6d341e45865c852170e8bbf2c8ffa9aca907d6"
dependencies = [ dependencies = [
"data-url", "data-url",
"http", "http",
@@ -5476,8 +5476,8 @@ dependencies = [
[[package]] [[package]]
name = "tauri-plugin-notification" name = "tauri-plugin-notification"
version = "2.0.0-beta.8" version = "2.0.0-beta.9"
source = "git+https://github.com/tauri-apps/plugins-workspace?branch=v2#955ed6aec6420d6a98337e2a3f33590d9d8fbdcf" source = "git+https://github.com/tauri-apps/plugins-workspace?branch=v2#8f6d341e45865c852170e8bbf2c8ffa9aca907d6"
dependencies = [ dependencies = [
"log", "log",
"notify-rust", "notify-rust",
@@ -5494,8 +5494,8 @@ dependencies = [
[[package]] [[package]]
name = "tauri-plugin-os" name = "tauri-plugin-os"
version = "2.0.0-beta.6" version = "2.0.0-beta.7"
source = "git+https://github.com/tauri-apps/plugins-workspace?branch=v2#955ed6aec6420d6a98337e2a3f33590d9d8fbdcf" source = "git+https://github.com/tauri-apps/plugins-workspace?branch=v2#8f6d341e45865c852170e8bbf2c8ffa9aca907d6"
dependencies = [ dependencies = [
"gethostname", "gethostname",
"log", "log",
@@ -5511,8 +5511,8 @@ dependencies = [
[[package]] [[package]]
name = "tauri-plugin-process" name = "tauri-plugin-process"
version = "2.0.0-beta.6" version = "2.0.0-beta.7"
source = "git+https://github.com/tauri-apps/plugins-workspace?branch=v2#955ed6aec6420d6a98337e2a3f33590d9d8fbdcf" source = "git+https://github.com/tauri-apps/plugins-workspace?branch=v2#8f6d341e45865c852170e8bbf2c8ffa9aca907d6"
dependencies = [ dependencies = [
"tauri", "tauri",
"tauri-plugin", "tauri-plugin",
@@ -5520,8 +5520,8 @@ dependencies = [
[[package]] [[package]]
name = "tauri-plugin-shell" name = "tauri-plugin-shell"
version = "2.0.0-beta.7" version = "2.0.0-beta.8"
source = "git+https://github.com/tauri-apps/plugins-workspace?branch=v2#955ed6aec6420d6a98337e2a3f33590d9d8fbdcf" source = "git+https://github.com/tauri-apps/plugins-workspace?branch=v2#8f6d341e45865c852170e8bbf2c8ffa9aca907d6"
dependencies = [ dependencies = [
"encoding_rs", "encoding_rs",
"log", "log",
@@ -5558,8 +5558,8 @@ dependencies = [
[[package]] [[package]]
name = "tauri-plugin-updater" name = "tauri-plugin-updater"
version = "2.0.0-beta.8" version = "2.0.0-beta.9"
source = "git+https://github.com/tauri-apps/plugins-workspace?branch=v2#955ed6aec6420d6a98337e2a3f33590d9d8fbdcf" source = "git+https://github.com/tauri-apps/plugins-workspace?branch=v2#8f6d341e45865c852170e8bbf2c8ffa9aca907d6"
dependencies = [ dependencies = [
"base64 0.22.1", "base64 0.22.1",
"dirs", "dirs",
@@ -5586,8 +5586,8 @@ dependencies = [
[[package]] [[package]]
name = "tauri-plugin-upload" name = "tauri-plugin-upload"
version = "2.0.0-beta.7" version = "2.0.0-beta.8"
source = "git+https://github.com/tauri-apps/plugins-workspace?branch=v2#955ed6aec6420d6a98337e2a3f33590d9d8fbdcf" source = "git+https://github.com/tauri-apps/plugins-workspace?branch=v2#8f6d341e45865c852170e8bbf2c8ffa9aca907d6"
dependencies = [ dependencies = [
"futures-util", "futures-util",
"log", "log",
@@ -5604,8 +5604,8 @@ dependencies = [
[[package]] [[package]]
name = "tauri-plugin-window-state" name = "tauri-plugin-window-state"
version = "2.0.0-beta.9" version = "2.0.0-beta.10"
source = "git+https://github.com/tauri-apps/plugins-workspace?branch=v2#955ed6aec6420d6a98337e2a3f33590d9d8fbdcf" source = "git+https://github.com/tauri-apps/plugins-workspace?branch=v2#8f6d341e45865c852170e8bbf2c8ffa9aca907d6"
dependencies = [ dependencies = [
"bitflags 2.6.0", "bitflags 2.6.0",
"log", "log",
@@ -7237,18 +7237,18 @@ dependencies = [
[[package]] [[package]]
name = "zerocopy" name = "zerocopy"
version = "0.7.34" version = "0.7.35"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ae87e3fcd617500e5d106f0380cf7b77f3c6092aae37191433159dda23cfb087" checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0"
dependencies = [ dependencies = [
"zerocopy-derive", "zerocopy-derive",
] ]
[[package]] [[package]]
name = "zerocopy-derive" name = "zerocopy-derive"
version = "0.7.34" version = "0.7.35"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "15e934569e47891f7d9411f1a451d947a60e000ab3bd24fbb970f000387d1b3b" checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",

View File

@@ -37,7 +37,7 @@ tauri-specta = { git = "https://github.com/reyamir/tauri-specta", features = [
"typescript", "typescript",
] } ] }
tauri-plugin-theme = "0.4.1" tauri-plugin-theme = "0.4.1"
tauri-plugin-decorum = "0.1.0" tauri-plugin-decorum = "0.1.3"
specta = "^2.0.0-rc.12" specta = "^2.0.0-rc.12"
keyring = "2" keyring = "2"
keyring-search = "0.2.0" keyring-search = "0.2.0"

View File

@@ -1,3 +1,5 @@
#[cfg(target_os = "macos")]
pub mod fns; pub mod fns;
#[cfg(target_os = "macos")]
pub mod tray; pub mod tray;
pub mod window; pub mod window;

View File

@@ -5,12 +5,15 @@ use std::str::FromStr;
use cocoa::{appkit::NSApp, base::nil, foundation::NSString}; use cocoa::{appkit::NSApp, base::nil, foundation::NSString};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use specta::Type; use specta::Type;
#[cfg(not(target_os = "linux"))]
use tauri::utils::config::WindowEffectsConfig; use tauri::utils::config::WindowEffectsConfig;
#[cfg(not(target_os = "linux"))]
use tauri::window::Effect; use tauri::window::Effect;
#[cfg(target_os = "macos")] #[cfg(target_os = "macos")]
use tauri::TitleBarStyle; use tauri::TitleBarStyle;
use tauri::WebviewWindowBuilder; use tauri::WebviewWindowBuilder;
use tauri::{LogicalPosition, LogicalSize, Manager, State, WebviewUrl}; use tauri::{LogicalPosition, LogicalSize, Manager, State, WebviewUrl};
#[cfg(not(target_os = "linux"))]
use tauri_plugin_decorum::WebviewWindowExt; use tauri_plugin_decorum::WebviewWindowExt;
use url::Url; use url::Url;
@@ -187,26 +190,38 @@ pub fn open_window(window: Window, app_handle: tauri::AppHandle) -> Result<(), S
.unwrap(); .unwrap();
#[cfg(target_os = "windows")] #[cfg(target_os = "windows")]
let window = WebviewWindowBuilder::new(&app_handle, label, WebviewUrl::App(PathBuf::from(url))) let window = WebviewWindowBuilder::new(
.title(title) &app_handle,
.min_inner_size(width, height) &window.label,
.inner_size(width, height) WebviewUrl::App(PathBuf::from(window.url)),
.effects(WindowEffectsConfig { )
state: None, .title(title)
effects: vec![Effect::Mica], .min_inner_size(window.width, window.height)
radius: None, .inner_size(window.width, window.height)
color: None, .minimizable(window.minimizable)
}) .maximizable(window.maximizable)
.build() .effects(WindowEffectsConfig {
.unwrap(); state: None,
effects: vec![Effect::Mica],
radius: None,
color: None,
})
.build()
.unwrap();
#[cfg(target_os = "linux")] #[cfg(target_os = "linux")]
let window = WebviewWindowBuilder::new(&app_handle, label, WebviewUrl::App(PathBuf::from(url))) let window = WebviewWindowBuilder::new(
.title(title) &app_handle,
.min_inner_size(width, height) &window.label,
.inner_size(width, height) WebviewUrl::App(PathBuf::from(window.url)),
.build() )
.unwrap(); .title(title)
.min_inner_size(window.width, window.height)
.inner_size(window.width, window.height)
.minimizable(window.minimizable)
.maximizable(window.maximizable)
.build()
.unwrap();
// Set decoration // Set decoration
window.create_overlay_titlebar().unwrap(); window.create_overlay_titlebar().unwrap();

View File

@@ -20,6 +20,7 @@ use std::{
str::FromStr, str::FromStr,
}; };
use tauri::{path::BaseDirectory, Manager}; use tauri::{path::BaseDirectory, Manager};
#[cfg(not(target_os = "linux"))]
use tauri_plugin_decorum::WebviewWindowExt; use tauri_plugin_decorum::WebviewWindowExt;
pub mod commands; pub mod commands;
@@ -139,6 +140,10 @@ fn main() {
tauri::Builder::default() tauri::Builder::default()
.setup(|app| { .setup(|app| {
#[cfg(target_os = "macos")]
app.handle().plugin(tauri_nspanel::init()).unwrap();
#[cfg(not(target_os = "linux"))]
let main_window = app.get_webview_window("main").unwrap(); let main_window = app.get_webview_window("main").unwrap();
// Set custom decoration for Windows // Set custom decoration for Windows
@@ -216,6 +221,21 @@ fn main() {
Ok(()) Ok(())
}) })
.enable_macos_default_menu(false)
.on_window_event(move |window, event| {
#[cfg(target_os = "macos")]
if let tauri::WindowEvent::ThemeChanged(_) = event {
if let Some(webview) = window.get_webview_window(window.label()) {
webview.set_traffic_lights_inset(8.0, 16.0).unwrap();
}
}
#[cfg(target_os = "macos")]
if let tauri::WindowEvent::Resized(_) = event {
if let Some(webview) = window.get_webview_window(window.label()) {
webview.set_traffic_lights_inset(8.0, 16.0).unwrap();
}
}
})
.plugin(tauri_nspanel::init()) .plugin(tauri_nspanel::init())
.plugin(tauri_plugin_theme::init(ctx.config_mut())) .plugin(tauri_plugin_theme::init(ctx.config_mut()))
.plugin(tauri_plugin_decorum::init()) .plugin(tauri_plugin_decorum::init())

View File

@@ -1,16 +1,16 @@
{ {
"$schema": "../node_modules/@tauri-apps/cli/schema.json", "$schema": "../node_modules/@tauri-apps/cli/schema.json",
"app": { "app": {
"windows": [ "windows": [
{ {
"title": "Lume", "title": "Lume",
"label": "main", "label": "main",
"titleBarStyle": "Overlay", "titleBarStyle": "Overlay",
"width": 500, "width": 1045,
"height": 800, "height": 800,
"minWidth": 500, "minWidth": 480,
"minHeight": 800 "minHeight": 760
} }
] ]
} }
} }

View File

@@ -1,19 +1,21 @@
{ {
"$schema": "../node_modules/@tauri-apps/cli/schema.json", "$schema": "../node_modules/@tauri-apps/cli/schema.json",
"app": { "app": {
"windows": [ "windows": [
{ {
"title": "Lume", "title": "Lume",
"label": "main", "label": "main",
"width": 500, "width": 1045,
"height": 800, "height": 800,
"minWidth": 500, "minWidth": 480,
"minHeight": 800, "minHeight": 760,
"transparent": true, "transparent": true,
"windowEffects": { "windowEffects": {
"effects": ["mica"] "effects": [
} "mica"
} ]
] }
} }
]
}
} }