diff --git a/packages/desktop/Cargo.lock b/packages/desktop/Cargo.lock index d552a878..99c8b54b 100644 --- a/packages/desktop/Cargo.lock +++ b/packages/desktop/Cargo.lock @@ -826,8 +826,6 @@ dependencies = [ "async-trait", "clap", "cocoa 0.25.0", - "libc", - "libc-stdhandle", "reqwest", "serde", "serde_json", @@ -841,7 +839,6 @@ dependencies = [ "tokio", "tracing", "tracing-subscriber", - "windows 0.52.0", ] [[package]] @@ -1890,16 +1887,6 @@ version = "0.2.149" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a08173bc88b7955d1b3145aa561539096c421ac8debde8cbc3612ec635fee29b" -[[package]] -name = "libc-stdhandle" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6dac2473dc28934c5e0b82250dab231c9d3b94160d91fe9ff483323b05797551" -dependencies = [ - "cc", - "libc", -] - [[package]] name = "libloading" version = "0.7.4" @@ -4399,7 +4386,7 @@ dependencies = [ "webview2-com-macros", "webview2-com-sys", "windows 0.51.1", - "windows-core 0.51.1", + "windows-core", "windows-implement", "windows-interface", ] @@ -4423,7 +4410,7 @@ checksum = "3775bb005c3170497ec411b36005708b57ad486bfa3d23864c92f5973858ce8d" dependencies = [ "thiserror", "windows 0.51.1", - "windows-core 0.51.1", + "windows-core", ] [[package]] @@ -4484,22 +4471,12 @@ version = "0.51.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ca229916c5ee38c2f2bc1e9d8f04df975b4bd93f9955dc69fabb5d91270045c9" dependencies = [ - "windows-core 0.51.1", + "windows-core", "windows-implement", "windows-interface", "windows-targets 0.48.5", ] -[[package]] -name = "windows" -version = "0.52.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e48a53791691ab099e5e2ad123536d0fff50652600abaf43bbf952894110d0be" -dependencies = [ - "windows-core 0.52.0", - "windows-targets 0.52.0", -] - [[package]] name = "windows-core" version = "0.51.1" @@ -4509,15 +4486,6 @@ dependencies = [ "windows-targets 0.48.5", ] -[[package]] -name = "windows-core" -version = "0.52.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9" -dependencies = [ - "windows-targets 0.52.0", -] - [[package]] name = "windows-implement" version = "0.51.1" @@ -4588,21 +4556,6 @@ dependencies = [ "windows_x86_64_msvc 0.48.5", ] -[[package]] -name = "windows-targets" -version = "0.52.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a18201040b24831fbb9e4eb208f8892e1f50a37feb53cc7ff887feb8f50e7cd" -dependencies = [ - "windows_aarch64_gnullvm 0.52.0", - "windows_aarch64_msvc 0.52.0", - "windows_i686_gnu 0.52.0", - "windows_i686_msvc 0.52.0", - "windows_x86_64_gnu 0.52.0", - "windows_x86_64_gnullvm 0.52.0", - "windows_x86_64_msvc 0.52.0", -] - [[package]] name = "windows_aarch64_gnullvm" version = "0.42.2" @@ -4615,12 +4568,6 @@ version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.52.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cb7764e35d4db8a7921e09562a0304bf2f93e0a51bfccee0bd0bb0b666b015ea" - [[package]] name = "windows_aarch64_msvc" version = "0.42.2" @@ -4633,12 +4580,6 @@ version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" -[[package]] -name = "windows_aarch64_msvc" -version = "0.52.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbaa0368d4f1d2aaefc55b6fcfee13f41544ddf36801e793edbbfd7d7df075ef" - [[package]] name = "windows_i686_gnu" version = "0.42.2" @@ -4651,12 +4592,6 @@ version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" -[[package]] -name = "windows_i686_gnu" -version = "0.52.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a28637cb1fa3560a16915793afb20081aba2c92ee8af57b4d5f28e4b3e7df313" - [[package]] name = "windows_i686_msvc" version = "0.42.2" @@ -4669,12 +4604,6 @@ version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" -[[package]] -name = "windows_i686_msvc" -version = "0.52.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ffe5e8e31046ce6230cc7215707b816e339ff4d4d67c65dffa206fd0f7aa7b9a" - [[package]] name = "windows_x86_64_gnu" version = "0.42.2" @@ -4687,12 +4616,6 @@ version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" -[[package]] -name = "windows_x86_64_gnu" -version = "0.52.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d6fa32db2bc4a2f5abeacf2b69f7992cd09dca97498da74a151a3132c26befd" - [[package]] name = "windows_x86_64_gnullvm" version = "0.42.2" @@ -4705,12 +4628,6 @@ version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.52.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a657e1e9d3f514745a572a6846d3c7aa7dbe1658c056ed9c3344c4109a6949e" - [[package]] name = "windows_x86_64_msvc" version = "0.42.2" @@ -4723,12 +4640,6 @@ version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" -[[package]] -name = "windows_x86_64_msvc" -version = "0.52.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dff9641d1cd4be8d1a070daf9e3773c5f67e78b4d9d42263020c057706765c04" - [[package]] name = "winnow" version = "0.4.7" diff --git a/packages/desktop/Cargo.toml b/packages/desktop/Cargo.toml index 253e33df..39a62472 100644 --- a/packages/desktop/Cargo.toml +++ b/packages/desktop/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "desktop" version = "0.0.0" -description = "A Tauri App" +description = "Zebar is a tool for creating customizable and cross-platform taskbars, desktop widgets, and popups." authors = ["you"] license = "" repository = "" @@ -16,7 +16,6 @@ tauri-build = { version = "2.0.0-alpha.11", features = [] } anyhow = "1.0" async-trait = "0.1.74" clap = { version = "4.4.8", features = ["derive"] } -libc = "0.2" reqwest = { version = "0.11.22", features = ["json"] } tauri = { version = "2.0.0-alpha.17", features = ["macos-private-api"] } tauri-plugin-http = "2.0.0-alpha.5" @@ -30,10 +29,6 @@ tokio = { version = "1.33.0", features = ["full"] } tracing = "0.1.40" tracing-subscriber = "0.3.17" -[target."cfg(windows)".dependencies] -windows = { version = "0.52.0", features = ["Win32_Foundation", "Win32_System_Console", "Win32_UI_WindowsAndMessaging", "Win32_UI_Input_KeyboardAndMouse"] } -libc-stdhandle = "=0.1.0" - [target.'cfg(target_os = "macos")'.dependencies] cocoa = "0.25.0" diff --git a/packages/desktop/resources/start.bat b/packages/desktop/resources/start.bat index 1c8e73ee..7c1d1abb 100644 --- a/packages/desktop/resources/start.bat +++ b/packages/desktop/resources/start.bat @@ -1,14 +1,5 @@ @echo off -@REM powershell.exe -Command "Start-Process -NoNewWindow -FilePath ./start.ps1" -@REM powershell.exe -Command "Start-Process -FilePath 'powershell' -ArgumentList '-File ./script.ps1' -WindowStyle Hidden" -@REM Start-Process -NoNewWindow -FilePath "zebar" -ArgumentList "open bar --args $monitor" - -@REM for /f "tokens=*" %%a in ('zebar monitors') do ( -@REM start /b zebar open bar --args %%a -@REM ) +@REM Start hidden powershell script, which runs `zebar open bar --args ...` for every monitor. powershell -WindowStyle hidden -Command ^ $monitors = zebar monitors; ^ foreach ($monitor in $monitors) { Start-Process -NoNewWindow -FilePath \"zebar\" -ArgumentList \"open bar --args $monitor\" }; - - @REM Start-Process -NoNewWindow -FilePath "zebar" -ArgumentList "open bar --args $monitor"Write-Output 'first line'; ^ - @REM Write-Output 'second line'; diff --git a/packages/desktop/resources/start.ps1 b/packages/desktop/resources/start.ps1 deleted file mode 100644 index 00d14c42..00000000 --- a/packages/desktop/resources/start.ps1 +++ /dev/null @@ -1,6 +0,0 @@ -$monitors = zebar monitors -foreach ($monitor in $monitors) { - Start-Process -NoNewWindow -FilePath "zebar" -ArgumentList "open bar --args $monitor" -} -# Start-Process -FilePath "cmd.exe" -ArgumentList "/c start.bat" -WindowStyle Hidden -# Start-Process -FilePath "cmd.exe" -ArgumentList "/c ./start.bat" diff --git a/packages/desktop/resources/start.sh b/packages/desktop/resources/start.sh index d1073da0..ec6e6642 100644 --- a/packages/desktop/resources/start.sh +++ b/packages/desktop/resources/start.sh @@ -1,3 +1,3 @@ #!/usr/bin/env bash - +# Run `zebar open bar --args ...` for every monitor. zebar monitors --print0 | xargs -0 -P 99 -I % sh -c 'zebar open bar --args %' diff --git a/packages/desktop/src/cli.rs b/packages/desktop/src/cli.rs index 1a440b06..342b0dc7 100644 --- a/packages/desktop/src/cli.rs +++ b/packages/desktop/src/cli.rs @@ -1,12 +1,7 @@ -use std::{io, process}; +use std::process; use anyhow::Result; use clap::{Parser, Subcommand}; -use windows::Win32::UI::Input::KeyboardAndMouse::VK_RETURN; -use windows::Win32::{ - Foundation::{HWND, LPARAM, WPARAM}, - System::Console::{FreeConsole, GetConsoleWindow}, -}; #[derive(Parser, Debug)] #[clap(author, version, about, long_about = None, arg_required_else_help = true)] @@ -17,14 +12,14 @@ pub struct Cli { #[derive(Subcommand, Debug)] pub enum CliCommand { - /// Open a window by its ID (eg. 'zebar open bar'). + /// Open a window by its ID (eg. `zebar open bar`). Open { - /// ID of the window to open (eg. 'bar'). + /// ID of the window to open (eg. `bar`). window_id: String, /// Arguments to pass to the window. /// - /// These become available via the 'self' provider. + /// These become available via the `self` provider. #[clap(short, long, num_args = 1.., value_parser=parse_open_args)] args: Option>, }, @@ -33,43 +28,21 @@ pub enum CliCommand { /// Use ASCII NUL character (character code 0) instead of newlines /// for delimiting monitors. /// - /// Useful for piping to 'xargs -0'. + /// Useful for piping to `xargs -0`. #[clap(short, long)] print0: bool, }, } -/// Print to `stdout`/`stderror` and exit the process. +/// Print to stdout/stderror and exit the process. pub fn print_and_exit(output: Result) { - use windows::Win32::UI::WindowsAndMessaging::*; match output { Ok(output) => { print!("{}", output); - // unsafe { - // let cw: HWND = GetConsoleWindow(); - // println!("cw: {:?}", cw); - // // SendMessageW(cw, WM_KEYDOWN, 0x0D, 0); - // // SendMessageW(cw, WM_KEYUP, 0x0D, 0); - // // let x = VK_ENTER; - // let xx = - // SendMessageW(cw, WM_CHAR, WPARAM(0x0D as _), LPARAM(0 as _)); - // println!("xx: {:?}", xx); - // println!("xx: {:?}", xx.0); - // // SendMessageW(cw, WM_KEYUP, WPARAM(0x0D as _), LPARAM(0 as _)); - - // // let _ = SendMessageW(cw, 0x0102, 0x0D.into(), 0x0.into()); - // let _ = FreeConsole(); - // }; process::exit(0); } Err(err) => { eprintln!("Error: {}", err); - // unsafe { - // let cw = GetConsoleWindow(); - // SendMessageW(cw, WM_CHAR, WPARAM(0x0D as _), LPARAM(0 as _)); - // // SendMessageW(cw, WM_KEYUP, WPARAM(0x0D as _), LPARAM(0 as _)); - // let _ = FreeConsole(); - // }; process::exit(1); } } diff --git a/packages/desktop/src/main.rs b/packages/desktop/src/main.rs index 0f1733d3..e0a991b8 100644 --- a/packages/desktop/src/main.rs +++ b/packages/desktop/src/main.rs @@ -1,8 +1,6 @@ -// Prevents additional console window on Windows in release. -// #![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] #![feature(unix_sigpipe)] -use std::{collections::HashMap, env, ffi::CString, sync::Arc}; +use std::{collections::HashMap, env, sync::Arc}; use anyhow::{Context, Result}; use clap::Parser; @@ -22,9 +20,6 @@ use tokio::{ task, }; use tracing::info; -use windows::Win32::System::Console::{ - AttachConsole, ATTACH_PARENT_PROCESS, -}; use crate::util::window_ext::WindowExt; @@ -112,30 +107,6 @@ async fn main() { tauri::async_runtime::set(tokio::runtime::Handle::current()); tracing_subscriber::fmt::init(); - // Attach to the console if there is one. When building for Windows, - // `windows_subsystem` is configured to be a GUI app and thus does not - // output anything without explicitly attaching to a console. - // #[cfg(all(target_os = "windows", not(debug_assertions)))] - // { - // let console_attached = unsafe { AttachConsole(ATTACH_PARENT_PROCESS) }; - // if console_attached == 0 { - // return; - // } - - // let conin = CString::new("CONIN$").unwrap(); - // let conout = CString::new("CONOUT$").unwrap(); - // let r = CString::new("r").unwrap(); - // let w = CString::new("w").unwrap(); - - // use libc_stdhandle::*; - - // // Python uses the CRT for I/O, and it requires the descriptors are reopened. - // unsafe { - // libc::freopen(conin.as_ptr(), r.as_ptr(), stdin()); - // libc::freopen(conout.as_ptr(), w.as_ptr(), stdout()); - // libc::freopen(conout.as_ptr(), w.as_ptr(), stderr()); - // } - let app = tauri::Builder::default() .setup(|app| { let cli = Cli::parse(); diff --git a/packages/desktop/src/user_config.rs b/packages/desktop/src/user_config.rs index 9ffbdd74..48175eea 100644 --- a/packages/desktop/src/user_config.rs +++ b/packages/desktop/src/user_config.rs @@ -1,4 +1,4 @@ -use std::{fs, io::Read, path::PathBuf}; +use std::{fs, path::PathBuf}; use anyhow::{Context, Result}; use tauri::{path::BaseDirectory, AppHandle, Manager}; @@ -19,11 +19,11 @@ pub fn read_file( }; // Create new config file from sample if it doesn't exist. - match config_path.exists() { - true => fs::read_to_string(&config_path) - .context("Unable to read config file."), - false => create_from_sample(&config_path, app_handle), + if !config_path.exists() { + create_from_sample(&config_path, app_handle)?; } + + fs::read_to_string(&config_path).context("Unable to read config file.") } /// Initialize config at the given path from the sample config resource. @@ -31,45 +31,39 @@ pub fn read_file( fn create_from_sample( config_path: &PathBuf, app_handle: AppHandle, -) -> Result { +) -> Result<()> { let resources_path = app_handle .path() .resolve("resources", BaseDirectory::Resource) .context("Unable to resolve resources for creating sample config.")?; - // let xx = resources_path.join("sample-config.yaml"); - let mut sample_file = fs::File::open(&resources_path) - .context("Unable to read sample config.")?; - - // Read the contents of the sample config. - let mut config_string = String::new(); - sample_file.read_to_string(&mut config_string)?; - - let parent_dir = + let dest_dir = config_path.parent().context("Invalid config directory.")?; - // Create the containing directory. - std::fs::create_dir_all(&parent_dir).with_context(|| { + // Create the destination directory. + std::fs::create_dir_all(&dest_dir).with_context(|| { format!("Unable to create directory {}.", &config_path.display()) })?; - for entry_result in fs::read_dir(resources_path)? { - let entry = entry_result?; - let file_type = entry.file_type()?; - let src_path = entry.path(); - let dest_path = parent_dir.join(entry.file_name()); - - if file_type.is_file() { - fs::copy(&src_path, &dest_path).with_context(|| { - format!("Unable to write to {}", dest_path.display()) - })?; - } - } + let sample_filenames = + vec!["sample-config.yaml", "start.sh", "start.bat"]; - // fs::write(&config_path, &config_string) - // .context("Unable to write config file.")?; + // Copy over sample config and startup scripts. + for sample_filename in sample_filenames { + let dest_filename = match sample_filename { + "sample-config.yaml" => "config.yaml", + other => other, + }; - Ok(config_string) + let src_path = resources_path.join(sample_filename); + let dest_path = dest_dir.join(dest_filename); + + fs::copy(&src_path, &dest_path).with_context(|| { + format!("Unable to write to {}.", dest_path.display()) + })?; + } + + Ok(()) } pub fn open_config_dir(app_handle: AppHandle) -> Result<()> {