Skip to content

Commit

Permalink
chore: fix some clippy warnings (#4)
Browse files Browse the repository at this point in the history
chore: fix some clippy warnings
  • Loading branch information
decipher3114 authored Oct 4, 2024
2 parents 7e5cc1a + c17bbfe commit 04ba9d2
Show file tree
Hide file tree
Showing 10 changed files with 59 additions and 44 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ rdev = { git = "https://github.com/rustdesk-org/rdev", branch = "master"}
rfd = { version = "0.14", features = ["gtk3", "tokio"], default-features = false }
serde = { version = "1.0", features = ["derive"] }
tiny-skia = "0.11"
tokio = { version = "1.39", features = ["full", "rt"] }
tokio = { version = "1.40", features = ["full", "rt"] }
toml = "0.8"
tray-icon = "0.17"
xcap = "0.0"
Expand Down
8 changes: 4 additions & 4 deletions src/assets.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
pub const APPNAME: &str = "Capter";

pub const FONT_MEDIUM: &[u8; 86616] = include_bytes!("../assets/fonts/SpaceGrotesk-Medium.ttf");
pub const FONT_MEDIUM: &[u8] = include_bytes!("../assets/fonts/SpaceGrotesk-Medium.ttf");

pub const FONT_BOLD: &[u8; 86520] = include_bytes!("../assets/fonts/SpaceGrotesk-Bold.ttf");
pub const FONT_BOLD: &[u8] = include_bytes!("../assets/fonts/SpaceGrotesk-Bold.ttf");

pub const FONT_ICONS: &[u8; 2336] = include_bytes!("../assets/fonts/icons.ttf");
pub const FONT_ICONS: &[u8] = include_bytes!("../assets/fonts/icons.ttf");

pub const APPICON: &[u8; 1358] = include_bytes!("../assets/icons/icon.png");
pub const APPICON: &[u8] = include_bytes!("../assets/icons/icon.png");

use iced::Font;

Expand Down
33 changes: 12 additions & 21 deletions src/entities/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,22 @@ use std::collections::BTreeMap;
use iced::window::Id;
use tray_icon::TrayIcon;

use crate::entities::{
capture::CaptureEvent,
config::{Config, ConfigEvent},
window::WindowType,
};
pub use crate::entities::events::AppEvent;
use crate::entities::{config::Config, window::WindowType};

pub struct App {
pub _tray_icon: TrayIcon,
#[expect(dead_code)]
tray_icon: TrayIcon,
pub config: Config,
pub windows: BTreeMap<Id, WindowType>,
}

#[derive(Debug, Clone)]
pub enum AppEvent {
OpenConfigureWindow,
OpenDirectory,
UpdateDirectory(Id),
GetScaleFactor(Id, f32),
OpenCaptureWindow,
Undo,
Done,
Cancel,
RequestClose(Id),
WindowClosed(Id),
ExitApp,
Config(Id, ConfigEvent),
Capture(Id, CaptureEvent),
impl App {
pub fn new(tray_icon: TrayIcon, config: Config) -> Self {
Self {
tray_icon,
config,
windows: BTreeMap::new(),
}
}
}
20 changes: 20 additions & 0 deletions src/entities/events.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
use iced::window::Id;

use super::{capture::CaptureEvent, config::ConfigEvent};

#[derive(Debug, Clone)]
pub enum AppEvent {
OpenConfigureWindow,
OpenDirectory,
UpdateDirectory(Id),
GetScaleFactor(Id, f32),
OpenCaptureWindow,
Undo,
Done,
Cancel,
RequestClose(Id),
WindowClosed(Id),
ExitApp,
Config(Id, ConfigEvent),
Capture(Id, CaptureEvent),
}
1 change: 1 addition & 0 deletions src/entities/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
pub mod app;
pub mod capture;
pub mod config;
mod events;
pub mod style;
pub mod theme;
pub mod window;
4 changes: 2 additions & 2 deletions src/entities/window.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::entities::{capture::CaptureWindow, config::ConfigureWindow};

pub enum WindowType {
Configure(ConfigureWindow),
Capture(CaptureWindow),
Configure(Box<ConfigureWindow>),
Capture(Box<CaptureWindow>),
}
23 changes: 10 additions & 13 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ mod theme;
mod utils;
mod windows;

use std::collections::BTreeMap;

use assets::{APPICON, APPNAME, FONT_BOLD, FONT_ICONS, FONT_MEDIUM, MEDIUM};
use entities::{
app::{App, AppEvent},
Expand All @@ -16,6 +14,7 @@ use entities::{
theme::Theme,
window::WindowType,
};

use iced::{
advanced::graphics::image::image_rs::ImageFormat,
application::DefaultStyle,
Expand Down Expand Up @@ -43,6 +42,7 @@ pub fn main() -> Result<(), iced::Error> {
if interprocess::local_socket::Stream::connect(name).is_ok() {
return Ok(());
};

daemon(App::title, App::update, App::view)
.font(FONT_MEDIUM)
.font(FONT_BOLD)
Expand All @@ -52,19 +52,15 @@ pub fn main() -> Result<(), iced::Error> {
.theme(App::theme)
.subscription(App::subscription)
.antialiasing(true)
.run_with(App::new)
.run_with(App::run)
}

impl App {
pub fn new() -> (App, Task<AppEvent>) {
pub fn run() -> (App, Task<AppEvent>) {
let (config, is_initial) = Config::new();
let _tray_icon = tray_icon();
let tray_icon = tray_icon();
(
App {
_tray_icon,
config,
windows: BTreeMap::new(),
},
App::new(tray_icon, config),
if is_initial {
Task::done(AppEvent::OpenConfigureWindow)
} else {
Expand Down Expand Up @@ -108,10 +104,10 @@ impl App {
});
self.windows.insert(
id,
WindowType::Configure(ConfigureWindow::new(
WindowType::Configure(Box::new(ConfigureWindow::new(
shorten_path(self.config.directory.clone()),
self.config.theme.clone(),
)),
))),
);
return open_task.discard().chain(gain_focus(id));
}
Expand Down Expand Up @@ -153,7 +149,8 @@ impl App {
..Default::default()
});
let capture_window = CaptureWindow::new();
self.windows.insert(id, WindowType::Capture(capture_window));
self.windows
.insert(id, WindowType::Capture(Box::new(capture_window)));
return open_task
.discard()
.chain(gain_focus(id))
Expand Down
5 changes: 4 additions & 1 deletion src/utils/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ impl Config {
return File::options()
.read(true)
.create(true)
.truncate(false)
.write(true)
.open(path);
}
Expand All @@ -79,6 +80,8 @@ impl Config {
}

pub fn default_path() -> String {
// TODO: REPLACE the .unwrap() calls with .unwrap_or(DEFAULT_VALUE)

#[cfg(target_os = "windows")]
let path = format!(
"{}{}\\Pictures\\Capter",
Expand All @@ -95,7 +98,7 @@ impl Config {
DirBuilder::new()
.recursive(true)
.create(Path::new(&path))
.unwrap();
.expect("error creating directory.");

path
}
Expand Down
2 changes: 1 addition & 1 deletion src/utils/tray_icon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ pub fn tray_icon_listener() -> impl Stream<Item = AppEvent> {
});

loop {
if let Some(event) = reciever.recv().await {
if let Some(event) = reciever.recv().await {
match event {
TrayIconEvent::Click { button: Left, .. } => {
output.send(AppEvent::OpenConfigureWindow).await.unwrap()
Expand Down
5 changes: 4 additions & 1 deletion src/windows/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ impl ConfigureWindow {
match message {
ConfigEvent::UpdateFolderPath => Task::done(AppEvent::UpdateDirectory(id)),
ConfigEvent::OpenFolder => Task::done(AppEvent::OpenDirectory),
ConfigEvent::UpdateTheme(event) => self.theme.update(event).into(),
ConfigEvent::UpdateTheme(event) => {
self.theme.update(event);
Task::none()
}
ConfigEvent::RequestExit => Task::done(AppEvent::ExitApp),
}
}
Expand Down

0 comments on commit 04ba9d2

Please sign in to comment.