Skip to content

Commit

Permalink
working on windows service install/uninstall
Browse files Browse the repository at this point in the history
  • Loading branch information
rustdesk committed Jun 5, 2023
1 parent f1cc427 commit b07ac43
Show file tree
Hide file tree
Showing 17 changed files with 280 additions and 688 deletions.
427 changes: 26 additions & 401 deletions Cargo.lock

Large diffs are not rendered by default.

10 changes: 2 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ path = "src/naming.rs"

[features]
inline = []
hbbs = []
cli = []
flutter_texture_render = []
appimage = []
Expand Down Expand Up @@ -92,9 +91,7 @@ arboard = "3.2"
system_shutdown = "4.0"

[target.'cfg(target_os = "windows")'.dependencies]
trayicon = { git = "https://github.com/open-trade/trayicon-rs", features = ["winit"] }
winit = "0.26"
winapi = { version = "0.3", features = ["winuser", "wincrypt"] }
winapi = { version = "0.3", features = ["winuser", "wincrypt", "shellscalingapi"] }
winreg = "0.10"
windows-service = "0.6"
virtual_display = { path = "libs/virtual_display", optional = true }
Expand All @@ -113,7 +110,7 @@ dark-light = "1.0"
fruitbasket = "0.10"
objc_id = "0.1"

[target.'cfg(any(target_os = "macos", target_os = "linux"))'.dependencies]
[target.'cfg(any(target_os = "macos", target_os = "linux", target_os = "windows"))'.dependencies]
tray-icon = "0.5"
tao = { git = "https://github.com/Kingtous/tao", branch = "muda" }
image = "0.24"
Expand All @@ -134,9 +131,6 @@ users = { version = "0.11" }
android_logger = "0.13"
jni = "0.21"

[target.'cfg(any(target_os = "android", target_os = "ios"))'.dependencies]
flutter_rust_bridge = "1.75"

[workspace]
members = ["libs/scrap", "libs/hbb_common", "libs/enigo", "libs/clipboard", "libs/virtual_display", "libs/virtual_display/dylib", "libs/portable"]
exclude = ["vdi/host", "examples/custom_plugin"]
Expand Down
2 changes: 1 addition & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ fn build_manifest() {
use std::io::Write;
if std::env::var("PROFILE").unwrap() == "release" {
let mut res = winres::WindowsResource::new();
res.set_icon("res/icon.ico")
res.set_icon("res/tray-icon.ico")
.set_language(winapi::um::winnt::MAKELANGID(
winapi::um::winnt::LANG_ENGLISH,
winapi::um::winnt::SUBLANG_ENGLISH_US,
Expand Down
2 changes: 1 addition & 1 deletion flutter/macos/Runner/MainFlutterWindow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import texture_rgba_renderer
class MainFlutterWindow: NSWindow {
override func awakeFromNib() {
if (!rustdesk_core_main()){
print("Rustdesk core returns false, exiting without launching Flutter app.")
// print("Rustdesk core returns false, exiting without launching Flutter app.")
NSApplication.shared.terminate(self)
}
let flutterViewController = FlutterViewController.init()
Expand Down
7 changes: 7 additions & 0 deletions flutter/windows/runner/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ add_executable(${BINARY_NAME} WIN32
# that need different build settings.
apply_standard_settings(${BINARY_NAME})

# Add preprocessor definitions for the build version.
target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION=\"${FLUTTER_VERSION}\"")
target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_MAJOR=${FLUTTER_VERSION_MAJOR}")
target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_MINOR=${FLUTTER_VERSION_MINOR}")
target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_PATCH=${FLUTTER_VERSION_PATCH}")
target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_BUILD=${FLUTTER_VERSION_BUILD}")

# Disable Windows macros that collide with C++ standard library functions.
target_compile_definitions(${BINARY_NAME} PRIVATE "NOMINMAX")

Expand Down
10 changes: 5 additions & 5 deletions flutter/windows/runner/Runner.rc
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,14 @@ IDI_APP_ICON ICON "resources\\app_icon.ico"
// Version
//

#ifdef FLUTTER_BUILD_NUMBER
#define VERSION_AS_NUMBER FLUTTER_BUILD_NUMBER
#if defined(FLUTTER_VERSION_MAJOR) && defined(FLUTTER_VERSION_MINOR) && defined(FLUTTER_VERSION_PATCH) && defined(FLUTTER_VERSION_BUILD)
#define VERSION_AS_NUMBER FLUTTER_VERSION_MAJOR,FLUTTER_VERSION_MINOR,FLUTTER_VERSION_PATCH,FLUTTER_VERSION_BUILD
#else
#define VERSION_AS_NUMBER 1,0,0
#define VERSION_AS_NUMBER 1,0,0,0
#endif

#ifdef FLUTTER_BUILD_NAME
#define VERSION_AS_STRING #FLUTTER_BUILD_NAME
#if defined(FLUTTER_VERSION)
#define VERSION_AS_STRING FLUTTER_VERSION
#else
#define VERSION_AS_STRING "1.0.0"
#endif
Expand Down
2 changes: 1 addition & 1 deletion flutter/windows/runner/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ int APIENTRY wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev,
for (const auto& argument : command_line_arguments) {
args_str += (argument + " ");
}
std::cout << "Rustdesk [" << args_str << "], core returns false, exiting without launching Flutter app." << std::endl;
// std::cout << "Rustdesk [" << args_str << "], core returns false, exiting without launching Flutter app." << std::endl;
return EXIT_SUCCESS;
}
std::vector<std::string> rust_args(c_args, c_args + args_len);
Expand Down
1 change: 1 addition & 0 deletions libs/portable/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ embed-resource = "2.1"
brotli = "3.3"
dirs = "5.0"
md5 = "0.7"
winapi = { version = "0.3", features = ["winbase"] }
2 changes: 1 addition & 1 deletion libs/portable/icon.rc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
rustdesk_icon ICON "../../res/icon.ico"
rustdesk_icon ICON "../../res/tray-icon.ico"
16 changes: 9 additions & 7 deletions libs/portable/src/bin_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ impl BinaryData {
let cursor = Cursor::new(self.raw);
let mut decoder = brotli::Decompressor::new(cursor, BUF_SIZE);
let mut buf = Vec::new();
decoder.read_to_end(&mut buf).unwrap();
decoder.read_to_end(&mut buf).ok();
buf
}

Expand All @@ -51,7 +51,7 @@ impl BinaryData {
}
if p.exists() {
// check md5
let f = fs::read(p.clone()).unwrap();
let f = fs::read(p.clone()).unwrap_or_default();
let digest = format!("{:x}", md5::compute(&f));
let md5_record = String::from_utf8_lossy(self.md5_code);
if digest == md5_record {
Expand Down Expand Up @@ -127,11 +127,13 @@ impl BinaryReader {

let exe_path = prefix.join(&self.exe);
if exe_path.exists() {
let f = File::open(exe_path).unwrap();
let meta = f.metadata().unwrap();
let mut permissions = meta.permissions();
permissions.set_mode(0o755);
f.set_permissions(permissions).unwrap();
if let Ok(f) = File::open(exe_path) {
if let Ok(meta) = f.metadata() {
let mut permissions = meta.permissions();
permissions.set_mode(0o755);
f.set_permissions(permissions).ok();
}
}
}
}
}
11 changes: 7 additions & 4 deletions libs/portable/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#![windows_subsystem = "windows"]

use std::{
os::windows::process::CommandExt,
path::PathBuf,
process::{Command, Stdio},
};
Expand Down Expand Up @@ -40,17 +41,18 @@ fn setup(reader: BinaryReader, dir: Option<PathBuf>, clear: bool) -> Option<Path
fn execute(path: PathBuf, args: Vec<String>) {
println!("executing {}", path.display());
// setup env
let exe = std::env::current_exe().unwrap();
let exe_name = exe.file_name().unwrap();
let exe = std::env::current_exe().unwrap_or_default();
let exe_name = exe.file_name().unwrap_or_default();
// run executable
Command::new(path)
.args(args)
.creation_flags(winapi::um::winbase::CREATE_NO_WINDOW)
.env(APPNAME_RUNTIME_ENV_KEY, exe_name)
.stdin(Stdio::inherit())
.stdout(Stdio::inherit())
.stderr(Stdio::inherit())
.output()
.expect(&format!("failed to execute {:?}", exe_name));
.ok();
}

fn main() {
Expand Down Expand Up @@ -84,7 +86,7 @@ fn main() {
}

mod windows {
use std::{fs, path::PathBuf, process::Command};
use std::{fs, os::windows::process::CommandExt, path::PathBuf, process::Command};

// Used for privacy mode(magnifier impl).
pub const RUNTIME_BROKER_EXE: &'static str = "C:\\Windows\\System32\\RuntimeBroker.exe";
Expand All @@ -105,6 +107,7 @@ mod windows {
}
let _allow_err = Command::new("taskkill")
.args(&["/F", "/IM", "RuntimeBroker_rustdesk.exe"])
.creation_flags(winapi::um::winbase::CREATE_NO_WINDOW)
.output();
let _allow_err = std::fs::copy(src, &format!("{}\\{}", dir.to_string_lossy(), tgt));
}
Expand Down
1 change: 0 additions & 1 deletion res/icon.ico

This file was deleted.

3 changes: 0 additions & 3 deletions src/core_main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,6 @@ pub fn core_main() -> Option<Vec<String>> {
log::error!("Failed to before-uninstall: {}", err);
}
return None;
} else if args[0] == "--update" {
hbb_common::allow_err!(platform::update_me());
return None;
} else if args[0] == "--reinstall" {
hbb_common::allow_err!(platform::uninstall_me(false));
hbb_common::allow_err!(platform::install_me(
Expand Down
2 changes: 0 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ use common::*;
pub mod cli;
#[cfg(not(any(target_os = "android", target_os = "ios", feature = "cli")))]
pub mod core_main;
#[cfg(all(windows, feature = "hbbs"))]
mod hbbs;
mod lang;
#[cfg(windows)]
mod license;
Expand Down
Loading

0 comments on commit b07ac43

Please sign in to comment.