Merge pull request from 21pages/wallpaper_remove_unsupported

not show remove wallpaper option if unsupported
This commit is contained in:
RustDesk 2023-10-14 22:22:37 +08:00 committed by GitHub
commit 16b4db5083
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 68 additions and 20 deletions

2
Cargo.lock generated

@ -6602,7 +6602,7 @@ dependencies = [
[[package]] [[package]]
name = "wallpaper" name = "wallpaper"
version = "3.2.0" version = "3.2.0"
source = "git+https://github.com/21pages/wallpaper.rs#2bbb70acd93be179c69cb96cb8c3dda487e6f5fd" source = "git+https://github.com/21pages/wallpaper.rs#ce4a0cd3f58327c7cc44d15a63706fb0c022bacf"
dependencies = [ dependencies = [
"dirs 5.0.1", "dirs 5.0.1",
"enquote", "enquote",

@ -323,24 +323,7 @@ class _GeneralState extends State<_General> {
'enable-confirm-closing-tabs', 'enable-confirm-closing-tabs',
isServer: false), isServer: false),
_OptionCheckBox(context, 'Adaptive bitrate', 'enable-abr'), _OptionCheckBox(context, 'Adaptive bitrate', 'enable-abr'),
if (Platform.isWindows || Platform.isLinux) wallpaper(),
Row(
children: [
Flexible(
child: _OptionCheckBox(
context,
'Remove wallpaper during incoming sessions',
'allow-remove-wallpaper'),
),
_CountDownButton(
text: 'Test',
second: 5,
onPressed: () {
bind.mainTestWallpaper(second: 5);
},
)
],
),
_OptionCheckBox( _OptionCheckBox(
context, context,
'Open connection in new tab', 'Open connection in new tab',
@ -367,6 +350,42 @@ class _GeneralState extends State<_General> {
return _Card(title: 'Other', children: children); 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() { Widget hwcodec() {
return Offstage( return Offstage(
offstage: !bind.mainHasHwcodec(), offstage: !bind.mainHasHwcodec(),

@ -1675,6 +1675,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. /// Send a url scheme throught the ipc.
/// ///
/// * macOS only /// * macOS only

@ -1341,6 +1341,14 @@ impl WallPaperRemover {
old_path_dark, 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 { impl Drop for WallPaperRemover {

@ -2392,6 +2392,10 @@ impl WallPaperRemover {
Ok(Self { old_path }) 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<String> { fn get_recent_wallpaper() -> ResultType<String> {
// SystemParametersInfoW may return %appdata%\Microsoft\Windows\Themes\TranscodedWallpaper, not real path and may not real cache // 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/ // https://www.makeuseof.com/find-desktop-wallpapers-file-location-windows-11/

@ -595,6 +595,10 @@ impl UI {
fn get_login_device_info(&self) -> String { fn get_login_device_info(&self) -> String {
get_login_device_info_json() get_login_device_info_json()
} }
fn support_remove_wallpaper(&self) -> bool {
support_remove_wallpaper()
}
} }
impl sciter::EventHandler for UI { impl sciter::EventHandler for UI {
@ -680,6 +684,7 @@ impl sciter::EventHandler for UI {
fn default_video_save_directory(); fn default_video_save_directory();
fn handle_relay_id(String); fn handle_relay_id(String);
fn get_login_device_info(); fn get_login_device_info();
fn support_remove_wallpaper();
} }
} }

@ -210,6 +210,7 @@ class Enhancements: Reactor.Component {
function render() { function render() {
var has_hwcodec = handler.has_hwcodec(); var has_hwcodec = handler.has_hwcodec();
var support_remove_wallpaper = handler.support_remove_wallpaper();
var me = this; var me = this;
self.timer(1ms, function() { me.toggleMenuState() }); self.timer(1ms, function() { me.toggleMenuState() });
return <li>{translate('Enhancements')} return <li>{translate('Enhancements')}
@ -217,7 +218,7 @@ class Enhancements: Reactor.Component {
{has_hwcodec ? <li #enable-hwcodec><span>{svg_checkmark}</span>{translate("Hardware Codec")} (beta)</li> : ""} {has_hwcodec ? <li #enable-hwcodec><span>{svg_checkmark}</span>{translate("Hardware Codec")} (beta)</li> : ""}
<li #enable-abr><span>{svg_checkmark}</span>{translate("Adaptive bitrate")} (beta)</li> <li #enable-abr><span>{svg_checkmark}</span>{translate("Adaptive bitrate")} (beta)</li>
<li #screen-recording>{translate("Recording")}</li> <li #screen-recording>{translate("Recording")}</li>
{is_osx ? "" : <li #allow-remove-wallpaper><span>{svg_checkmark}</span>{translate("Remove wallpaper during incoming sessions")}</li>} {support_remove_wallpaper ? <li #allow-remove-wallpaper><span>{svg_checkmark}</span>{translate("Remove wallpaper during incoming sessions")}</li> : ""}
</menu> </menu>
</li>; </li>;
} }

@ -1256,3 +1256,10 @@ pub fn handle_relay_id(id: String) -> String {
id 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;
}