mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-04-23 00:58:32 +02:00
Shared window crate
This commit is contained in:
14
Cargo.lock
generated
14
Cargo.lock
generated
@@ -10297,6 +10297,7 @@ dependencies = [
|
|||||||
"yaak-tauri-utils",
|
"yaak-tauri-utils",
|
||||||
"yaak-templates",
|
"yaak-templates",
|
||||||
"yaak-tls",
|
"yaak-tls",
|
||||||
|
"yaak-window",
|
||||||
"yaak-ws",
|
"yaak-ws",
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -10304,10 +10305,12 @@ dependencies = [
|
|||||||
name = "yaak-app-proxy"
|
name = "yaak-app-proxy"
|
||||||
version = "0.0.0"
|
version = "0.0.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"log 0.4.29",
|
||||||
"serde",
|
"serde",
|
||||||
"tauri",
|
"tauri",
|
||||||
"tauri-build",
|
"tauri-build",
|
||||||
"yaak-proxy",
|
"yaak-proxy",
|
||||||
|
"yaak-window",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -10632,6 +10635,17 @@ dependencies = [
|
|||||||
"yaak-models",
|
"yaak-models",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "yaak-window"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"log 0.4.29",
|
||||||
|
"md5 0.8.0",
|
||||||
|
"rand 0.9.1",
|
||||||
|
"tauri",
|
||||||
|
"tokio",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "yaak-ws"
|
name = "yaak-ws"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ members = [
|
|||||||
"crates-tauri/yaak-license",
|
"crates-tauri/yaak-license",
|
||||||
"crates-tauri/yaak-mac-window",
|
"crates-tauri/yaak-mac-window",
|
||||||
"crates-tauri/yaak-tauri-utils",
|
"crates-tauri/yaak-tauri-utils",
|
||||||
|
"crates-tauri/yaak-window",
|
||||||
]
|
]
|
||||||
|
|
||||||
[workspace.dependencies]
|
[workspace.dependencies]
|
||||||
@@ -72,6 +73,7 @@ yaak-fonts = { path = "crates-tauri/yaak-fonts" }
|
|||||||
yaak-license = { path = "crates-tauri/yaak-license" }
|
yaak-license = { path = "crates-tauri/yaak-license" }
|
||||||
yaak-mac-window = { path = "crates-tauri/yaak-mac-window" }
|
yaak-mac-window = { path = "crates-tauri/yaak-mac-window" }
|
||||||
yaak-tauri-utils = { path = "crates-tauri/yaak-tauri-utils" }
|
yaak-tauri-utils = { path = "crates-tauri/yaak-tauri-utils" }
|
||||||
|
yaak-window = { path = "crates-tauri/yaak-window" }
|
||||||
|
|
||||||
[profile.release]
|
[profile.release]
|
||||||
strip = false
|
strip = false
|
||||||
|
|||||||
@@ -75,4 +75,5 @@ yaak-sse = { workspace = true }
|
|||||||
yaak-sync = { workspace = true }
|
yaak-sync = { workspace = true }
|
||||||
yaak-templates = { workspace = true }
|
yaak-templates = { workspace = true }
|
||||||
yaak-tls = { workspace = true }
|
yaak-tls = { workspace = true }
|
||||||
|
yaak-window = { workspace = true }
|
||||||
yaak-ws = { workspace = true }
|
yaak-ws = { workspace = true }
|
||||||
|
|||||||
@@ -78,10 +78,79 @@ mod render;
|
|||||||
mod sync_ext;
|
mod sync_ext;
|
||||||
mod updates;
|
mod updates;
|
||||||
mod uri_scheme;
|
mod uri_scheme;
|
||||||
mod window;
|
|
||||||
mod window_menu;
|
mod window_menu;
|
||||||
mod ws_ext;
|
mod ws_ext;
|
||||||
|
|
||||||
|
fn setup_window_menu<R: Runtime>(win: &WebviewWindow<R>) -> Result<()> {
|
||||||
|
#[allow(unused_variables)]
|
||||||
|
let menu = window_menu::app_menu(win.app_handle())?;
|
||||||
|
|
||||||
|
// This causes the window to not be clickable (in AppImage), so disable on Linux
|
||||||
|
#[cfg(not(target_os = "linux"))]
|
||||||
|
win.app_handle().set_menu(menu).expect("Failed to set app menu");
|
||||||
|
|
||||||
|
let webview_window = win.clone();
|
||||||
|
win.on_menu_event(move |w, event| {
|
||||||
|
use tauri::{Emitter, LogicalSize, PhysicalSize};
|
||||||
|
use tauri_plugin_opener::OpenerExt;
|
||||||
|
|
||||||
|
if !w.is_focused().unwrap() {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let event_id = event.id().0.as_str();
|
||||||
|
match event_id {
|
||||||
|
"hacked_quit" => {
|
||||||
|
w.webview_windows().iter().for_each(|(_, w)| {
|
||||||
|
info!("Closing window {}", w.label());
|
||||||
|
let _ = w.close();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
"close" => w.close().unwrap(),
|
||||||
|
"zoom_reset" => w.emit("zoom_reset", true).unwrap(),
|
||||||
|
"zoom_in" => w.emit("zoom_in", true).unwrap(),
|
||||||
|
"zoom_out" => w.emit("zoom_out", true).unwrap(),
|
||||||
|
"settings" => w.emit("settings", true).unwrap(),
|
||||||
|
"open_feedback" => {
|
||||||
|
if let Err(e) =
|
||||||
|
w.app_handle().opener().open_url("https://yaak.app/feedback", None::<&str>)
|
||||||
|
{
|
||||||
|
warn!("Failed to open feedback {e:?}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Commands for development
|
||||||
|
"dev.reset_size" => webview_window
|
||||||
|
.set_size(LogicalSize::new(1100.0, 600.0))
|
||||||
|
.unwrap(),
|
||||||
|
"dev.reset_size_16x9" => {
|
||||||
|
let width = webview_window.outer_size().unwrap().width;
|
||||||
|
let height = width * 9 / 16;
|
||||||
|
webview_window.set_size(PhysicalSize::new(width, height)).unwrap()
|
||||||
|
}
|
||||||
|
"dev.reset_size_16x10" => {
|
||||||
|
let width = webview_window.outer_size().unwrap().width;
|
||||||
|
let height = width * 10 / 16;
|
||||||
|
webview_window.set_size(PhysicalSize::new(width, height)).unwrap()
|
||||||
|
}
|
||||||
|
"dev.refresh" => webview_window.eval("location.reload()").unwrap(),
|
||||||
|
"dev.generate_theme_css" => {
|
||||||
|
w.emit("generate_theme_css", true).unwrap();
|
||||||
|
}
|
||||||
|
"dev.toggle_devtools" => {
|
||||||
|
if webview_window.is_devtools_open() {
|
||||||
|
webview_window.close_devtools();
|
||||||
|
} else {
|
||||||
|
webview_window.open_devtools();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
/// Extension trait for easily creating a PluginContext from a WebviewWindow
|
/// Extension trait for easily creating a PluginContext from a WebviewWindow
|
||||||
pub trait PluginContextExt<R: Runtime> {
|
pub trait PluginContextExt<R: Runtime> {
|
||||||
fn plugin_context(&self) -> PluginContext;
|
fn plugin_context(&self) -> PluginContext;
|
||||||
@@ -1452,13 +1521,17 @@ async fn cmd_new_child_window(
|
|||||||
title: &str,
|
title: &str,
|
||||||
inner_size: (f64, f64),
|
inner_size: (f64, f64),
|
||||||
) -> YaakResult<()> {
|
) -> YaakResult<()> {
|
||||||
window::create_child_window(&parent_window, url, label, title, inner_size)?;
|
let use_native_titlebar = parent_window.app_handle().db().get_settings().use_native_titlebar;
|
||||||
|
let win = yaak_window::window::create_child_window(&parent_window, url, label, title, inner_size, use_native_titlebar)?;
|
||||||
|
setup_window_menu(&win)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
async fn cmd_new_main_window(app_handle: AppHandle, url: &str) -> YaakResult<()> {
|
async fn cmd_new_main_window(app_handle: AppHandle, url: &str) -> YaakResult<()> {
|
||||||
window::create_main_window(&app_handle, url)?;
|
let use_native_titlebar = app_handle.db().get_settings().use_native_titlebar;
|
||||||
|
let win = yaak_window::window::create_main_window(&app_handle, url, use_native_titlebar)?;
|
||||||
|
setup_window_menu(&win)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1737,7 +1810,10 @@ pub fn run() {
|
|||||||
.run(|app_handle, event| {
|
.run(|app_handle, event| {
|
||||||
match event {
|
match event {
|
||||||
RunEvent::Ready => {
|
RunEvent::Ready => {
|
||||||
let _ = window::create_main_window(app_handle, "/");
|
let use_native_titlebar = app_handle.db().get_settings().use_native_titlebar;
|
||||||
|
if let Ok(win) = yaak_window::window::create_main_window(app_handle, "/", use_native_titlebar) {
|
||||||
|
let _ = setup_window_menu(&win);
|
||||||
|
}
|
||||||
let h = app_handle.clone();
|
let h = app_handle.clone();
|
||||||
tauri::async_runtime::spawn(async move {
|
tauri::async_runtime::spawn(async move {
|
||||||
let info = history::get_or_upsert_launch_info(&h);
|
let info = history::get_or_upsert_launch_info(&h);
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ use crate::http_request::send_http_request_with_context;
|
|||||||
use crate::models_ext::BlobManagerExt;
|
use crate::models_ext::BlobManagerExt;
|
||||||
use crate::models_ext::QueryManagerExt;
|
use crate::models_ext::QueryManagerExt;
|
||||||
use crate::render::{render_grpc_request, render_http_request, render_json_value};
|
use crate::render::{render_grpc_request, render_http_request, render_json_value};
|
||||||
use crate::window::{CreateWindowConfig, create_window};
|
use yaak_window::window::{CreateWindowConfig, create_window};
|
||||||
use crate::{
|
use crate::{
|
||||||
call_frontend, cookie_jar_from_window, environment_from_window, get_window_from_plugin_context,
|
call_frontend, cookie_jar_from_window, environment_from_window, get_window_from_plugin_context,
|
||||||
workspace_from_window,
|
workspace_from_window,
|
||||||
@@ -320,6 +320,7 @@ async fn handle_host_plugin_request<R: Runtime>(
|
|||||||
HostRequest::OpenWindow(req) => {
|
HostRequest::OpenWindow(req) => {
|
||||||
let (navigation_tx, mut navigation_rx) = tokio::sync::mpsc::channel(128);
|
let (navigation_tx, mut navigation_rx) = tokio::sync::mpsc::channel(128);
|
||||||
let (close_tx, mut close_rx) = tokio::sync::mpsc::channel(128);
|
let (close_tx, mut close_rx) = tokio::sync::mpsc::channel(128);
|
||||||
|
let use_native_titlebar = app_handle.db().get_settings().use_native_titlebar;
|
||||||
let win_config = CreateWindowConfig {
|
let win_config = CreateWindowConfig {
|
||||||
url: &req.url,
|
url: &req.url,
|
||||||
label: &req.label,
|
label: &req.label,
|
||||||
@@ -328,6 +329,7 @@ async fn handle_host_plugin_request<R: Runtime>(
|
|||||||
close_tx: Some(close_tx),
|
close_tx: Some(close_tx),
|
||||||
inner_size: req.size.clone().map(|s| (s.width, s.height)),
|
inner_size: req.size.clone().map(|s| (s.width, s.height)),
|
||||||
data_dir_key: req.data_dir_key.clone(),
|
data_dir_key: req.data_dir_key.clone(),
|
||||||
|
use_native_titlebar,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
if let Err(e) = create_window(app_handle, win_config) {
|
if let Err(e) = create_window(app_handle, win_config) {
|
||||||
|
|||||||
@@ -13,6 +13,8 @@ crate-type = ["staticlib", "cdylib", "lib"]
|
|||||||
tauri-build = { version = "2.5.3", features = [] }
|
tauri-build = { version = "2.5.3", features = [] }
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
log = { workspace = true }
|
||||||
serde = { workspace = true, features = ["derive"] }
|
serde = { workspace = true, features = ["derive"] }
|
||||||
tauri = { workspace = true }
|
tauri = { workspace = true }
|
||||||
yaak-proxy = { workspace = true }
|
yaak-proxy = { workspace = true }
|
||||||
|
yaak-window = { workspace = true }
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
|
use log::error;
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
use std::sync::Mutex;
|
use std::sync::Mutex;
|
||||||
use tauri::State;
|
use tauri::{RunEvent, State};
|
||||||
use yaak_proxy::ProxyHandle;
|
use yaak_proxy::ProxyHandle;
|
||||||
|
use yaak_window::window::CreateWindowConfig;
|
||||||
|
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
@@ -58,6 +60,22 @@ pub fn run() {
|
|||||||
tauri::Builder::default()
|
tauri::Builder::default()
|
||||||
.manage(ProxyState::default())
|
.manage(ProxyState::default())
|
||||||
.invoke_handler(tauri::generate_handler![proxy_metadata, proxy_start, proxy_stop])
|
.invoke_handler(tauri::generate_handler![proxy_metadata, proxy_start, proxy_stop])
|
||||||
.run(tauri::generate_context!())
|
.build(tauri::generate_context!())
|
||||||
.expect("error while running yaak proxy tauri application");
|
.expect("error while building yaak proxy tauri application")
|
||||||
|
.run(|app_handle, event| {
|
||||||
|
if let RunEvent::Ready = event {
|
||||||
|
let config = CreateWindowConfig {
|
||||||
|
url: "/",
|
||||||
|
label: "main",
|
||||||
|
title: "Yaak Proxy",
|
||||||
|
inner_size: Some((1000.0, 700.0)),
|
||||||
|
visible: true,
|
||||||
|
hide_titlebar: true,
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
|
if let Err(e) = yaak_window::window::create_window(app_handle, config) {
|
||||||
|
error!("Failed to create proxy window: {e:?}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,16 +10,7 @@
|
|||||||
},
|
},
|
||||||
"app": {
|
"app": {
|
||||||
"withGlobalTauri": false,
|
"withGlobalTauri": false,
|
||||||
"windows": [
|
"windows": []
|
||||||
{
|
|
||||||
"label": "main",
|
|
||||||
"title": "Yaak Proxy",
|
|
||||||
"width": 1000,
|
|
||||||
"height": 700,
|
|
||||||
"minWidth": 720,
|
|
||||||
"minHeight": 480
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
},
|
||||||
"bundle": {
|
"bundle": {
|
||||||
"icon": [
|
"icon": [
|
||||||
|
|||||||
12
crates-tauri/yaak-window/Cargo.toml
Normal file
12
crates-tauri/yaak-window/Cargo.toml
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
[package]
|
||||||
|
name = "yaak-window"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2024"
|
||||||
|
publish = false
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
log = { workspace = true }
|
||||||
|
md5 = "0.8.0"
|
||||||
|
rand = "0.9.0"
|
||||||
|
tauri = { workspace = true }
|
||||||
|
tokio = { workspace = true, features = ["sync"] }
|
||||||
1
crates-tauri/yaak-window/src/lib.rs
Normal file
1
crates-tauri/yaak-window/src/lib.rs
Normal file
@@ -0,0 +1 @@
|
|||||||
|
pub mod window;
|
||||||
@@ -1,13 +1,6 @@
|
|||||||
use crate::error::Result;
|
use log::info;
|
||||||
use crate::models_ext::QueryManagerExt;
|
|
||||||
use crate::window_menu::app_menu;
|
|
||||||
use log::{info, warn};
|
|
||||||
use rand::random;
|
use rand::random;
|
||||||
use tauri::{
|
use tauri::{AppHandle, Manager, Runtime, WebviewUrl, WebviewWindow, WindowEvent};
|
||||||
AppHandle, Emitter, LogicalSize, Manager, PhysicalSize, Runtime, WebviewUrl, WebviewWindow,
|
|
||||||
WindowEvent,
|
|
||||||
};
|
|
||||||
use tauri_plugin_opener::OpenerExt;
|
|
||||||
use tokio::sync::mpsc;
|
use tokio::sync::mpsc;
|
||||||
|
|
||||||
const DEFAULT_WINDOW_WIDTH: f64 = 1100.0;
|
const DEFAULT_WINDOW_WIDTH: f64 = 1100.0;
|
||||||
@@ -16,11 +9,11 @@ const DEFAULT_WINDOW_HEIGHT: f64 = 600.0;
|
|||||||
const MIN_WINDOW_WIDTH: f64 = 300.0;
|
const MIN_WINDOW_WIDTH: f64 = 300.0;
|
||||||
const MIN_WINDOW_HEIGHT: f64 = 300.0;
|
const MIN_WINDOW_HEIGHT: f64 = 300.0;
|
||||||
|
|
||||||
pub(crate) const MAIN_WINDOW_PREFIX: &str = "main_";
|
pub const MAIN_WINDOW_PREFIX: &str = "main_";
|
||||||
const OTHER_WINDOW_PREFIX: &str = "other_";
|
const OTHER_WINDOW_PREFIX: &str = "other_";
|
||||||
|
|
||||||
#[derive(Default, Debug)]
|
#[derive(Default, Debug)]
|
||||||
pub(crate) struct CreateWindowConfig<'s> {
|
pub struct CreateWindowConfig<'s> {
|
||||||
pub url: &'s str,
|
pub url: &'s str,
|
||||||
pub label: &'s str,
|
pub label: &'s str,
|
||||||
pub title: &'s str,
|
pub title: &'s str,
|
||||||
@@ -29,27 +22,22 @@ pub(crate) struct CreateWindowConfig<'s> {
|
|||||||
pub navigation_tx: Option<mpsc::Sender<String>>,
|
pub navigation_tx: Option<mpsc::Sender<String>>,
|
||||||
pub close_tx: Option<mpsc::Sender<()>>,
|
pub close_tx: Option<mpsc::Sender<()>>,
|
||||||
pub data_dir_key: Option<String>,
|
pub data_dir_key: Option<String>,
|
||||||
|
pub visible: bool,
|
||||||
pub hide_titlebar: bool,
|
pub hide_titlebar: bool,
|
||||||
|
pub use_native_titlebar: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn create_window<R: Runtime>(
|
pub fn create_window<R: Runtime>(
|
||||||
handle: &AppHandle<R>,
|
handle: &AppHandle<R>,
|
||||||
config: CreateWindowConfig,
|
config: CreateWindowConfig,
|
||||||
) -> Result<WebviewWindow<R>> {
|
) -> tauri::Result<WebviewWindow<R>> {
|
||||||
#[allow(unused_variables)]
|
|
||||||
let menu = app_menu(handle)?;
|
|
||||||
|
|
||||||
// This causes the window to not be clickable (in AppImage), so disable on Linux
|
|
||||||
#[cfg(not(target_os = "linux"))]
|
|
||||||
handle.set_menu(menu).expect("Failed to set app menu");
|
|
||||||
|
|
||||||
info!("Create new window label={}", config.label);
|
info!("Create new window label={}", config.label);
|
||||||
|
|
||||||
let mut win_builder =
|
let mut win_builder =
|
||||||
tauri::WebviewWindowBuilder::new(handle, config.label, WebviewUrl::App(config.url.into()))
|
tauri::WebviewWindowBuilder::new(handle, config.label, WebviewUrl::App(config.url.into()))
|
||||||
.title(config.title)
|
.title(config.title)
|
||||||
.resizable(true)
|
.resizable(true)
|
||||||
.visible(false) // To prevent theme flashing, the frontend code calls show() immediately after configuring the theme
|
.visible(config.visible)
|
||||||
.fullscreen(false)
|
.fullscreen(false)
|
||||||
.min_inner_size(MIN_WINDOW_WIDTH, MIN_WINDOW_HEIGHT);
|
.min_inner_size(MIN_WINDOW_WIDTH, MIN_WINDOW_HEIGHT);
|
||||||
|
|
||||||
@@ -96,8 +84,7 @@ pub(crate) fn create_window<R: Runtime>(
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
let settings = handle.db().get_settings();
|
if config.hide_titlebar && !config.use_native_titlebar {
|
||||||
if config.hide_titlebar && !settings.use_native_titlebar {
|
|
||||||
#[cfg(target_os = "macos")]
|
#[cfg(target_os = "macos")]
|
||||||
{
|
{
|
||||||
use tauri::TitleBarStyle;
|
use tauri::TitleBarStyle;
|
||||||
@@ -129,68 +116,14 @@ pub(crate) fn create_window<R: Runtime>(
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
let webview_window = win.clone();
|
|
||||||
win.on_menu_event(move |w, event| {
|
|
||||||
if !w.is_focused().unwrap() {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
let event_id = event.id().0.as_str();
|
|
||||||
match event_id {
|
|
||||||
"hacked_quit" => {
|
|
||||||
// Cmd+Q on macOS doesn't trigger `CloseRequested` so we use a custom Quit menu
|
|
||||||
// and trigger close() for each window.
|
|
||||||
w.webview_windows().iter().for_each(|(_, w)| {
|
|
||||||
info!("Closing window {}", w.label());
|
|
||||||
let _ = w.close();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
"close" => w.close().unwrap(),
|
|
||||||
"zoom_reset" => w.emit("zoom_reset", true).unwrap(),
|
|
||||||
"zoom_in" => w.emit("zoom_in", true).unwrap(),
|
|
||||||
"zoom_out" => w.emit("zoom_out", true).unwrap(),
|
|
||||||
"settings" => w.emit("settings", true).unwrap(),
|
|
||||||
"open_feedback" => {
|
|
||||||
if let Err(e) =
|
|
||||||
w.app_handle().opener().open_url("https://yaak.app/feedback", None::<&str>)
|
|
||||||
{
|
|
||||||
warn!("Failed to open feedback {e:?}")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Commands for development
|
|
||||||
"dev.reset_size" => webview_window
|
|
||||||
.set_size(LogicalSize::new(DEFAULT_WINDOW_WIDTH, DEFAULT_WINDOW_HEIGHT))
|
|
||||||
.unwrap(),
|
|
||||||
"dev.reset_size_16x9" => {
|
|
||||||
let width = webview_window.outer_size().unwrap().width;
|
|
||||||
let height = width * 9 / 16;
|
|
||||||
webview_window.set_size(PhysicalSize::new(width, height)).unwrap()
|
|
||||||
}
|
|
||||||
"dev.reset_size_16x10" => {
|
|
||||||
let width = webview_window.outer_size().unwrap().width;
|
|
||||||
let height = width * 10 / 16;
|
|
||||||
webview_window.set_size(PhysicalSize::new(width, height)).unwrap()
|
|
||||||
}
|
|
||||||
"dev.refresh" => webview_window.eval("location.reload()").unwrap(),
|
|
||||||
"dev.generate_theme_css" => {
|
|
||||||
w.emit("generate_theme_css", true).unwrap();
|
|
||||||
}
|
|
||||||
"dev.toggle_devtools" => {
|
|
||||||
if webview_window.is_devtools_open() {
|
|
||||||
webview_window.close_devtools();
|
|
||||||
} else {
|
|
||||||
webview_window.open_devtools();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
Ok(win)
|
Ok(win)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn create_main_window(handle: &AppHandle, url: &str) -> Result<WebviewWindow> {
|
pub fn create_main_window(
|
||||||
|
handle: &AppHandle,
|
||||||
|
url: &str,
|
||||||
|
use_native_titlebar: bool,
|
||||||
|
) -> tauri::Result<WebviewWindow> {
|
||||||
let mut counter = 0;
|
let mut counter = 0;
|
||||||
let label = loop {
|
let label = loop {
|
||||||
let label = format!("{MAIN_WINDOW_PREFIX}{counter}");
|
let label = format!("{MAIN_WINDOW_PREFIX}{counter}");
|
||||||
@@ -212,19 +145,21 @@ pub(crate) fn create_main_window(handle: &AppHandle, url: &str) -> Result<Webvie
|
|||||||
100.0 + random::<f64>() * 20.0,
|
100.0 + random::<f64>() * 20.0,
|
||||||
)),
|
)),
|
||||||
hide_titlebar: true,
|
hide_titlebar: true,
|
||||||
|
use_native_titlebar,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
|
|
||||||
create_window(handle, config)
|
create_window(handle, config)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn create_child_window(
|
pub fn create_child_window(
|
||||||
parent_window: &WebviewWindow,
|
parent_window: &WebviewWindow,
|
||||||
url: &str,
|
url: &str,
|
||||||
label: &str,
|
label: &str,
|
||||||
title: &str,
|
title: &str,
|
||||||
inner_size: (f64, f64),
|
inner_size: (f64, f64),
|
||||||
) -> Result<WebviewWindow> {
|
use_native_titlebar: bool,
|
||||||
|
) -> tauri::Result<WebviewWindow> {
|
||||||
let app_handle = parent_window.app_handle();
|
let app_handle = parent_window.app_handle();
|
||||||
let label = format!("{OTHER_WINDOW_PREFIX}_{label}");
|
let label = format!("{OTHER_WINDOW_PREFIX}_{label}");
|
||||||
let scale_factor = parent_window.scale_factor()?;
|
let scale_factor = parent_window.scale_factor()?;
|
||||||
@@ -245,6 +180,7 @@ pub(crate) fn create_child_window(
|
|||||||
inner_size: Some(inner_size),
|
inner_size: Some(inner_size),
|
||||||
position: Some(position),
|
position: Some(position),
|
||||||
hide_titlebar: true,
|
hide_titlebar: true,
|
||||||
|
use_native_titlebar,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
|
|
||||||
Reference in New Issue
Block a user