From a285a83269878ec65d259748a62d1dd11fa9a2ab Mon Sep 17 00:00:00 2001 From: Tw93 Date: Wed, 11 Sep 2024 19:16:00 +0800 Subject: [PATCH] :sparkles: Support Mac dark mode --- bin/README.md | 8 ++++++++ bin/README_CN.md | 8 ++++++++ bin/cli.ts | 1 + bin/defaults.ts | 1 + bin/helpers/merge.ts | 2 ++ bin/types.ts | 4 ++++ src-tauri/pake.json | 1 + src-tauri/src/app/config.rs | 1 + src-tauri/src/app/window.rs | 9 +++++++-- 9 files changed, 33 insertions(+), 2 deletions(-) diff --git a/bin/README.md b/bin/README.md index b7a214e..4c835a1 100644 --- a/bin/README.md +++ b/bin/README.md @@ -146,6 +146,14 @@ Sets whether the window is always at the top level, defaults to `false`. --always-on-top ``` +#### [dark-mode] + +Force Mac to package applications using dark mode, default is `false`. + +```shell +--dark-mode +``` + #### [disabled-web-shortcuts] Sets whether to disable web shortcuts in the original Pake container, defaults to `false`. diff --git a/bin/README_CN.md b/bin/README_CN.md index 503ac1c..027f4e6 100644 --- a/bin/README_CN.md +++ b/bin/README_CN.md @@ -146,6 +146,14 @@ pake [url] [options] --always-on-top ``` +#### [dark-mode] + +强制 Mac 打包应用使用黑暗模式,默认为 `false`。 + +```shell +--dark-mode +``` + #### [disabled-web-shortcuts] 设置是否禁用原有 Pake 容器里面的网页操作快捷键,默认为 `false`。 diff --git a/bin/cli.ts b/bin/cli.ts index a3a4081..b6da2ce 100644 --- a/bin/cli.ts +++ b/bin/cli.ts @@ -38,6 +38,7 @@ program new Option('--targets ', 'Only for Linux, option "deb" or "appimage"').default(DEFAULT.targets).hideHelp(), ) .addOption(new Option('--always-on-top', 'Always on the top level').default(DEFAULT.alwaysOnTop).hideHelp()) + .addOption(new Option('--dark-mode', 'Force Mac app to use dark mode').default(DEFAULT.darkMode).hideHelp()) .addOption( new Option('--disabled-web-shortcuts', 'Disabled webPage shortcuts') .default(DEFAULT.disabledWebShortcuts) diff --git a/bin/defaults.ts b/bin/defaults.ts index 9613b79..fe04bb5 100644 --- a/bin/defaults.ts +++ b/bin/defaults.ts @@ -8,6 +8,7 @@ export const DEFAULT_PAKE_OPTIONS: PakeCliOptions = { resizable: true, hideTitleBar: false, alwaysOnTop: false, + darkMode: false, disabledWebShortcuts: false, activationShortcut: '', userAgent: '', diff --git a/bin/helpers/merge.ts b/bin/helpers/merge.ts index a84a907..cc5102c 100644 --- a/bin/helpers/merge.ts +++ b/bin/helpers/merge.ts @@ -14,6 +14,7 @@ export async function mergeConfig(url: string, options: PakeAppOptions, tauriCon fullscreen, hideTitleBar, alwaysOnTop, + darkMode, disabledWebShortcuts, activationShortcut, userAgent, @@ -39,6 +40,7 @@ export async function mergeConfig(url: string, options: PakeAppOptions, tauriCon hide_title_bar: hideTitleBar, activation_shortcut: activationShortcut, always_on_top: alwaysOnTop, + dark_mode: darkMode, disabled_web_shortcuts: disabledWebShortcuts, }; Object.assign(tauriConf.pake.windows[0], { url, ...tauriConfWindowOptions }); diff --git a/bin/types.ts b/bin/types.ts index 13a3a89..f674d00 100644 --- a/bin/types.ts +++ b/bin/types.ts @@ -27,6 +27,10 @@ export interface PakeCliOptions { // Enable windows always on top, default false alwaysOnTop: boolean; + + // Force Mac to use dark mode, default false + darkMode: boolean; + // Disable web shortcuts, default false disabledWebShortcuts: boolean; diff --git a/src-tauri/pake.json b/src-tauri/pake.json index 382b34b..885b447 100644 --- a/src-tauri/pake.json +++ b/src-tauri/pake.json @@ -8,6 +8,7 @@ "width": 1200, "height": 780, "resizable": true, + "dark_mode": false, "always_on_top": false, "activation_shortcut": "", "disabled_web_shortcuts": false diff --git a/src-tauri/src/app/config.rs b/src-tauri/src/app/config.rs index 5280875..43af244 100644 --- a/src-tauri/src/app/config.rs +++ b/src-tauri/src/app/config.rs @@ -10,6 +10,7 @@ pub struct WindowConfig { pub resizable: bool, pub url_type: String, pub always_on_top: bool, + pub dark_mode: bool, pub disabled_web_shortcuts: bool, pub activation_shortcut: String, } diff --git a/src-tauri/src/app/window.rs b/src-tauri/src/app/window.rs index cde6528..bd32cec 100644 --- a/src-tauri/src/app/window.rs +++ b/src-tauri/src/app/window.rs @@ -1,6 +1,6 @@ use crate::app::config::PakeConfig; use std::path::PathBuf; -use tauri::{App, Window, WindowBuilder, WindowUrl}; +use tauri::{App, Theme, Window, WindowBuilder, WindowUrl}; #[cfg(target_os = "macos")] use tauri::TitleBarStyle; @@ -45,7 +45,12 @@ pub fn build_window(app: &mut App, config: PakeConfig, _data_dir: PathBuf) -> Wi } else { TitleBarStyle::Visible }; - window_builder = window_builder.title_bar_style(title_bar_style) + + window_builder = window_builder.title_bar_style(title_bar_style); + + if window_config.dark_mode { + window_builder = window_builder.theme(Some(Theme::Dark)); + } } #[cfg(not(target_os = "macos"))]