diff --git a/Cargo.lock b/Cargo.lock index 6d36e20..e4c3a70 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1862,9 +1862,12 @@ dependencies = [ [[package]] name = "run-cat" -version = "0.1.0" +version = "0.1.1" dependencies = [ + "dirs", + "gtk", "image", + "libappindicator", "sysinfo", "tray-icon", "winit", diff --git a/Cargo.toml b/Cargo.toml index 6133e1e..d14e147 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,6 +14,14 @@ image = "0.25.1" sysinfo = "0.30.12" winit="0.29" +# [target."cfg(target_os = \"unix\")".dev-dependencies] +# gtk = "0.18" +[target."cfg(target_os = \"linux\")".dependencies] +libappindicator = "0.9" +dirs = "5" +gtk = "0.18" + + # The profile that 'cargo dist' will build with [profile.dist] inherits = "release" diff --git a/build.rs b/build.rs index 9f1dc70..9bc63a5 100644 --- a/build.rs +++ b/build.rs @@ -1,8 +1,13 @@ fn main() { - // sudo #[cfg(unix)] - std::process::Command::new("sudo") - .args(&["apt install libgtk-3-dev libxdo-dev libappindicator3-dev #or libayatana-appindicator3-dev -y"]) + std::process::Command::new("apt") + .args([ + "install", + "libgtk-3-dev", + "libxdo-dev", + "libayatana-appindicator3-dev", + "-y", + ]) .status() .unwrap(); } diff --git a/src/main.rs b/src/main.rs index 02a5acf..ee2ae2f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,14 +1,10 @@ #![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] -// Copyright 2022-2022 Tauri Programme within The Commons Conservancy -// SPDX-License-Identifier: Apache-2.0 -// SPDX-License-Identifier: MIT -#![allow(unused)] use tray_icon::{ - menu::{AboutMetadata, Menu, MenuEvent, MenuItem, PredefinedMenuItem}, + menu::{Menu, MenuEvent, MenuItem}, TrayIconBuilder, TrayIconEvent, }; -use winit::event_loop::{ControlFlow, EventLoop, EventLoopBuilder}; +use winit::event_loop::{ControlFlow, EventLoop}; use sysinfo::System; @@ -39,16 +35,15 @@ fn main() { // Since winit doesn't use gtk on Linux, and we need gtk for // the tray icon to show up, we need to spawn a thread // where we initialize gtk and create the tray_icon + let app_icon = load_icon(include_bytes!("../assets/png/app32.png")); #[cfg(target_os = "linux")] std::thread::spawn(|| { use tray_icon::menu::Menu; - - let icon = load_icon(std::path::Path::new(path)); - + let app_icon = load_icon(include_bytes!("../assets/png/app32.png")); gtk::init().unwrap(); let _tray_icon = TrayIconBuilder::new() .with_menu(Box::new(Menu::new())) - .with_icon(icon) + .with_icon(app_icon.clone()) .build() .unwrap(); @@ -81,30 +76,28 @@ fn main() { let dark_item = MenuItem::new("dark", true, None); let light_item = MenuItem::new("light", true, None); - tray_menu.append_items(&[&dark_item, &light_item, &quit_item]); + tray_menu.append_items(&[&dark_item, &light_item, &quit_item]).unwrap(); - let app_icon = load_icon(include_bytes!("../assets/png/app32.png")); let tray_icon = TrayIconBuilder::new() .with_menu(Box::new(tray_menu)) .with_tooltip("run cat~") - .with_icon(app_icon) + .with_icon(app_icon.clone()) .build() .unwrap(); let event_loop = EventLoop::new().unwrap(); let menu_channel = MenuEvent::receiver(); - let tray_channel = TrayIconEvent::receiver(); + // let tray_channel = TrayIconEvent::receiver(); let mut sys = System::new(); sys.refresh_all(); let mut last_update_ts = std::time::Instant::now(); - let mut avg_cpu_usage = 0; let mut last_refresh_cpu = std::time::Instant::now(); let cpu_gap = 300; let mut last_avg_cpu_usage = 0.; - event_loop.run(move |event, event_loop| { + event_loop.run(move |_, event_loop| { // We add delay of 16 ms (60fps) to event_loop to reduce cpu load. // This can be removed to allow ControlFlow::Poll to poll on each cpu cycle // Alternatively, you can set ControlFlow::Wait or use TrayIconEvent::set_event_handler, @@ -140,7 +133,6 @@ fn main() { let fps: u64 = get_fps(avg); let ms = 1000 / fps; - let sleep_time = std::time::Duration::from_millis(ms); if last_update_ts.elapsed().as_millis() >= ms.into() { last_update_ts = now; @@ -153,5 +145,5 @@ fn main() { c += 1; tray_icon.set_icon(Some(icon.clone())).unwrap(); } - }); + }).unwrap(); }