Skip to content

Commit

Permalink
feat: working batch script; add start scripts to config dir
Browse files Browse the repository at this point in the history
  • Loading branch information
lars-berger committed Feb 16, 2024
1 parent d68340a commit 9bd2e0b
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 210 deletions.
95 changes: 3 additions & 92 deletions packages/desktop/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 1 addition & 6 deletions packages/desktop/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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 = ""
Expand All @@ -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"
Expand All @@ -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"

Expand Down
11 changes: 1 addition & 10 deletions packages/desktop/resources/start.bat
Original file line number Diff line number Diff line change
@@ -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';
6 changes: 0 additions & 6 deletions packages/desktop/resources/start.ps1

This file was deleted.

2 changes: 1 addition & 1 deletion packages/desktop/resources/start.sh
Original file line number Diff line number Diff line change
@@ -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 %'
39 changes: 6 additions & 33 deletions packages/desktop/src/cli.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand All @@ -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<Vec<(String, String)>>,
},
Expand All @@ -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<String>) {
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);
}
}
Expand Down
31 changes: 1 addition & 30 deletions packages/desktop/src/main.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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();
Expand Down
Loading

0 comments on commit 9bd2e0b

Please sign in to comment.