✨ Pass pakeConfig to web
This commit is contained in:
@@ -2,13 +2,14 @@
|
||||
"windows": [
|
||||
{
|
||||
"url": "https://weread.qq.com",
|
||||
"url_type": "web",
|
||||
"transparent": true,
|
||||
"fullscreen": false,
|
||||
"width": 1200,
|
||||
"height": 780,
|
||||
"resizable": true,
|
||||
"url_type": "web",
|
||||
"always_on_top": false
|
||||
"always_on_top": false,
|
||||
"disabled_web_shortcuts": false
|
||||
}
|
||||
],
|
||||
"user_agent": {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use serde::Deserialize;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct WindowConfig {
|
||||
pub url: String,
|
||||
pub transparent: bool,
|
||||
@@ -10,9 +10,10 @@ pub struct WindowConfig {
|
||||
pub resizable: bool,
|
||||
pub url_type: String,
|
||||
pub always_on_top: bool,
|
||||
pub disabled_web_shortcuts: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct PlatformSpecific<T> {
|
||||
pub macos: T,
|
||||
pub linux: T,
|
||||
@@ -44,7 +45,7 @@ where
|
||||
pub type UserAgent = PlatformSpecific<String>;
|
||||
pub type FunctionON = PlatformSpecific<bool>;
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct PakeConfig {
|
||||
pub windows: Vec<WindowConfig>,
|
||||
pub user_agent: UserAgent,
|
||||
|
||||
@@ -19,6 +19,11 @@ pub fn get_window(app: &mut App, config: PakeConfig, _data_dir: PathBuf) -> Wind
|
||||
_ => 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)
|
||||
@@ -28,18 +33,13 @@ pub fn get_window(app: &mut App, config: PakeConfig, _data_dir: PathBuf) -> Wind
|
||||
.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"));
|
||||
|
||||
// For dynamic display of header styles
|
||||
if window_config.transparent {
|
||||
let transparent_script = "window.pakeWindowTitleTransparent = true;";
|
||||
window_builder = window_builder.initialization_script(transparent_script);
|
||||
}
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
{
|
||||
let title_bar_style = if window_config.transparent {
|
||||
|
||||
18
src-tauri/src/inject/event.js
vendored
18
src-tauri/src/inject/event.js
vendored
@@ -88,14 +88,16 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
});
|
||||
});
|
||||
|
||||
document.addEventListener('keyup', (event) => {
|
||||
if (/windows|linux/i.test(navigator.userAgent) && event.ctrlKey) {
|
||||
handleShortcut(event);
|
||||
}
|
||||
if (/macintosh|mac os x/i.test(navigator.userAgent) && event.metaKey) {
|
||||
handleShortcut(event);
|
||||
}
|
||||
});
|
||||
if (window['pakeConfig']?.disabled_web_shortcuts !== true) {
|
||||
document.addEventListener('keyup', (event) => {
|
||||
if (/windows|linux/i.test(navigator.userAgent) && event.ctrlKey) {
|
||||
handleShortcut(event);
|
||||
}
|
||||
if (/macintosh|mac os x/i.test(navigator.userAgent) && event.metaKey) {
|
||||
handleShortcut(event);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Collect blob urls to blob by overriding window.URL.createObjectURL
|
||||
function collectUrlToBlobs() {
|
||||
|
||||
2
src-tauri/src/inject/style.js
vendored
2
src-tauri/src/inject/style.js
vendored
@@ -412,7 +412,7 @@ window.addEventListener('DOMContentLoaded', _event => {
|
||||
}
|
||||
`;
|
||||
const isMac = navigator.platform.toUpperCase().indexOf('MAC') >= 0;
|
||||
if (window.pakeWindowTitleTransparent && isMac) {
|
||||
if (window['pakeConfig']?.transparent && isMac) {
|
||||
const topPaddingStyleElement = document.createElement('style');
|
||||
topPaddingStyleElement.innerHTML = topPaddingCSS;
|
||||
document.head.appendChild(topPaddingStyleElement);
|
||||
|
||||
Reference in New Issue
Block a user