diff --git a/Cargo.lock b/Cargo.lock index 4064c301..27dc23c1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7,6 +7,7 @@ name = "Launcher" version = "0.9.2" dependencies = [ "byteorder", + "chrono", "serde", "serde_json", "tokio", @@ -28,6 +29,27 @@ version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "512761e0bb2578dd7380c6baaa0f4ce03e84f95e960231d1dec8bf4d7d6e2627" +[[package]] +name = "android-tzdata" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0" + +[[package]] +name = "android_system_properties" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" +dependencies = [ + "libc", +] + +[[package]] +name = "autocfg" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26" + [[package]] name = "backtrace" version = "0.3.74" @@ -43,18 +65,53 @@ dependencies = [ "windows-targets", ] +[[package]] +name = "bumpalo" +version = "3.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1628fb46dfa0b37568d12e5edd512553eccf6a22a78e8bde00bb4aed84d5bdbf" + [[package]] name = "byteorder" version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" +[[package]] +name = "cc" +version = "1.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e3a13707ac958681c13b39b458c073d0d9bc8a22cb1b2f4c8e55eb72c13f362" +dependencies = [ + "shlex", +] + [[package]] name = "cfg-if" version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "chrono" +version = "0.4.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a7964611d71df112cb1730f2ee67324fcf4d0fc6606acbbe9bfe06df124637c" +dependencies = [ + "android-tzdata", + "iana-time-zone", + "js-sys", + "num-traits", + "wasm-bindgen", + "windows-link", +] + +[[package]] +name = "core-foundation-sys" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" + [[package]] name = "equivalent" version = "1.0.2" @@ -73,6 +130,30 @@ version = "0.15.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bf151400ff0baff5465007dd2f3e717f3fe502074ca563069ce3a6629d07b289" +[[package]] +name = "iana-time-zone" +version = "0.1.63" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b0c919e5debc312ad217002b8048a17b7d83f80703865bbfcfebb0458b0b27d8" +dependencies = [ + "android_system_properties", + "core-foundation-sys", + "iana-time-zone-haiku", + "js-sys", + "log", + "wasm-bindgen", + "windows-core", +] + +[[package]] +name = "iana-time-zone-haiku" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" +dependencies = [ + "cc", +] + [[package]] name = "indexmap" version = "2.9.0" @@ -89,12 +170,28 @@ version = "1.0.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c" +[[package]] +name = "js-sys" +version = "0.3.77" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1cfaf33c695fc6e08064efbc1f72ec937429614f25eef83af942d0e227c3a28f" +dependencies = [ + "once_cell", + "wasm-bindgen", +] + [[package]] name = "libc" version = "0.2.171" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c19937216e9d3aa9956d9bb8dfc0b0c8beb6058fc4f7a4dc4d850edf86a237d6" +[[package]] +name = "log" +version = "0.4.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13dc2df351e3202783a1fe0d44375f7295ffb4049267b0f3018346dc122a1d94" + [[package]] name = "memchr" version = "2.7.4" @@ -121,6 +218,15 @@ dependencies = [ "windows-sys", ] +[[package]] +name = "num-traits" +version = "0.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" +dependencies = [ + "autocfg", +] + [[package]] name = "object" version = "0.36.7" @@ -130,6 +236,12 @@ dependencies = [ "memchr", ] +[[package]] +name = "once_cell" +version = "1.21.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d" + [[package]] name = "pin-project-lite" version = "0.2.16" @@ -160,6 +272,12 @@ version = "0.1.24" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" +[[package]] +name = "rustversion" +version = "1.0.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eded382c5f5f786b989652c49544c4877d9f015cc22e145a5ea8ea66c2921cd2" + [[package]] name = "ryu" version = "1.0.20" @@ -207,6 +325,12 @@ dependencies = [ "serde", ] +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + [[package]] name = "socket2" version = "0.5.9" @@ -306,6 +430,123 @@ version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" +[[package]] +name = "wasm-bindgen" +version = "0.2.100" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1edc8929d7499fc4e8f0be2262a241556cfc54a0bea223790e71446f2aab1ef5" +dependencies = [ + "cfg-if", + "once_cell", + "rustversion", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.100" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2f0a0651a5c2bc21487bde11ee802ccaf4c51935d0d3d42a6101f98161700bc6" +dependencies = [ + "bumpalo", + "log", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.100" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7fe63fc6d09ed3792bd0897b314f53de8e16568c2b3f7982f468c0bf9bd0b407" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.100" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ae87ea40c9f689fc23f209965b6fb8a99ad69aeeb0231408be24920604395de" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.100" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a05d73b933a847d6cccdda8f838a22ff101ad9bf93e33684f39c1f5f0eece3d" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "windows-core" +version = "0.61.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4763c1de310c86d75a878046489e2e5ba02c649d185f21c67d4cf8a56d098980" +dependencies = [ + "windows-implement", + "windows-interface", + "windows-link", + "windows-result", + "windows-strings", +] + +[[package]] +name = "windows-implement" +version = "0.60.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a47fddd13af08290e67f4acabf4b459f647552718f683a7b415d290ac744a836" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "windows-interface" +version = "0.59.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd9211b69f8dcdfa817bfd14bf1c97c9188afa36f4750130fcdf3f400eca9fa8" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "windows-link" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "76840935b766e1b0a05c0066835fb9ec80071d4c09a16f6bd5f7e655e3c14c38" + +[[package]] +name = "windows-result" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c64fd11a4fd95df68efcfee5f44a294fe71b8bc6a91993e2791938abcc712252" +dependencies = [ + "windows-link", +] + +[[package]] +name = "windows-strings" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a2ba9642430ee452d5a7aa78d72907ebe8cfda358e8cb7918a2050581322f97" +dependencies = [ + "windows-link", +] + [[package]] name = "windows-sys" version = "0.52.0" diff --git a/Source/Hurl.BrowserSelector/App.xaml.cs b/Source/Hurl.BrowserSelector/App.xaml.cs index 6d6e2960..51c8e0e6 100644 --- a/Source/Hurl.BrowserSelector/App.xaml.cs +++ b/Source/Hurl.BrowserSelector/App.xaml.cs @@ -1,10 +1,10 @@ -using Hurl.BrowserSelector.State; -using Hurl.BrowserSelector.Helpers; +using Hurl.BrowserSelector.Helpers; +using Hurl.BrowserSelector.State; using Hurl.BrowserSelector.Windows; using System; -using System.Diagnostics; using System.IO; using System.IO.Pipes; +using System.Text; using System.Text.Json; using System.Threading; using System.Windows; @@ -54,6 +54,13 @@ private void Dispatcher_UnhandledException(object sender, System.Windows.Threadi protected override void OnStartup(StartupEventArgs e) { + var x = new StringBuilder(); + foreach (var arg in e.Args) + { + x.Append(arg); + x.Append(" "); + } + writeLogToFile($"Received startup args: {x.ToString()}"); _singleInstanceMutex = new Mutex(true, MUTEX_NAME, out var isOwned); _singleInstanceWaitHandle = new EventWaitHandle(false, EventResetMode.AutoReset, EVENT_NAME); @@ -121,6 +128,16 @@ public void OnInstanceInvoked(string[] args) }); } + + private void writeLogToFile(string message) + { + var timeOfLog = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"); + string logFilePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Hurl", "log.txt"); + Directory.CreateDirectory(Path.GetDirectoryName(logFilePath) ?? string.Empty); + File.AppendAllText(logFilePath, $"{timeOfLog}: {message}\n"); + } + + public void PipeServer() { var isFirstTimeLaunching = true; @@ -144,6 +161,7 @@ public void PipeServer() using StreamReader sr = new(_pipeserver); string args = sr.ReadToEnd(); + writeLogToFile($"Received args: {args}"); string[] argsArray = JsonSerializer.Deserialize(args) ?? []; OnInstanceInvoked(argsArray); } @@ -153,7 +171,7 @@ public void PipeServer() } catch (Exception e) { - Debug.WriteLine($"Error in PipeServer: {e.Message}"); + writeLogToFile($"Error in PipeServer: {e.Message}"); } } } diff --git a/Source/Launcher/Cargo.toml b/Source/Launcher/Cargo.toml index 69933a92..2a21432e 100644 --- a/Source/Launcher/Cargo.toml +++ b/Source/Launcher/Cargo.toml @@ -10,6 +10,7 @@ winresource = "0.1" [dependencies] byteorder = "1" +chrono = { version = "0.4", features = ["now"] } serde = { version = "1", features = ["derive"] } serde_json = "1" tokio = { version = "1", features = ["macros", "rt-multi-thread", "net"] } diff --git a/Source/Launcher/src/main.rs b/Source/Launcher/src/main.rs index a4a2ba0c..7d6e998f 100644 --- a/Source/Launcher/src/main.rs +++ b/Source/Launcher/src/main.rs @@ -2,8 +2,8 @@ use std::{ env, - fs::write, - io::{self, Read}, + fs::OpenOptions, + io::{self, Read, prelude::*}, process::Command, }; @@ -22,7 +22,10 @@ async fn main() { Ok(val) => { let json_val: Result = serde_json::from_slice(&val); match json_val { - Ok(val) => Some(val.url), + Ok(val) => { + write_log_to_file(&format!("Received URL via Native Msg: {}", val.url)); + Some(val.url) + } Err(_) => None, } } @@ -38,6 +41,7 @@ async fn main() { }; let args = env::args().collect::>(); + write_log_to_file(&format!("Received args: {:?}", args)); let trimed_args = &args[1..]; let pipe_conn = named_pipe::ClientOptions::new().open(PIPE_NAME); @@ -51,7 +55,11 @@ async fn main() { }; let _ = client.try_write(args_str.as_bytes()); } - Err(_) => { + Err(e) => { + // append the error log to file + write_log_to_file(&format!("Failed to connect to pipe: {}", e)); + + // If the pipe connection fails, we can still run Hurl.exe with the arguments let args = match native_msg_url { Some(url) => vec![url], None => trimed_args.to_vec(), @@ -72,8 +80,21 @@ pub fn read_input(mut input: R) -> io::Result> { } } -// static USER_SETTINGS: &str = "C:\\Users\\uchan\\AppData\\Roaming\\Hurl\\UserSettings.json"; - -// let file = std::fs::read_to_string(USER_SETTINGS).unwrap(); -// let user_settings: models::Settings = serde_json::from_str(&file).unwrap(); -// let user_settings_json = serde_json::to_string(&user_settings).unwrap(); +fn write_log_to_file(message: &str) { + let log_file = OpenOptions::new() + .create(true) + .append(true) + .open(r"C:\Users\uchan\AppData\Roaming\Hurl\log.txt"); + match log_file { + Ok(mut file) => { + let now = chrono::Local::now(); + let formatted_time = now.format("%Y-%m-%d %H:%M:%S").to_string(); + if let Err(e) = writeln!(file, "{}: {}", formatted_time, message) { + eprintln!("Failed to write error log: {}", e); + } + } + Err(e) => { + eprintln!("Failed to open log file: {}", e); + } + } +}