From 68ef1fc9e0a07f3160216044046814e0c5a0bb99 Mon Sep 17 00:00:00 2001 From: 21pages Date: Sat, 14 Oct 2023 18:50:41 +0800 Subject: [PATCH] show wallpaper only when support, show test on checked Signed-off-by: 21pages --- Cargo.lock | 2 +- .../desktop/pages/desktop_setting_page.dart | 55 +++++++++++++------ src/flutter_ffi.rs | 4 ++ src/platform/linux.rs | 8 +++ src/platform/windows.rs | 4 ++ src/ui.rs | 5 ++ src/ui/index.tis | 3 +- src/ui_interface.rs | 15 ++++- 8 files changed, 75 insertions(+), 21 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ca9ddc2f4..519476e93 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6602,7 +6602,7 @@ dependencies = [ [[package]] name = "wallpaper" version = "3.2.0" -source = "git+https://github.com/21pages/wallpaper.rs#2bbb70acd93be179c69cb96cb8c3dda487e6f5fd" +source = "git+https://github.com/21pages/wallpaper.rs#ce4a0cd3f58327c7cc44d15a63706fb0c022bacf" dependencies = [ "dirs 5.0.1", "enquote", diff --git a/flutter/lib/desktop/pages/desktop_setting_page.dart b/flutter/lib/desktop/pages/desktop_setting_page.dart index a105f2135..3bbade76e 100644 --- a/flutter/lib/desktop/pages/desktop_setting_page.dart +++ b/flutter/lib/desktop/pages/desktop_setting_page.dart @@ -323,24 +323,7 @@ class _GeneralState extends State<_General> { 'enable-confirm-closing-tabs', isServer: false), _OptionCheckBox(context, 'Adaptive bitrate', 'enable-abr'), - if (Platform.isWindows || Platform.isLinux) - Row( - children: [ - Flexible( - child: _OptionCheckBox( - context, - 'Remove wallpaper during incoming sessions', - 'allow-remove-wallpaper'), - ), - _CountDownButton( - text: 'Test', - second: 5, - onPressed: () { - bind.mainTestWallpaper(second: 5); - }, - ) - ], - ), + wallpaper(), _OptionCheckBox( context, 'Open connection in new tab', @@ -367,6 +350,42 @@ class _GeneralState extends State<_General> { return _Card(title: 'Other', children: children); } + Widget wallpaper() { + return futureBuilder(future: () async { + final support = await bind.mainSupportRemoveWallpaper(); + return support; + }(), hasData: (data) { + if (data is bool && data == true) { + final option = 'allow-remove-wallpaper'; + bool value = mainGetBoolOptionSync(option); + return Row( + children: [ + Flexible( + child: _OptionCheckBox( + context, + 'Remove wallpaper during incoming sessions', + option, + update: () { + setState(() {}); + }, + ), + ), + if (value) + _CountDownButton( + text: 'Test', + second: 5, + onPressed: () { + bind.mainTestWallpaper(second: 5); + }, + ) + ], + ); + } + + return Offstage(); + }); + } + Widget hwcodec() { return Offstage( offstage: !bind.mainHasHwcodec(), diff --git a/src/flutter_ffi.rs b/src/flutter_ffi.rs index b4ae89bc9..883835c26 100644 --- a/src/flutter_ffi.rs +++ b/src/flutter_ffi.rs @@ -1625,6 +1625,10 @@ pub fn main_test_wallpaper(_second: u64) { }); } +pub fn main_support_remove_wallpaper() -> bool { + support_remove_wallpaper() +} + /// Send a url scheme throught the ipc. /// /// * macOS only diff --git a/src/platform/linux.rs b/src/platform/linux.rs index a4975d3aa..37b27cf64 100644 --- a/src/platform/linux.rs +++ b/src/platform/linux.rs @@ -1341,6 +1341,14 @@ impl WallPaperRemover { old_path_dark, }) } + + pub fn support() -> bool { + let desktop = std::env::var("XDG_CURRENT_DESKTOP").unwrap_or_default(); + if wallpaper::gnome::is_compliant(&desktop) || desktop.as_str() == "XFCE" { + return wallpaper::get().is_ok(); + } + false + } } impl Drop for WallPaperRemover { diff --git a/src/platform/windows.rs b/src/platform/windows.rs index 9cc4fd39f..f664b1aee 100644 --- a/src/platform/windows.rs +++ b/src/platform/windows.rs @@ -2392,6 +2392,10 @@ impl WallPaperRemover { Ok(Self { old_path }) } + pub fn support() -> bool { + wallpaper::get().is_ok() || !Self::get_recent_wallpaper().unwrap_or_default().is_empty() + } + fn get_recent_wallpaper() -> ResultType { // SystemParametersInfoW may return %appdata%\Microsoft\Windows\Themes\TranscodedWallpaper, not real path and may not real cache // https://www.makeuseof.com/find-desktop-wallpapers-file-location-windows-11/ diff --git a/src/ui.rs b/src/ui.rs index 27793b31f..fbe715fa9 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -598,6 +598,10 @@ impl UI { fn get_login_device_info(&self) -> String { get_login_device_info_json() } + + fn support_remove_wallpaper(&self) -> bool { + support_remove_wallpaper() + } } impl sciter::EventHandler for UI { @@ -683,6 +687,7 @@ impl sciter::EventHandler for UI { fn default_video_save_directory(); fn handle_relay_id(String); fn get_login_device_info(); + fn support_remove_wallpaper(); } } diff --git a/src/ui/index.tis b/src/ui/index.tis index 67deed7d7..7a46e3b3f 100644 --- a/src/ui/index.tis +++ b/src/ui/index.tis @@ -210,6 +210,7 @@ class Enhancements: Reactor.Component { function render() { var has_hwcodec = handler.has_hwcodec(); + var support_remove_wallpaper = handler.support_remove_wallpaper(); var me = this; self.timer(1ms, function() { me.toggleMenuState() }); return
  • {translate('Enhancements')} @@ -217,7 +218,7 @@ class Enhancements: Reactor.Component { {has_hwcodec ?
  • {svg_checkmark}{translate("Hardware Codec")} (beta)
  • : ""}
  • {svg_checkmark}{translate("Adaptive bitrate")} (beta)
  • {translate("Recording")}
  • - {is_osx ? "" :
  • {svg_checkmark}{translate("Remove wallpaper during incoming sessions")}
  • } + {support_remove_wallpaper ?
  • {svg_checkmark}{translate("Remove wallpaper during incoming sessions")}
  • : ""} ; } diff --git a/src/ui_interface.rs b/src/ui_interface.rs index ed2b4f4fc..f61e683ed 100644 --- a/src/ui_interface.rs +++ b/src/ui_interface.rs @@ -594,7 +594,13 @@ pub fn current_is_wayland() -> bool { #[inline] pub fn get_new_version() -> String { - (*SOFTWARE_UPDATE_URL.lock().unwrap().rsplit('/').next().unwrap_or("")).to_string() + (*SOFTWARE_UPDATE_URL + .lock() + .unwrap() + .rsplit('/') + .next() + .unwrap_or("")) + .to_string() } #[inline] @@ -1248,3 +1254,10 @@ pub fn handle_relay_id(id: String) -> String { id } } + +pub fn support_remove_wallpaper() -> bool { + #[cfg(any(target_os = "windows", target_os = "linux"))] + return crate::platform::WallPaperRemover::support(); + #[cfg(not(any(target_os = "windows", target_os = "linux")))] + return false; +}