From 673986d045b18fed0349fd2192e9a5b340945233 Mon Sep 17 00:00:00 2001 From: rustdesk Date: Mon, 14 Jun 2021 17:51:45 +0800 Subject: [PATCH] https://github.com/rustdesk/rustdesk/issues/69 --- src/platform/windows.rs | 30 ++++++++++++++++++++++++++++++ src/ui.rs | 6 ++++++ src/ui/index.html | 15 +-------------- src/ui/index.tis | 18 ++++++++++++++++++ 4 files changed, 55 insertions(+), 14 deletions(-) diff --git a/src/platform/windows.rs b/src/platform/windows.rs index 0d64a8238..043c73321 100644 --- a/src/platform/windows.rs +++ b/src/platform/windows.rs @@ -1037,3 +1037,33 @@ pub fn get_installed_version() -> String { } "".to_owned() } + + +pub fn create_shortcut(id: &str) -> ResultType<()> { + let exe = std::env::current_exe()?.to_str().unwrap_or("").to_owned(); + let shortcut = write_cmds( + format!( + " +Set oWS = WScript.CreateObject(\"WScript.Shell\") +strDesktop = oWS.SpecialFolders(\"Desktop\") +Set objFSO = CreateObject(\"Scripting.FileSystemObject\") +sLinkFile = objFSO.BuildPath(strDesktop, \"{id}.lnk\") +Set oLink = oWS.CreateShortcut(sLinkFile) + oLink.TargetPath = \"{exe}\" + oLink.Arguments = \"--connect {id}\" +oLink.Save + ", + exe = exe, + id = id, + ), + "vbs", + )? + .to_str() + .unwrap_or("") + .to_owned(); + std::process::Command::new("cscript") + .arg(&shortcut) + .output()?; + allow_err!(std::fs::remove_file(shortcut)); + Ok(()) +} diff --git a/src/ui.rs b/src/ui.rs index a8e1450ff..4f4506d00 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -486,6 +486,11 @@ impl UI { format!("{}.{}", p.to_string_lossy(), self.get_software_ext()) } + fn create_shortcut(&self, id: String) { + #[cfg(windows)] + crate::platform::windows::create_shortcut(&id).ok(); + } + fn open_url(&self, url: String) { #[cfg(windows)] let p = "explorer"; @@ -541,6 +546,7 @@ impl sciter::EventHandler for UI { fn get_software_store_path(); fn get_software_ext(); fn open_url(String); + fn create_shortcut(String); } } diff --git a/src/ui/index.html b/src/ui/index.html index 638e5d09d..c51c64d84 100644 --- a/src/ui/index.html +++ b/src/ui/index.html @@ -9,22 +9,9 @@ include "common.tis"; include "index.tis"; - - -
  • Connect
  • -
  • Transfer File
  • -
  • TCP Tunneling
  • -
  • RDP
  • -
  • Remove
  • - -
    - -
  • Refresh random password
  • -
  • Set your own password
  • -
    - \ No newline at end of file + diff --git a/src/ui/index.tis b/src/ui/index.tis index e8321c0e7..1af803470 100644 --- a/src/ui/index.tis +++ b/src/ui/index.tis @@ -103,6 +103,8 @@ event click $(menu#remote-context li) (evt, me) { } else if (action == "remove") { handler.remove_peer(id); app.recent_sessions.update(); + } else if (action == "shortcut") { + handler.create_shortcut(id); } else if (action == "rdp") { createNewConnect(id, "rdp"); } else if (action == "tunnel") { @@ -310,6 +312,22 @@ class App: Reactor.Component var is_can_screen_recording = handler.is_can_screen_recording(false); return
    + + +
  • Connect
  • +
  • Transfer File
  • +
  • TCP Tunneling
  • +
  • RDP
  • +
  • Remove
  • + {is_win &&
  • Create Desktop Shortcut
  • } + +
    + + +
  • Refresh random password
  • +
  • Set your own password
  • + +
    Your Desktop