mirror of
https://github.com/SableClient/Sable.git
synced 2026-12-05 08:12:22 -08:00
fix: move window creation into rust side for easier control
This commit is contained in:
4 files changed
+20
-42
No files matched your search
@@ -3,7 +3,7 @@ use std::sync::atomic::{AtomicBool, Ordering};
|
||||
use tauri::{
|
||||
menu::{Menu, MenuEvent, MenuItem},
|
||||
tray::{MouseButton, TrayIcon, TrayIconBuilder, TrayIconEvent},
|
||||
AppHandle, Manager, RunEvent, WebviewUrl, WebviewWindow, WebviewWindowBuilder,
|
||||
AppHandle, Manager, RunEvent, WebviewUrl, WebviewWindowBuilder,
|
||||
};
|
||||
|
||||
pub const MAIN_WINDOW_LABEL: &str = "main";
|
||||
@@ -113,20 +113,13 @@ fn handle_tray_double_click(app: &AppHandle<crate::BrowserEngine>, event: &TrayI
|
||||
}
|
||||
}
|
||||
|
||||
pub fn configure_main_window(_window: &WebviewWindow<crate::BrowserEngine>) {
|
||||
#[cfg(target_os = "windows")]
|
||||
{
|
||||
let _ = _window.set_decorations(false);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn handle_run_event(app: &AppHandle<crate::BrowserEngine>, event: RunEvent) {
|
||||
if let RunEvent::ExitRequested { code, api, .. } = event {
|
||||
handle_exit_request(app, code, &api);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn show_or_create_main_window(app: &AppHandle<crate::BrowserEngine>) -> tauri::Result<()> {
|
||||
pub fn show_or_create_main_window<R: tauri::Runtime>(app: &AppHandle<R>) -> tauri::Result<()> {
|
||||
if let Some(window) = app.get_webview_window(MAIN_WINDOW_LABEL) {
|
||||
let _ = window.unminimize();
|
||||
let _ = window.show();
|
||||
@@ -134,22 +127,19 @@ pub fn show_or_create_main_window(app: &AppHandle<crate::BrowserEngine>) -> taur
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
if let Some(window_config) = app
|
||||
.config()
|
||||
.app
|
||||
.windows
|
||||
.iter()
|
||||
.find(|window| window.label == MAIN_WINDOW_LABEL)
|
||||
.or_else(|| app.config().app.windows.first())
|
||||
{
|
||||
let window = WebviewWindowBuilder::from_config(app, window_config)?.build()?;
|
||||
configure_main_window(&window);
|
||||
return Ok(());
|
||||
}
|
||||
log::info!("Main window not found, creating a new one.");
|
||||
|
||||
let window =
|
||||
WebviewWindowBuilder::new(app, MAIN_WINDOW_LABEL, WebviewUrl::default()).build()?;
|
||||
configure_main_window(&window);
|
||||
let builder = WebviewWindowBuilder::new(app, MAIN_WINDOW_LABEL, WebviewUrl::default())
|
||||
.title(app.package_info().name.clone())
|
||||
.resizable(true)
|
||||
.fullscreen(false)
|
||||
.inner_size(1280.0, 720.0)
|
||||
.visible(false);
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
let builder = builder.decorations(false);
|
||||
|
||||
builder.build()?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -3,9 +3,6 @@ mod windows;
|
||||
#[cfg(desktop)]
|
||||
mod desktop_tray;
|
||||
|
||||
#[cfg(desktop)]
|
||||
use tauri::Manager;
|
||||
|
||||
#[cfg(desktop)]
|
||||
use tauri_plugin_window_state::StateFlags;
|
||||
|
||||
@@ -56,9 +53,7 @@ pub fn run() {
|
||||
|
||||
#[cfg(desktop)]
|
||||
{
|
||||
if let Some(window) = app.get_webview_window(desktop_tray::MAIN_WINDOW_LABEL) {
|
||||
desktop_tray::configure_main_window(&window);
|
||||
}
|
||||
desktop_tray::show_or_create_main_window(app.handle())?;
|
||||
desktop_tray::create_system_tray(app.handle())?;
|
||||
}
|
||||
|
||||
|
||||
@@ -10,16 +10,7 @@
|
||||
"beforeBuildCommand": "pnpm build"
|
||||
},
|
||||
"app": {
|
||||
"windows": [
|
||||
{
|
||||
"title": "sable",
|
||||
"width": 1280,
|
||||
"height": 720,
|
||||
"visible": false,
|
||||
"resizable": true,
|
||||
"fullscreen": false
|
||||
}
|
||||
],
|
||||
"windows": [],
|
||||
"security": {
|
||||
"csp": "default-src 'self' blob: data: filesystem: ws: wss: http: https: tauri:; script-src 'self' 'unsafe-eval' 'unsafe-inline' blob: data: filesystem: ws: wss: http: https: tauri:; img-src 'self' data: blob: filesystem: http: https:; connect-src 'self' ipc: ws: wss: http: https: http://ipc.localhost"
|
||||
}
|
||||
@@ -54,4 +45,4 @@
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -11,7 +11,9 @@ const getAppBaseUrl = (): string => {
|
||||
}
|
||||
|
||||
if (import.meta.env.DEV) {
|
||||
return window.location.origin;
|
||||
// TODO: disabled for now since it causes issues with the SSO flow. We should find a better solution for this in the future.
|
||||
// return window.location.origin;
|
||||
return `${TAURI_SSO_PROTOCOL}//${TAURI_SSO_HOST}`;
|
||||
}
|
||||
|
||||
return 'https://app.sable.moe';
|
||||
|
||||
Reference in new issue
Block a user