-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
/
window.rs
59 lines (50 loc) · 2.07 KB
/
window.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
use crate::app::config::PakeConfig;
use std::path::PathBuf;
use tauri::{App, Window, WindowBuilder, WindowUrl};
#[cfg(target_os = "macos")]
use tauri::TitleBarStyle;
pub fn get_window(app: &mut App, config: PakeConfig, _data_dir: PathBuf) -> Window {
let window_config = config
.windows
.first()
.expect("At least one window configuration is required");
let user_agent = config.user_agent.get();
let url = match window_config.url_type.as_str() {
"web" => WindowUrl::App(window_config.url.parse().unwrap()),
"local" => WindowUrl::App(PathBuf::from(&window_config.url)),
_ => panic!("url type can only be web or local"),
};
let config_script = format!(
"window.pakeConfig = {}",
serde_json::to_string(&window_config).unwrap()
);
let mut window_builder = WindowBuilder::new(app, "pake", url)
.title("")
.user_agent(user_agent)
.visible(false) // Prevent initial shaking
.resizable(window_config.resizable)
.fullscreen(window_config.fullscreen)
.inner_size(window_config.width, window_config.height)
.disable_file_drop_handler()
.always_on_top(window_config.always_on_top)
.initialization_script(&config_script)
.initialization_script(include_str!("../inject/component.js"))
.initialization_script(include_str!("../inject/event.js"))
.initialization_script(include_str!("../inject/style.js"))
//This is necessary to allow for file injection by external developers for customization purposes.
.initialization_script(include_str!("../inject/custom.js"));
#[cfg(target_os = "macos")]
{
let title_bar_style = if window_config.hide_title_bar {
TitleBarStyle::Overlay
} else {
TitleBarStyle::Visible
};
window_builder = window_builder.title_bar_style(title_bar_style)
}
#[cfg(not(target_os = "macos"))]
{
window_builder = window_builder.data_directory(_data_dir);
}
window_builder.build().expect("Failed to build window")
}