Add about page, add icons, use open crate

This commit is contained in:
Jeremy Soller 2024-02-28 09:29:05 -07:00
parent ea93c7df32
commit b39c845456
No known key found for this signature in database
GPG key ID: D02FD439211AF56F
18 changed files with 296 additions and 46 deletions

131
Cargo.lock generated
View file

@ -257,6 +257,12 @@ version = "0.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "70033777eb8b5124a81a1889416543dddef2de240019b674c81285a2635a7e1e"
[[package]]
name = "anyhow"
version = "1.0.80"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5ad32ce52e4161730f7098c077cd2ed6229b5804ccf99e5366be1ab72a98b4e1"
[[package]]
name = "apply"
version = "0.3.0"
@ -1162,6 +1168,7 @@ dependencies = [
"mime_guess",
"notify",
"once_cell",
"open",
"paste",
"rust-embed",
"serde",
@ -1171,6 +1178,7 @@ dependencies = [
"test-log",
"tokio",
"trash",
"vergen",
]
[[package]]
@ -1446,6 +1454,15 @@ dependencies = [
"byteorder",
]
[[package]]
name = "deranged"
version = "0.3.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b42b6fa04a440b495c8b04d0e71b707c585f83cb9cb28cf8cd0d976c315e31b4"
dependencies = [
"powerfmt",
]
[[package]]
name = "derivative"
version = "2.2.0"
@ -2903,6 +2920,31 @@ dependencies = [
"windows-sys 0.48.0",
]
[[package]]
name = "is-docker"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "928bae27f42bc99b60d9ac7334e3a21d10ad8f1835a4e12ec3ec0464765ed1b3"
dependencies = [
"once_cell",
]
[[package]]
name = "is-wsl"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "173609498df190136aa7dea1a91db051746d339e18476eed5ca40521f02d7aa5"
dependencies = [
"is-docker",
"once_cell",
]
[[package]]
name = "itoa"
version = "1.0.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b1a46d1a171d865aa5f83f92695765caa047a9b4cbae2cbf37dbd613a793fd4c"
[[package]]
name = "jni"
version = "0.21.1"
@ -3625,6 +3667,12 @@ dependencies = [
"num-traits",
]
[[package]]
name = "num-conv"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9"
[[package]]
name = "num-integer"
version = "0.1.46"
@ -3730,6 +3778,15 @@ dependencies = [
"syn 2.0.51",
]
[[package]]
name = "num_threads"
version = "0.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c7398b9c8b70908f6371f47ed36737907c87c52af34c268fed0bf0ceb92ead9"
dependencies = [
"libc",
]
[[package]]
name = "objc"
version = "0.2.7"
@ -3822,6 +3879,17 @@ version = "1.19.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92"
[[package]]
name = "open"
version = "5.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eedff767bc49d336bff300224f73307ae36963c843e38dc9312a22171b012cbc"
dependencies = [
"is-wsl",
"libc",
"pathdiff",
]
[[package]]
name = "option-ext"
version = "0.2.0"
@ -3995,6 +4063,12 @@ version = "1.0.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "de3145af08024dea9fa9914f381a17b8fc6034dfb00f3a84013f7ff43f29ed4c"
[[package]]
name = "pathdiff"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8835116a5c179084a830efb3adc117ab007512b535bc1a21c991d3b32a6b44dd"
[[package]]
name = "percent-encoding"
version = "2.3.1"
@ -4133,6 +4207,12 @@ dependencies = [
"windows-sys 0.52.0",
]
[[package]]
name = "powerfmt"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391"
[[package]]
name = "ppv-lite86"
version = "0.2.17"
@ -4587,6 +4667,12 @@ dependencies = [
"owned_ttf_parser 0.15.2",
]
[[package]]
name = "rustversion"
version = "1.0.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7ffc183a10b4478d04cbbbfc96d0873219d962dd5accaff2ffbd4ceb7df837f4"
[[package]]
name = "rustybuzz"
version = "0.12.1"
@ -5127,6 +5213,39 @@ dependencies = [
"weezl",
]
[[package]]
name = "time"
version = "0.3.34"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c8248b6521bb14bc45b4067159b9b6ad792e2d6d754d6c41fb50e29fefe38749"
dependencies = [
"deranged",
"itoa",
"libc",
"num-conv",
"num_threads",
"powerfmt",
"serde",
"time-core",
"time-macros",
]
[[package]]
name = "time-core"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ef927ca75afb808a4d64dd374f00a2adf8d0fcff8e7b184af886c3c87ec4a3f3"
[[package]]
name = "time-macros"
version = "0.2.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7ba3a3ef41e6672a2f0f001392bb5dcd3ff0a9992d618ca761a11c3121547774"
dependencies = [
"num-conv",
"time-core",
]
[[package]]
name = "tiny-keccak"
version = "2.0.2"
@ -5548,6 +5667,18 @@ version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a"
[[package]]
name = "vergen"
version = "8.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e27d6bdd219887a9eadd19e1c34f32e47fa332301184935c6d9bca26f3cca525"
dependencies = [
"anyhow",
"cfg-if 1.0.0",
"rustversion",
"time",
]
[[package]]
name = "version-compare"
version = "0.1.1"

View file

@ -1,15 +1,21 @@
[package]
name = "cosmic-files"
version = "0.1.0"
authors = ["Jeremy Soller <jeremy@system76.com>"]
edition = "2021"
license = "GPL-3.0-only"
rust-version = "1.71"
[build-dependencies]
vergen = { version = "8", features = ["git", "gitcl"] }
[dependencies]
chrono = { version = "0.4", features = ["unstable-locales"] }
dirs = "5.0.1"
env_logger = "0.11"
image = "0.24"
once_cell = "1.19"
open = "5.0.2"
lexical-sort = "0.3.1"
log = "0.4"
mime_guess = "2"

11
build.rs Normal file
View file

@ -0,0 +1,11 @@
fn main() -> Result<(), Box<dyn std::error::Error>> {
// Rebuild if i18n files change
println!("cargo:rerun-if-changed=i18n");
vergen::EmitBuilder::builder()
.fail_on_error()
.git_commit_date()
.git_sha(true)
.emit()?;
Ok(())
}

1
debian/control vendored
View file

@ -4,6 +4,7 @@ Priority: optional
Maintainer: Jeremy Soller <jeremy@system76.com>
Build-Depends:
debhelper-compat (=13),
git,
just (>= 1.13.0),
pkg-config,
rust-all,

View file

@ -1,3 +1,4 @@
cosmic-files = COSMIC Files
empty-folder = Empty folder
empty-folder-hidden = Empty folder (has hidden items)
filesystem = Filesystem
@ -37,6 +38,10 @@ size = Size
# Context Pages
## About
about = About
git-description = Git commit {$hash} on {$date}
## Operations
operations = Operations
pending = Pending
@ -89,3 +94,4 @@ view = View
grid-view = Grid view
list-view = List view
menu-settings = Settings...
menu-about = About COSMIC Files...

View file

@ -15,6 +15,9 @@ desktop := APPID + '.desktop'
desktop-src := 'res' / desktop
desktop-dst := clean(rootdir / prefix) / 'share' / 'applications' / desktop
icons-src := 'res' / 'icons' / 'hicolor'
icons-dst := clean(rootdir / prefix) / 'share' / 'icons' / 'hicolor'
# Default recipe which runs `just build-release`
default: build-release
@ -60,7 +63,10 @@ run *args:
# Installs files
install:
install -Dm0755 {{bin-src}} {{bin-dst}}
install -Dm0755 {{desktop-src}} {{desktop-dst}}
install -Dm0644 {{desktop-src}} {{desktop-dst}}
for size in `ls {{icons-src}}`; do \
install -Dm0644 "{{icons-src}}/$size/apps/{{APPID}}.svg" "{{icons-dst}}/$size/apps/{{APPID}}.svg"; \
done
# Uninstalls installed files
uninstall:

View file

@ -1,11 +1,11 @@
#TODO: more build-out, desktop actions, translations?
[Desktop Entry]
Name=COSMIC File Manager
Name=COSMIC Files
Exec=cosmic-files %F
Terminal=false
Type=Application
StartupNotify=true
Icon=system-file-manager
Icon=com.system76.CosmicFiles
Categories=COSMIC;Utility;FileManager;
Keywords=Folder;Manager;
MimeType=inode/directory;

View file

@ -0,0 +1,12 @@
<svg width="128" height="128" viewBox="0 0 128 128" fill="none" xmlns="http://www.w3.org/2000/svg">
<g id="Size=128">
<path id="Rectangle 491" d="M4 28C4 23.5817 7.58172 20 12 20H47.8985C49.5893 20 51.2365 20.5357 52.6039 21.5301L61.5 28H116C120.418 28 124 31.5817 124 36V100C124 104.418 120.418 108 116 108H12C7.58172 108 4 104.418 4 100V28Z" fill="#008490"/>
<rect id="Rectangle 418" x="4" y="36" width="120" height="72" rx="8" fill="url(#paint0_linear_2004_703)"/>
</g>
<defs>
<linearGradient id="paint0_linear_2004_703" x1="124" y1="36" x2="20.4185" y2="126.742" gradientUnits="userSpaceOnUse">
<stop stop-color="#49BAC8"/>
<stop offset="1" stop-color="#229FAD"/>
</linearGradient>
</defs>
</svg>

After

Width:  |  Height:  |  Size: 701 B

View file

@ -0,0 +1,12 @@
<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
<g id="Size=16">
<path id="Rectangle 491" d="M1 4.5C1 3.67157 1.67157 3 2.5 3H5.37868C5.7765 3 6.15804 3.15804 6.43934 3.43934L7 4H13.5C14.3284 4 15 4.67157 15 5.5V11.5C15 12.3284 14.3284 13 13.5 13H2.5C1.67157 13 1 12.3284 1 11.5V4.5Z" fill="#008490"/>
<rect id="Rectangle 418" x="1" y="5" width="14" height="8" rx="1.5" fill="url(#paint0_linear_2004_698)"/>
</g>
<defs>
<linearGradient id="paint0_linear_2004_698" x1="15" y1="5" x2="3.43042" y2="15.6422" gradientUnits="userSpaceOnUse">
<stop stop-color="#49BAC8"/>
<stop offset="1" stop-color="#229FAD"/>
</linearGradient>
</defs>
</svg>

After

Width:  |  Height:  |  Size: 687 B

View file

@ -0,0 +1,12 @@
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<g id="Size=24">
<path id="Rectangle 491" d="M2 6.25C2 5.00736 3.00736 4 4.25 4H8.06802C8.66476 4 9.23705 4.23705 9.65901 4.65901L11 6H19.75C20.9926 6 22 7.00736 22 8.25V17.75C22 18.9926 20.9926 20 19.75 20H4.25C3.00736 20 2 18.9926 2 17.75V6.25Z" fill="#008490"/>
<rect id="Rectangle 418" x="2" y="8" width="20" height="12" rx="2.25" fill="url(#paint0_linear_2004_699)"/>
</g>
<defs>
<linearGradient id="paint0_linear_2004_699" x1="22" y1="8" x2="4.73642" y2="23.1236" gradientUnits="userSpaceOnUse">
<stop stop-color="#49BAC8"/>
<stop offset="1" stop-color="#229FAD"/>
</linearGradient>
</defs>
</svg>

After

Width:  |  Height:  |  Size: 700 B

View file

@ -0,0 +1,12 @@
<svg width="256" height="256" viewBox="0 0 256 256" fill="none" xmlns="http://www.w3.org/2000/svg">
<g id="Size=256">
<path id="Rectangle 491" d="M8 56C8 47.1634 15.1634 40 24 40H95.7971C99.1785 40 102.473 41.0713 105.208 43.0602L123 56H232C240.837 56 248 63.1634 248 72V200C248 208.837 240.837 216 232 216H24C15.1634 216 8 208.837 8 200V56Z" fill="#008490"/>
<rect id="Rectangle 418" x="8" y="72" width="240" height="144" rx="16" fill="url(#paint0_linear_2004_704)"/>
</g>
<defs>
<linearGradient id="paint0_linear_2004_704" x1="248" y1="72" x2="40.837" y2="253.483" gradientUnits="userSpaceOnUse">
<stop stop-color="#49BAC8"/>
<stop offset="1" stop-color="#229FAD"/>
</linearGradient>
</defs>
</svg>

After

Width:  |  Height:  |  Size: 701 B

View file

@ -0,0 +1,12 @@
<svg width="32" height="32" viewBox="0 0 32 32" fill="none" xmlns="http://www.w3.org/2000/svg">
<g id="Size=32">
<path id="Rectangle 491" d="M2 9C2 7.34315 3.34315 6 5 6H11.6704C12.4285 6 13.1586 6.28706 13.7137 6.80344L15 8H27C28.6569 8 30 9.34315 30 11V23C30 24.6569 28.6569 26 27 26H5C3.34315 26 2 24.6569 2 23V9Z" fill="#008490"/>
<rect id="Rectangle 418" x="2" y="10" width="28" height="16" rx="3" fill="url(#paint0_linear_2004_700)"/>
</g>
<defs>
<linearGradient id="paint0_linear_2004_700" x1="30" y1="10" x2="6.86084" y2="31.2844" gradientUnits="userSpaceOnUse">
<stop stop-color="#49BAC8"/>
<stop offset="1" stop-color="#229FAD"/>
</linearGradient>
</defs>
</svg>

After

Width:  |  Height:  |  Size: 673 B

View file

@ -0,0 +1,12 @@
<svg width="48" height="48" viewBox="0 0 48 48" fill="none" xmlns="http://www.w3.org/2000/svg">
<g id="Size=48">
<path id="Rectangle 491" d="M2 11.5C2 9.567 3.567 8 5.5 8H17.8716C18.6361 8 19.3796 8.25034 19.9885 8.71275L23 11H42.5C44.433 11 46 12.567 46 14.5V36.5C46 38.433 44.433 40 42.5 40H5.5C3.567 40 2 38.433 2 36.5V11.5Z" fill="#008490"/>
<rect id="Rectangle 418" x="2" y="14" width="44" height="26" rx="3.5" fill="url(#paint0_linear_2004_701)"/>
</g>
<defs>
<linearGradient id="paint0_linear_2004_701" x1="46" y1="14" x2="8.52466" y2="47.335" gradientUnits="userSpaceOnUse">
<stop stop-color="#49BAC8"/>
<stop offset="1" stop-color="#229FAD"/>
</linearGradient>
</defs>
</svg>

After

Width:  |  Height:  |  Size: 685 B

View file

@ -0,0 +1,12 @@
<svg width="64" height="64" viewBox="0 0 64 64" fill="none" xmlns="http://www.w3.org/2000/svg">
<g id="Size=64">
<path id="Rectangle 491" d="M2 14C2 11.7909 3.79086 10 6 10H23.9493C24.7946 10 25.6183 10.2678 26.302 10.7651L30.75 14H58C60.2091 14 62 15.7909 62 18V50C62 52.2091 60.2091 54 58 54H6C3.79086 54 2 52.2091 2 50V14Z" fill="#008490"/>
<rect id="Rectangle 418" x="2" y="18" width="60" height="36" rx="4" fill="url(#paint0_linear_2004_702)"/>
</g>
<defs>
<linearGradient id="paint0_linear_2004_702" x1="62" y1="18" x2="10.2093" y2="63.3709" gradientUnits="userSpaceOnUse">
<stop stop-color="#49BAC8"/>
<stop offset="1" stop-color="#229FAD"/>
</linearGradient>
</defs>
</svg>

After

Width:  |  Height:  |  Size: 682 B

View file

@ -9,7 +9,7 @@ use cosmic::{
futures::{self, SinkExt},
keyboard::{Event as KeyEvent, Key, Modifiers},
subscription::{self, Subscription},
window, Event, Length,
window, Alignment, Event, Length,
},
style,
widget::{self, segmented_button},
@ -31,7 +31,6 @@ use crate::{
menu,
operation::Operation,
tab::{self, ItemMetadata, Location, Tab},
util,
};
#[derive(Clone, Debug)]
@ -42,6 +41,7 @@ pub struct Flags {
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum Action {
About,
Copy,
Cut,
HistoryNext,
@ -70,6 +70,7 @@ pub enum Action {
impl Action {
pub fn message(self, entity_opt: Option<segmented_button::Entity>) -> Message {
match self {
Action::About => Message::ToggleContextPage(ContextPage::About),
Action::Copy => Message::Copy(entity_opt),
Action::Cut => Message::Cut(entity_opt),
Action::HistoryNext => Message::TabMessage(None, tab::Message::GoNext),
@ -112,6 +113,7 @@ pub enum Message {
DialogComplete,
DialogUpdate(DialogPage),
Key(Modifiers, Key),
LaunchUrl(String),
Modifiers(Modifiers),
MoveToTrash(Option<segmented_button::Entity>),
NewItem(Option<segmented_button::Entity>, bool),
@ -139,6 +141,7 @@ pub enum Message {
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum ContextPage {
About,
Operations,
Properties,
Settings,
@ -147,6 +150,7 @@ pub enum ContextPage {
impl ContextPage {
fn title(&self) -> String {
match self {
Self::About => fl!("about"),
Self::Operations => fl!("operations"),
Self::Properties => fl!("properties"),
Self::Settings => fl!("settings"),
@ -308,6 +312,37 @@ impl App {
Command::none()
}
fn about(&self) -> Element<Message> {
let cosmic_theme::Spacing { space_xxs, .. } = self.core().system_theme().cosmic().spacing;
let repository = "https://github.com/pop-os/cosmic-files";
let hash = env!("VERGEN_GIT_SHA");
let date = env!("VERGEN_GIT_COMMIT_DATE");
widget::column::with_children(vec![
widget::svg(widget::svg::Handle::from_memory(
&include_bytes!(
"../res/icons/hicolor/128x128/apps/com.system76.CosmicFiles.svg"
)[..],
))
.into(),
widget::text::title3(fl!("cosmic-files")).into(),
widget::button::link(repository)
.on_press(Message::LaunchUrl(repository.to_string()))
.padding(0)
.into(),
widget::button::link(fl!(
"git-description",
hash = hash,
date = date
))
.on_press(Message::LaunchUrl(format!("{}/commits/{}", repository, hash)))
.padding(0)
.into(),
])
.align_items(Alignment::Center)
.spacing(space_xxs)
.into()
}
fn operations(&self) -> Element<Message> {
let mut children = Vec::new();
@ -679,6 +714,12 @@ impl Application for App {
}
}
}
Message::LaunchUrl(url) => match open::that_detached(&url) {
Ok(()) => {}
Err(err) => {
log::warn!("failed to open {:?}: {}", url, err);
}
},
Message::Modifiers(modifiers) => {
self.modifiers = modifiers;
}
@ -915,9 +956,8 @@ impl Application for App {
]));
}
tab::Command::OpenFile(item_path) => {
let mut command = util::open_command(&item_path);
match command.spawn() {
Ok(_) => (),
match open::that_detached(&item_path) {
Ok(()) => (),
Err(err) => {
log::warn!("failed to open {:?}: {}", item_path, err);
}
@ -977,6 +1017,7 @@ impl Application for App {
}
Some(match self.context_page {
ContextPage::About => self.about(),
ContextPage::Operations => self.operations(),
ContextPage::Properties => self.properties(),
ContextPage::Settings => self.settings(),

View file

@ -20,7 +20,6 @@ mod mime_icon;
mod mouse_area;
mod operation;
mod tab;
mod util;
pub fn home_dir() -> PathBuf {
match dirs::home_dir() {

View file

@ -158,6 +158,8 @@ pub fn menu_bar<'a>(key_binds: &HashMap<KeyBind, Action>) -> Element<'a, Message
menu_item(fl!("list-view"), Action::TabViewList),
MenuTree::new(horizontal_rule(1)),
menu_item(fl!("menu-settings"), Action::Settings),
MenuTree::new(horizontal_rule(1)),
menu_item(fl!("menu-about"), Action::About),
],
),
])

View file

@ -1,37 +0,0 @@
use std::{path::PathBuf, process};
#[cfg(target_os = "linux")]
pub fn open_command(path: &PathBuf) -> process::Command {
let mut command = process::Command::new("xdg-open");
command.arg(path);
command
}
#[cfg(target_os = "macos")]
pub fn open_command(path: &PathBuf) -> process::Command {
let mut command = process::Command::new("open");
command.arg(path);
command
}
#[cfg(target_os = "redox")]
pub fn open_command(path: &PathBuf) -> process::Command {
let mut command = process::Command::new("launcher");
command.arg(path);
command
}
#[cfg(target_os = "windows")]
pub fn open_command(path: &PathBuf) -> process::Command {
use std::os::windows::process::CommandExt;
let mut command = process::Command::new("cmd");
command
.arg("/c")
.arg("start")
.raw_arg("\"\"")
.arg(path)
.creation_flags(0x08000000);
command
}