Convert to library

This commit is contained in:
Jeremy Soller 2024-02-01 15:14:14 -07:00
parent d6c58991c0
commit 87ad2f7dd9
No known key found for this signature in database
GPG key ID: D02FD439211AF56F
8 changed files with 1377 additions and 1335 deletions

1190
src/app.rs Normal file

File diff suppressed because it is too large Load diff

View file

@ -2,7 +2,7 @@ use cosmic::iced::keyboard::{KeyCode, Modifiers};
use serde::{Deserialize, Serialize};
use std::{collections::HashMap, fmt};
use crate::Action;
use crate::app::Action;
#[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize)]
pub enum Modifier {

85
src/lib.rs Normal file
View file

@ -0,0 +1,85 @@
// Copyright 2023 System76 <info@system76.com>
// SPDX-License-Identifier: GPL-3.0-only
use cosmic::{
app::{Application, Settings},
cosmic_config::{self, CosmicConfigEntry},
};
use std::{path::PathBuf, process};
use app::{App, Flags};
mod app;
use config::{Config, CONFIG_VERSION};
mod config;
mod key_bind;
mod localize;
mod menu;
mod mime_icon;
mod mouse_area;
mod operation;
mod tab;
pub fn home_dir() -> PathBuf {
match dirs::home_dir() {
Some(home) => home,
None => {
log::warn!("failed to locate home directory");
PathBuf::from("/")
}
}
}
/// 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();
let (config_handler, config) = match cosmic_config::Config::new(App::APP_ID, CONFIG_VERSION) {
Ok(config_handler) => {
let config = match Config::get_entry(&config_handler) {
Ok(ok) => ok,
Err((errs, config)) => {
log::info!("errors loading config: {:?}", errs);
config
}
};
(Some(config_handler), config)
}
Err(err) => {
log::error!("failed to create config handler: {}", err);
(None, Config::default())
}
};
let mut settings = Settings::default();
settings = settings.theme(config.app_theme.theme());
#[cfg(target_os = "redox")]
{
// Redox does not support resize if doing CSDs
settings = settings.client_decorations(false);
}
//TODO: allow size limits on iced_winit
//settings = settings.size_limits(Limits::NONE.min_width(400.0).min_height(200.0));
let flags = Flags {
config_handler,
config,
};
cosmic::app::run::<App>(settings, flags)?;
Ok(())
}

File diff suppressed because it is too large Load diff

View file

@ -13,7 +13,12 @@ use cosmic::{
};
use std::collections::HashMap;
use crate::{fl, tab, Action, ContextPage, KeyBind, Location, Message, Tab};
use crate::{
app::{Action, ContextPage, Message},
fl,
key_bind::KeyBind,
tab::{self, Location, Tab},
};
macro_rules! menu_button {
($($x:expr),+ $(,)?) => (

View file

@ -1,7 +1,7 @@
use cosmic::iced::futures::{channel::mpsc, SinkExt};
use std::{error::Error, future::Future, io, path::PathBuf, time};
use crate::Message;
use crate::app::Message;
fn err_str<T: ToString>(err: T) -> String {
err.to_string()

View file

@ -417,7 +417,7 @@ pub struct Item {
}
impl Item {
pub fn property_view(&self, core: &Core) -> Element<crate::Message> {
pub fn property_view(&self, core: &Core) -> Element<crate::app::Message> {
let mut section = widget::settings::view_section("");
section = section.add(widget::settings::item::item_row(vec![
widget::icon::icon(self.icon_handle_list.clone())
@ -1022,7 +1022,7 @@ mod tests {
use test_log::test;
use super::scan_path;
use crate::test_utils::{
use crate::app::test_utils::{
empty_fs, eq_path_item, simple_fs, sort_files, NAME_LEN, NUM_DIRS, NUM_FILES, NUM_NESTED,
};