From 4f63e55a280c963c80c4b16385f0b47a5fc29320 Mon Sep 17 00:00:00 2001 From: Brian Bowman Date: Tue, 5 Jul 2022 05:49:25 -0500 Subject: [PATCH 1/3] Fix build errors on Unix --- src-tauri/Cargo.lock | 11 ++++++ src-tauri/Cargo.toml | 11 +++--- src-tauri/src/proxy.rs | 62 ++++++++++++++++++++------------- src-tauri/src/system_helpers.rs | 11 ++++-- 4 files changed, 65 insertions(+), 30 deletions(-) diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index f2d5257..2063b7f 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -756,6 +756,7 @@ dependencies = [ "rustls-pemfile", "serde", "serde_json", + "sudo", "sysinfo", "tauri", "tauri-build", @@ -3726,6 +3727,16 @@ version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6bdef32e8150c2a081110b42772ffe7d7c9032b606bc226c8260fd97e0976601" +[[package]] +name = "sudo" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88bd84d4c082e18e37fef52c0088e4407dabcef19d23a607fb4b5ee03b7d5b83" +dependencies = [ + "libc", + "log", +] + [[package]] name = "syn" version = "1.0.92" diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 7c90f77..e3ec2a2 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -14,6 +14,13 @@ rust-version = "1.57" [build-dependencies] tauri-build = { version = "1.0.0-rc.8", features = [] } +[target.'cfg(windows)'.dependencies] +is_elevated = "0.1.2" +registry = "1.2.1" + +[target.'cfg(unix)'.dependencies] +sudo = "0.6.0" + [dependencies] serde = { version = "1.0", features = ["derive"] } tauri = { version = "1.0.0-rc.9", features = ["api-all"] } @@ -28,9 +35,6 @@ zip = "0.6.2" # For creating a "global" downloads list. lazy_static = "1.4.0" -# Access to the Windows Registry. -registry = "1.2.1" - # Program opener. open = "2.1.2" duct = "0.13.5" @@ -39,7 +43,6 @@ duct = "0.13.5" serde_json = "1" # System process elevation. -is_elevated = "0.1.2" runas = "0.2.1" # Dependencies for the HTTP(S) proxy. diff --git a/src-tauri/src/proxy.rs b/src-tauri/src/proxy.rs index dc00879..35661b9 100644 --- a/src-tauri/src/proxy.rs +++ b/src-tauri/src/proxy.rs @@ -17,11 +17,12 @@ use hudsucker::{ use std::fs; use std::net::SocketAddr; use std::path::Path; -use registry::{Hive, Data, Security}; use rustls_pemfile as pemfile; use tauri::http::Uri; -use crate::system_helpers::run_command; + +#[cfg(windows)] +use registry::{Hive, Data, Security}; async fn shutdown_signal() { tokio::signal::ctrl_c().await @@ -109,37 +110,43 @@ pub async fn create_proxy(proxy_port: u16, certificate_path: String) { /** * Connects to the local HTTP(S) proxy server. */ +#[cfg(windows)] pub fn connect_to_proxy(proxy_port: u16) { - if cfg!(target_os = "windows") { - // Create 'ProxyServer' string. - let server_string: String = format!("http=127.0.0.1:{};https=127.0.0.1:{}", proxy_port, proxy_port); + // Create 'ProxyServer' string. + let server_string: String = format!("http=127.0.0.1:{};https=127.0.0.1:{}", proxy_port, proxy_port); - // Fetch the 'Internet Settings' registry key. - let settings = Hive::CurrentUser.open(r"Software\Microsoft\Windows\CurrentVersion\Internet Settings", Security::Write).unwrap(); + // Fetch the 'Internet Settings' registry key. + let settings = Hive::CurrentUser.open(r"Software\Microsoft\Windows\CurrentVersion\Internet Settings", Security::Write).unwrap(); - // Set registry values. - settings.set_value("ProxyServer", &Data::String(server_string.parse().unwrap())).unwrap(); - settings.set_value("ProxyEnable", &Data::U32(1)).unwrap(); - } + // Set registry values. + settings.set_value("ProxyServer", &Data::String(server_string.parse().unwrap())).unwrap(); + settings.set_value("ProxyEnable", &Data::U32(1)).unwrap(); println!("Connected to the proxy."); } +#[cfg(not(windows))] +pub fn connect_to_proxy(_proxy_port: u16) { + println!("Connecting to the proxy is not implemented on this platform."); +} + /** * Disconnects from the local HTTP(S) proxy server. */ +#[cfg(windows)] pub fn disconnect_from_proxy() { - if cfg!(target_os = "windows") { - // Fetch the 'Internet Settings' registry key. - let settings = Hive::CurrentUser.open(r"Software\Microsoft\Windows\CurrentVersion\Internet Settings", Security::Write).unwrap(); + // Fetch the 'Internet Settings' registry key. + let settings = Hive::CurrentUser.open(r"Software\Microsoft\Windows\CurrentVersion\Internet Settings", Security::Write).unwrap(); - // Set registry values. - settings.set_value("ProxyEnable", &Data::U32(0)).unwrap(); - } + // Set registry values. + settings.set_value("ProxyEnable", &Data::U32(0)).unwrap(); println!("Disconnected from proxy."); } +#[cfg(not(windows))] +pub fn disconnect_from_proxy() {} + /* * Generates a private key and certificate used by the certificate authority. * Additionally installs the certificate and private key in the Root CA store. @@ -201,12 +208,19 @@ pub fn generate_ca_files(path: &Path) { /* * Attempts to install the certificate authority's certificate into the Root CA store. */ +#[cfg(windows)] pub fn install_ca_files(cert_path: &Path) { - if cfg!(target_os = "windows") { - run_command("certutil", vec!["-user", "-addstore", "Root", cert_path.to_str().unwrap()]); - } else { - run_command("security", vec!["add-trusted-cert", "-d", "-r", "trustRoot", "-k", "/Library/Keychains/System.keychain", cert_path.to_str().unwrap()]); - } - + crate::system_helpers::run_command("certutil", vec!["-user", "-addstore", "Root", cert_path.to_str().unwrap()]); println!("Installed certificate."); -} \ No newline at end of file +} + +#[cfg(target_os = "macos")] +pub fn install_ca_files(cert_path: &Path) { + crate::system_helpers::run_command("security", vec!["add-trusted-cert", "-d", "-r", "trustRoot", "-k", "/Library/Keychains/System.keychain", cert_path.to_str().unwrap()]); + println!("Installed certificate."); +} + +#[cfg(not(any(windows, target_os = "macos")))] +pub fn install_ca_files(_cert_path: &Path) { + println!("Certificate installation is not supported on this platform."); +} diff --git a/src-tauri/src/system_helpers.rs b/src-tauri/src/system_helpers.rs index 329243f..d74794b 100644 --- a/src-tauri/src/system_helpers.rs +++ b/src-tauri/src/system_helpers.rs @@ -76,7 +76,14 @@ pub fn install_location() -> String { return exe_path.to_str().unwrap().to_string(); } +#[cfg(windows)] #[tauri::command] pub fn is_elevated() -> bool { - return is_elevated::is_elevated(); -} \ No newline at end of file + is_elevated::is_elevated() +} + +#[cfg(unix)] +#[tauri::command] +pub fn is_elevated() -> bool { + sudo::check() == sudo::RunningAs::Root +} From bb9a044e05c391b0271a31a10df0f6dc16cad77c Mon Sep 17 00:00:00 2001 From: Brian Bowman Date: Tue, 5 Jul 2022 19:42:46 -0500 Subject: [PATCH 2/3] Fix reading config on Unix --- src/utils/configuration.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/utils/configuration.ts b/src/utils/configuration.ts index 5404718..5ce8863 100644 --- a/src/utils/configuration.ts +++ b/src/utils/configuration.ts @@ -84,7 +84,7 @@ export async function saveConfig(obj: Configuration) { async function readConfigFile() { const local = await dataDir() - if (!configFilePath) configFilePath = local + 'cultivation\\configuration.json' + if (!configFilePath) configFilePath = local + 'cultivation/configuration.json' // Ensure Cultivation dir exists const dirs = await fs.readDir(local) @@ -94,12 +94,12 @@ async function readConfigFile() { await fs.createDir(local + 'cultivation').catch(e => console.log(e)) } - const innerDirs = await fs.readDir(local + '\\cultivation') + const innerDirs = await fs.readDir(local + '/cultivation') // Create grasscutter dir for potential installation if (!innerDirs.find((fileOrDir) => fileOrDir?.name === 'grasscutter')) { // Create dir - await fs.createDir(local + 'cultivation\\grasscutter').catch(e => console.log(e)) + await fs.createDir(local + 'cultivation/grasscutter').catch(e => console.log(e)) } const dataFiles = await fs.readDir(local + 'cultivation') From 1c0edd2bcdb6ebbc379a4120cf2557b4e2694751 Mon Sep 17 00:00:00 2001 From: phuchptty <13364457+phuchptty@users.noreply.github.com> Date: Wed, 6 Jul 2022 22:38:59 +0700 Subject: [PATCH 3/3] feat: add vietnamese language file --- src-tauri/lang/vi.json | 61 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 src-tauri/lang/vi.json diff --git a/src-tauri/lang/vi.json b/src-tauri/lang/vi.json new file mode 100644 index 0000000..6b1d3cd --- /dev/null +++ b/src-tauri/lang/vi.json @@ -0,0 +1,61 @@ +{ + "lang_name": "Tiếng Việt", + "main": { + "title": "Cultivation", + "launch_button": "Khởi Chạy", + "gc_enable": "Kết nối đến Grasscutter", + "https_enable": "Sử dụng HTTPS", + "ip_placeholder": "Địa chỉ máy chủ...", + "port_placeholder": "Cổng...", + "files_downloading": "Đang tải file: ", + "files_extracting": "Đang giải nén tệp tin: " + }, + "options": { + "enabled": "Bật", + "disabled": "Tắt", + "game_exec": "Đường dẫn đến GenshinImpact.exe", + "grasscutter_jar": "Đường dẫn đến Grasscutter.jar", + "toggle_encryption": "Bật/Tắt mã hoá", + "java_path": "Đường dẫn Java tuỳ chỉnh", + "grasscutter_with_game": "Tự động khởi chạy Grasscutter cùng game", + "language": "Chọn ngôn ngữ", + "background": "Ảnh nền tuỳ chỉnh (đường dẫn hoặc tệp tin ảnh)", + "theme": "Chọn giao diện" + }, + "downloads": { + "grasscutter_stable_data": "Tải xuống dữ liệu Grasscutter bản ổn định", + "grasscutter_latest_data": "Tải xuống dữ liệu Grasscutter bản mới nhất", + "grasscutter_stable_data_update": "Cập nhật dữ liệu Grasscutter bản ổn định", + "grasscutter_latest_data_update": "Cập nhật dữ liệu Grasscutter bản mới nhất", + "grasscutter_stable": "Tải xuống Grasscutter phiên bản ổn định", + "grasscutter_latest": "Tải xuống Grasscutter phiển bản mới nhất", + "grasscutter_stable_update": "Cập nhật Grasscutter ổn định", + "grasscutter_latest_update": "Cập nhật Grasscutter mới nhất", + "resources": "Tải xuống tài nguyên cho Grasscutter" + }, + "download_status": { + "downloading": "Đang tải", + "extracting": "Đang giải nén", + "error": "Lỗi", + "finished": "Đã xong", + "stopped": "Đã dừng" + }, + "components": { + "select_file": "Chọn tệp tin hoặc thư mục...", + "select_folder": "Chọn thư mục...", + "download": "Tải xuống" + }, + "news": { + "latest_commits": "Cập nhật gần đây", + "latest_version": "Phiên bản mới nhất" + }, + "help": { + "port_help_text": "Đảm bảo đây là cổng của server Dispatch, không phải cổng của server Game. Thường là '443'.", + "game_help_text": "Bạn không cần phải sử dụng một bản sao riêng để chơi với Grasscutter. Việc này chỉ xảy ra nếu bạn hạ phiên bản xuống 2.6 hoặc chưa cài đặt trò chơi.", + "gc_stable_jar": "Tải xuống phiên bản ổn định của Grasscutter, bảo gồm file jar và các file dữ liệu.", + "gc_dev_jar": "Tải xuống phiên bản phát triển mới nhất của Grasscutter, bảo gồm file jar và các file dữ liệu.", + "gc_stable_data": "Tải xuống bản ổn định các tệp dữ liệu của Grasscutter, không bao gồm file jar. Phù hợp khi cập nhật.", + "gc_dev_data": "Tải xuống bản phát triển mới nhất các tệp dữ liệu của Grasscutter, không bao gồm file jar. Phù hợp khi cập nhật.", + "resources": "Chúng được yêu cầu để chạy máy chủ Grasscutter. Nút này sẽ có màu xám nếu bạn có một thư mục tài nguyên có nội dung bên trong" + } +} \ No newline at end of file