Skip to content

Commit

Permalink
✨ Support Mac dark mode
Browse files Browse the repository at this point in the history
  • Loading branch information
tw93 committed Sep 11, 2024
1 parent caa50f6 commit a285a83
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 2 deletions.
8 changes: 8 additions & 0 deletions bin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
8 changes: 8 additions & 0 deletions bin/README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,14 @@ pake [url] [options]
--always-on-top
```
#### [dark-mode]
强制 Mac 打包应用使用黑暗模式,默认为 `false`
```shell
--dark-mode
```
#### [disabled-web-shortcuts]
设置是否禁用原有 Pake 容器里面的网页操作快捷键,默认为 `false`
Expand Down
1 change: 1 addition & 0 deletions bin/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ program
new Option('--targets <string>', '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)
Expand Down
1 change: 1 addition & 0 deletions bin/defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export const DEFAULT_PAKE_OPTIONS: PakeCliOptions = {
resizable: true,
hideTitleBar: false,
alwaysOnTop: false,
darkMode: false,
disabledWebShortcuts: false,
activationShortcut: '',
userAgent: '',
Expand Down
2 changes: 2 additions & 0 deletions bin/helpers/merge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export async function mergeConfig(url: string, options: PakeAppOptions, tauriCon
fullscreen,
hideTitleBar,
alwaysOnTop,
darkMode,
disabledWebShortcuts,
activationShortcut,
userAgent,
Expand All @@ -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 });
Expand Down
4 changes: 4 additions & 0 deletions bin/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
1 change: 1 addition & 0 deletions src-tauri/pake.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"width": 1200,
"height": 780,
"resizable": true,
"dark_mode": false,
"always_on_top": false,
"activation_shortcut": "",
"disabled_web_shortcuts": false
Expand Down
1 change: 1 addition & 0 deletions src-tauri/src/app/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down
9 changes: 7 additions & 2 deletions src-tauri/src/app/window.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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"))]
Expand Down

0 comments on commit a285a83

Please sign in to comment.