Skip to content

Commit 44002c9

Browse files
authored
Merge pull request #1245 from mgaldamez/feat/cross-platform-dark-mode
feat: support cross-platform dark mode on Windows and Linux
2 parents d6c6bb5 + 7d96b72 commit 44002c9

7 files changed

Lines changed: 21 additions & 23 deletions

File tree

bin/helpers/cli-program.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ ${green('|_| \\__,_|_|\\_\\___| can turn any webpage into a desktop app with
103103
.hideHelp(),
104104
)
105105
.addOption(
106-
new Option('--dark-mode', 'Force Mac app to use dark mode')
106+
new Option('--dark-mode', 'Force app to use dark mode (supports macOS, Windows, and Linux)')
107107
.default(DEFAULT.darkMode)
108108
.hideHelp(),
109109
)

bin/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export interface PakeCliOptions {
3838
// App version, the same as package.json version, default 1.0.0
3939
appVersion: string;
4040

41-
// Force Mac to use dark mode, default false
41+
// Force app to use dark mode (supports macOS, Windows, and Linux), default false
4242
darkMode: boolean;
4343

4444
// Disable web shortcuts, default false

dist/cli.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2685,7 +2685,7 @@ ${green('|_| \\__,_|_|\\_\\___| can turn any webpage into a desktop app with
26852685
.addOption(new Option('--maximize', 'Start window maximized')
26862686
.default(DEFAULT_PAKE_OPTIONS.maximize)
26872687
.hideHelp())
2688-
.addOption(new Option('--dark-mode', 'Force Mac app to use dark mode')
2688+
.addOption(new Option('--dark-mode', 'Force app to use dark mode (supports macOS, Windows, and Linux)')
26892689
.default(DEFAULT_PAKE_OPTIONS.darkMode)
26902690
.hideHelp())
26912691
.addOption(new Option('--disabled-web-shortcuts', 'Disabled webPage shortcuts')

docs/cli-usage.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ Set the version number of the packaged application to be consistent with the nam
218218

219219
#### [dark-mode]
220220

221-
Force Mac to package applications using dark mode, default is `false`.
221+
Force packaging applications using dark mode (supports macOS, Windows, and Linux), default is `false`.
222222

223223
```shell
224224
--dark-mode

docs/cli-usage_CN.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ pake https://github.com --name GitHub
216216

217217
#### [dark-mode]
218218

219-
强制 Mac 打包应用使用黑暗模式,默认为 `false`
219+
强制打包应用使用黑暗模式(支持 macOS、Windows 和 Linux),默认为 `false`
220220

221221
```shell
222222
--dark-mode

src-tauri/src/app/invoke.rs

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use tauri::http::Method;
77
use tauri::{command, AppHandle, Manager, Url, WebviewWindow};
88
use tauri_plugin_http::reqwest::{ClientBuilder, Request};
99

10-
#[cfg(target_os = "macos")]
1110
use tauri::Theme;
1211

1312
static BADGE_COUNT: AtomicI64 = AtomicI64::new(0);
@@ -183,21 +182,13 @@ pub fn set_dock_badge_label(app: AppHandle, label: Option<String>) -> Result<(),
183182

184183
#[command]
185184
pub async fn update_theme_mode(app: AppHandle, mode: String) {
186-
#[cfg(target_os = "macos")]
187-
{
188-
if let Some(window) = app.get_webview_window("pake") {
189-
let theme = if mode == "dark" {
190-
Theme::Dark
191-
} else {
192-
Theme::Light
193-
};
194-
let _ = window.set_theme(Some(theme));
195-
}
196-
}
197-
#[cfg(not(target_os = "macos"))]
198-
{
199-
let _ = app;
200-
let _ = mode;
185+
if let Some(window) = app.get_webview_window("pake") {
186+
let theme = if mode == "dark" {
187+
Theme::Dark
188+
} else {
189+
Theme::Light
190+
};
191+
let _ = window.set_theme(Some(theme));
201192
}
202193
}
203194

src-tauri/src/app/window.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@ use tauri::{
1212
AppHandle, Config, Manager, Url, WebviewUrl, WebviewWindow, WebviewWindowBuilder,
1313
};
1414

15+
use tauri::Theme;
16+
1517
#[cfg(target_os = "macos")]
16-
use tauri::{Theme, TitleBarStyle};
18+
use tauri::TitleBarStyle;
1719

1820
#[cfg(target_os = "windows")]
1921
fn build_proxy_browser_arg(url: &Url) -> Option<String> {
@@ -366,7 +368,12 @@ fn build_window(
366368
// Windows and Linux: set data_directory before proxy_url
367369
#[cfg(not(target_os = "macos"))]
368370
{
369-
window_builder = window_builder.data_directory(_data_dir).theme(None);
371+
let theme = if window_config.dark_mode {
372+
Some(Theme::Dark)
373+
} else {
374+
None // Follow system theme
375+
};
376+
window_builder = window_builder.data_directory(_data_dir).theme(theme);
370377

371378
if !config.proxy_url.is_empty() {
372379
if let Ok(proxy_url) = Url::from_str(&config.proxy_url) {

0 commit comments

Comments
 (0)