Skip to content

Commit

Permalink
Improve linux support
Browse files Browse the repository at this point in the history
  • Loading branch information
aymanfarsi committed Jun 27, 2024
1 parent 5807add commit 9ead1c4
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 45 deletions.
43 changes: 40 additions & 3 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ eframe = { version = "0.22.0", default-features = false, features = [
"glow",
] }
tray-item = { version = "0.10.0", features = ["ksni"] }
png = "0.17.13"
png = "0.16"
whoami = "1.4.1"

[target.'cfg(target_os = "macos")'.dependencies]
Expand Down
32 changes: 8 additions & 24 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ use notify::{Config, RecommendedWatcher, RecursiveMode, Watcher};
use tokio::sync::mpsc;

#[cfg(any(target_os = "windows", target_os = "linux"))]
use {
crate::utilities::tray_menu::init_tray_menu,
tray_item::{IconSource, TrayItem},
};
use {crate::utilities::tray_menu::init_tray_menu, tray_item::TrayItem};

#[cfg(target_os = "linux")]
use crate::utilities::utils::create_linux_tray_icon;
Expand All @@ -29,6 +26,7 @@ use crate::{
},
};

#[derive(Debug)]
pub struct RcloneApp {
pub app_config: AppConfig,
pub rclone: Rclone,
Expand Down Expand Up @@ -141,9 +139,10 @@ impl eframe::App for RcloneApp {
let tx_egui_clone_tray = self.tx_egui.clone();
let ctx_clone_tray = ctx.clone();
tokio::spawn(async move {
let app_icon = create_linux_tray_icon(include_bytes!("../assets/driveaf.png"));
let app_icon =
create_linux_tray_icon(include_bytes!("../assets/drivefuse.png"));

let mut tray = TrayItem::new("DriveAF Tray", app_icon).unwrap();
let mut tray = TrayItem::new("DriveFUSE Tray", app_icon).unwrap();
let rx_tray = init_tray_menu(&mut tray);
loop {
match rx_tray.recv() {
Expand All @@ -155,28 +154,13 @@ impl eframe::App for RcloneApp {
break;
}
Ok(Message::Icon) => {
let app_icon =
create_linux_tray_icon(include_bytes!("../assets/driveaf.png"));
let app_icon = create_linux_tray_icon(include_bytes!(
"../assets/drivefuse.png"
));
tray.set_icon(app_icon).unwrap();
tx_egui_clone_tray.send(Message::Icon).unwrap();
ctx_clone_tray.request_repaint();
}
Ok(Message::Red) => {
let red_icon = create_linux_tray_icon(include_bytes!(
"../assets/icon-red.ico"
));
tray.set_icon(red_icon).unwrap();
tx_egui_clone_tray.send(Message::Red).unwrap();
ctx_clone_tray.request_repaint();
}
Ok(Message::Green) => {
let green_icon = create_linux_tray_icon(include_bytes!(
"../assets/icon-green.ico"
));
tray.set_icon(green_icon).unwrap();
tx_egui_clone_tray.send(Message::Green).unwrap();
ctx_clone_tray.request_repaint();
}
Ok(Message::ShowApp) => {
tx_egui_clone_tray.send(Message::ShowApp).unwrap();
ctx_clone_tray.request_repaint();
Expand Down
40 changes: 26 additions & 14 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ use std::fs::create_dir_all;
fn main() -> eframe::Result<()> {
#[cfg(target_os = "windows")]
let dir = UserDirs::new()
.unwrap()
.expect("Unable to get user directories")
.document_dir()
.unwrap()
.expect("Unable to get document directory")
.to_str()
.unwrap()
.expect("Unable to convert path to string")
.to_owned()
+ "/drive_fuse";

Expand All @@ -37,7 +37,7 @@ fn main() -> eframe::Result<()> {
);

if !Path::new(&dir).exists() {
create_dir_all(&dir).unwrap();
create_dir_all(&dir).expect("Unable to create directory");
}

let file_appender = tracing_appender::rolling::never(dir, "drive_fuse.log");
Expand Down Expand Up @@ -79,7 +79,8 @@ fn main() -> eframe::Result<()> {
min_window_size: Some(egui::Vec2::new(395., 292.5)),
initial_window_size: Some(egui::Vec2::new(395., 292.5)),
icon_data: Some(
IconData::try_from_png_bytes(include_bytes!("../assets/drivefuse.png")).unwrap(),
IconData::try_from_png_bytes(include_bytes!("../assets/drivefuse.png"))
.expect("Unable to get icon data"),
),
..Default::default()
};
Expand All @@ -90,10 +91,12 @@ fn main() -> eframe::Result<()> {
)
} else {
#[cfg(target_os = "linux")]
create_dir_all(format!("/home/{}/drive_fuse", whoami::username())).unwrap();
create_dir_all(format!("/home/{}/drive_fuse", whoami::username()))
.expect("Unable to create directory");

#[cfg(target_os = "macos")]
create_dir_all(format!("/Users/{}/drive_fuse", whoami::username())).unwrap();
create_dir_all(format!("/Users/{}/drive_fuse", whoami::username()))
.expect("Unable to create directory");

let rt = Runtime::new().expect("Unable to create Runtime");
let _enter = rt.enter();
Expand All @@ -112,7 +115,8 @@ fn main() -> eframe::Result<()> {
min_window_size: Some(min_size),
initial_window_size: Some(min_size),
icon_data: Some(
IconData::try_from_png_bytes(include_bytes!("../assets/drivefuse.png")).unwrap(),
IconData::try_from_png_bytes(include_bytes!("../assets/drivefuse.png"))
.expect("Unable to get icon data"),
),
..Default::default()
};
Expand All @@ -135,7 +139,7 @@ fn check_dependencies(platform: &str) -> Vec<String> {
let mut cmd = Command::new("which");
let output = cmd.arg("fusermount");

let output = output.output().unwrap();
let output = output.output().expect("Failed to execute command");
if !output.status.success() {
missing_dependencies.push("FUSE".to_string());
}
Expand All @@ -145,7 +149,7 @@ fn check_dependencies(platform: &str) -> Vec<String> {
let mut cmd = Command::new("which");
let output = cmd.arg("umount");

let output = output.output().unwrap();
let output = output.output().expect("Failed to execute command");
if !output.status.success() {
missing_dependencies.push("FUSE".to_string());
}
Expand All @@ -160,10 +164,18 @@ fn check_dependencies(platform: &str) -> Vec<String> {
#[cfg(target_os = "windows")]
output.creation_flags(winbase::CREATE_NO_WINDOW);

let output = output.output().unwrap();
if !output.status.success() {
missing_dependencies.push("Rclone".to_string());
}
let output = output.output();
match output {
Ok(output) => {
if !output.status.success() {
missing_dependencies.push("Rclone".to_string());
}
}
Err(err) => {
tracing::error!("Error in check_dependencies while checking rclone: {}", err);
missing_dependencies.push("Rclone".to_string());
}
};

missing_dependencies
}
9 changes: 6 additions & 3 deletions src/utilities/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,12 @@ use crate::RcloneApp;
pub fn create_linux_tray_icon(bytes: &[u8]) -> IconSource {
let cursor = Cursor::new(bytes);
let decoder = png::Decoder::new(cursor);
let mut reader = decoder.read_info().unwrap();
let mut buf = vec![0; reader.output_buffer_size()];
reader.next_frame(&mut buf).unwrap();
let (info, mut reader) = decoder.read_info().expect("Error while reading info");
let mut buf = vec![0; info.buffer_size()];
reader
.next_frame(&mut buf)
.expect("Error while reading next frame");

IconSource::Data {
data: buf,
height: 32,
Expand Down

0 comments on commit 9ead1c4

Please sign in to comment.