2024-02-01 15:14:14 -07:00
|
|
|
// Copyright 2023 System76 <info@system76.com>
|
|
|
|
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
|
|
|
|
|
|
|
|
use cosmic::{
|
|
|
|
|
app::{Application, Settings},
|
2024-02-10 19:09:37 -07:00
|
|
|
iced::Limits,
|
2024-02-01 15:14:14 -07:00
|
|
|
};
|
2024-08-20 13:26:10 -06:00
|
|
|
use std::{env, fs, path::PathBuf, process};
|
2024-02-01 15:14:14 -07:00
|
|
|
|
|
|
|
|
use app::{App, Flags};
|
2024-08-20 13:26:10 -06:00
|
|
|
pub mod app;
|
2024-05-20 13:48:09 -06:00
|
|
|
pub mod clipboard;
|
2024-09-11 09:08:20 -06:00
|
|
|
use config::Config;
|
2024-08-20 13:26:10 -06:00
|
|
|
pub mod config;
|
2024-02-01 19:40:37 -07:00
|
|
|
pub mod dialog;
|
2024-02-01 15:14:14 -07:00
|
|
|
mod key_bind;
|
|
|
|
|
mod localize;
|
|
|
|
|
mod menu;
|
2024-03-01 16:10:30 -07:00
|
|
|
mod mime_app;
|
2024-03-04 12:28:16 -07:00
|
|
|
pub mod mime_icon;
|
2024-04-22 09:54:00 -06:00
|
|
|
mod mounter;
|
2024-02-01 15:14:14 -07:00
|
|
|
mod mouse_area;
|
|
|
|
|
mod operation;
|
2024-03-04 10:28:16 -07:00
|
|
|
mod spawn_detached;
|
2024-08-20 13:26:10 -06:00
|
|
|
use tab::Location;
|
|
|
|
|
pub mod tab;
|
2024-02-01 15:14:14 -07:00
|
|
|
|
2024-09-13 15:13:37 -06:00
|
|
|
pub(crate) fn err_str<T: ToString>(err: T) -> String {
|
|
|
|
|
err.to_string()
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-01 15:14:14 -07:00
|
|
|
pub fn home_dir() -> PathBuf {
|
|
|
|
|
match dirs::home_dir() {
|
|
|
|
|
Some(home) => home,
|
|
|
|
|
None => {
|
|
|
|
|
log::warn!("failed to locate home directory");
|
|
|
|
|
PathBuf::from("/")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-20 13:26:10 -06:00
|
|
|
/// Runs application in desktop mode
|
|
|
|
|
#[rustfmt::skip]
|
|
|
|
|
pub fn desktop() -> Result<(), Box<dyn std::error::Error>> {
|
|
|
|
|
env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("warn")).init();
|
|
|
|
|
|
|
|
|
|
localize::localize();
|
|
|
|
|
|
|
|
|
|
let (config_handler, config) = Config::load();
|
|
|
|
|
|
|
|
|
|
let locations = vec![
|
|
|
|
|
match dirs::desktop_dir() {
|
|
|
|
|
Some(path) => Location::Path(path),
|
|
|
|
|
None => Location::Path(home_dir()),
|
|
|
|
|
}
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
let mut settings = Settings::default();
|
|
|
|
|
settings = settings.theme(config.app_theme.theme());
|
|
|
|
|
settings = settings.size_limits(Limits::NONE.min_width(360.0).min_height(180.0));
|
|
|
|
|
settings = settings.exit_on_close(false);
|
|
|
|
|
settings = settings.transparent(true);
|
|
|
|
|
#[cfg(feature = "wayland")]
|
|
|
|
|
{
|
|
|
|
|
settings = settings.no_main_window(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let flags = Flags {
|
|
|
|
|
config_handler,
|
|
|
|
|
config,
|
|
|
|
|
mode: app::Mode::Desktop,
|
|
|
|
|
locations,
|
|
|
|
|
};
|
|
|
|
|
cosmic::app::run::<App>(settings, flags)?;
|
|
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-01 15:14:14 -07:00
|
|
|
/// Runs application with these settings
|
|
|
|
|
#[rustfmt::skip]
|
|
|
|
|
pub fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|
|
|
|
#[cfg(all(unix, not(target_os = "redox")))]
|
|
|
|
|
match fork::daemon(true, true) {
|
|
|
|
|
Ok(fork::Fork::Child) => (),
|
|
|
|
|
Ok(fork::Fork::Parent(_child_pid)) => process::exit(0),
|
|
|
|
|
Err(err) => {
|
|
|
|
|
eprintln!("failed to daemonize: {:?}", err);
|
|
|
|
|
process::exit(1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("warn")).init();
|
|
|
|
|
|
|
|
|
|
localize::localize();
|
|
|
|
|
|
2024-09-11 09:08:20 -06:00
|
|
|
let (config_handler, config) = Config::load();
|
2024-02-01 15:14:14 -07:00
|
|
|
|
2024-08-20 13:26:10 -06:00
|
|
|
let mut locations = Vec::new();
|
|
|
|
|
for arg in env::args().skip(1) {
|
|
|
|
|
let location = if &arg == "--trash" {
|
|
|
|
|
Location::Trash
|
|
|
|
|
} else {
|
|
|
|
|
match fs::canonicalize(&arg) {
|
|
|
|
|
Ok(absolute) => Location::Path(absolute),
|
|
|
|
|
Err(err) => {
|
|
|
|
|
log::warn!("failed to canonicalize {:?}: {}", arg, err);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
locations.push(location);
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-01 15:14:14 -07:00
|
|
|
let mut settings = Settings::default();
|
|
|
|
|
settings = settings.theme(config.app_theme.theme());
|
2024-02-10 19:09:37 -07:00
|
|
|
settings = settings.size_limits(Limits::NONE.min_width(360.0).min_height(180.0));
|
2024-08-09 09:59:25 -06:00
|
|
|
settings = settings.exit_on_close(false);
|
2024-02-01 15:14:14 -07:00
|
|
|
|
|
|
|
|
let flags = Flags {
|
|
|
|
|
config_handler,
|
|
|
|
|
config,
|
2024-08-20 13:26:10 -06:00
|
|
|
mode: app::Mode::App,
|
|
|
|
|
locations,
|
2024-02-01 15:14:14 -07:00
|
|
|
};
|
|
|
|
|
cosmic::app::run::<App>(settings, flags)?;
|
|
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|