-
-
Notifications
You must be signed in to change notification settings - Fork 57
Expand file tree
/
Copy pathmain.rs
More file actions
106 lines (85 loc) · 2.72 KB
/
Copy pathmain.rs
File metadata and controls
106 lines (85 loc) · 2.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#![deny(clippy::dbg_macro)]
pub use steel::steel_vm;
mod app;
mod autoupdate;
mod clipboard;
mod commands;
mod config;
mod database;
mod debounce;
mod extensions;
mod platform;
mod quit;
mod styles;
mod unit_conversion;
mod utils;
use std::{collections::HashMap, fs::OpenOptions, path::Path};
use crate::{
app::tile::{self, Hotkeys, Tile},
config::Config,
platform::macos::{get_autostart_status, launching::Shortcut},
styles::load_font,
};
use log::info;
use tracing_subscriber::{EnvFilter, Layer, util::SubscriberInitExt};
use crate::platform::set_activation_policy_accessory;
fn main() -> iced::Result {
set_activation_policy_accessory();
let home = std::env::var("HOME").unwrap();
let file_path = home.clone() + "/.config/rustcast/config.toml";
if !Path::new(&file_path).exists() {
std::fs::create_dir_all(home.clone() + "/.config/rustcast").unwrap();
std::fs::write(
&file_path,
toml::to_string(&Config::default()).unwrap_or_else(|x| x.to_string()),
)
.unwrap();
}
let mut config: Config = match std::fs::read_to_string(&file_path) {
Ok(a) => toml::from_str(&a).unwrap_or(Config::default()),
Err(_) => Config::default(),
};
config.start_at_login = get_autostart_status();
if cfg!(debug_assertions) {
let sub = tracing_subscriber::fmt().finish();
EnvFilter::new("rustcast=info").with_subscriber(sub).init();
} else {
let file = OpenOptions::new()
.create(true)
.append(true)
.open(config.log_path.replace("~", &home))
.unwrap();
let sub = tracing_subscriber::fmt().with_writer(file).finish();
EnvFilter::new("rustcast=info").with_subscriber(sub).init();
};
info!("Config loaded");
let show_hide =
Shortcut::parse(&config.toggle_hotkey).unwrap_or(Shortcut::parse("option+space").unwrap());
let cbhist = Shortcut::parse(&config.clipboard_hotkey.to_lowercase())
.unwrap_or_else(|_| Shortcut::parse("cmd+shift+c").unwrap());
let mut shell_map = HashMap::new();
for shell in &config.shells {
if let Some(hk_str) = &shell.hotkey
&& let Ok(hk) = Shortcut::parse(hk_str)
{
shell_map.insert(hk, shell.clone());
}
}
let hotkeys = Hotkeys {
toggle: show_hide,
clipboard_hotkey: cbhist,
shells: shell_map,
handle: None,
};
info!("Hotkeys loaded");
info!("Starting rustcast");
iced::daemon(
move || tile::elm::new(hotkeys.clone(), &config),
tile::update::handle_update,
tile::elm::view,
)
.subscription(Tile::subscription)
.font(load_font())
.theme(Tile::theme)
.run()
}