Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Ticked when it is merged and tested, not when it is started.
- [ ] Extract while downloading: read the archive from a URL and never store it (for formats that can be read front to back)
- [ ] Windows Defender quarantining a file mid-run: read each file back before its bytes are cut (see Safety and polish)
- [ ] Packages: winget, Homebrew, AUR (`pacman -S hatchzip`), Gentoo GURU, Flatpak; Steam Deck notes (the AppImage runs in desktop mode)
- [ ] File-manager menus: Windows 11 top-level menu, COSMIC Files, Thunar
- [ ] File-manager menus: Windows 11 top-level menu, COSMIC Files (Thunar done)
- [ ] Antivirus false positives: signed Windows builds, a notarized macOS app (unsigned builds get flagged by VirusTotal engines and moved to the Trash by macOS), and an FAQ until then
- [ ] Android (several requests); iOS is out of reach for in-place work
- [ ] `.dmg` disk images (requested): read-only UDIF images (zlib, bzip2, LZFSE, LZMA chunks) holding HFS+ or APFS; extracting the files means reading the file system inside, so first check whether a Rust reader exists
Expand Down Expand Up @@ -70,7 +70,7 @@ Ticked when it is merged and tested, not when it is started.
- [x] Windows Explorer: HatchZip submenu with "Extract here", "Extract to a new folder" and "Test", per user without admin rights (`crates/shell`; registry keys tested in CI, not yet clicked in a real Explorer)
- [x] Linux: Dolphin service menu, GNOME Files scripts and Nemo actions (`crates/shell`; files tested, not yet clicked)
- [x] Wire `crates/shell` into the GUI: `--register-shell` / `--unregister-shell` (no window, for installers) and a switch in the Settings menu (AppImage registers `$APPIMAGE`)
- [ ] Thunar custom actions
- [x] Thunar custom actions (`crates/shell`; files tested, not yet clicked)
- [ ] Windows 11 top-level context menu (the classic one sits under "Show more options"); needs a packaged shell extension
- [ ] macOS: Finder Quick Action (needs a Mac to test)
- [x] App icon: `assets/icon/` (SVG, PNGs 16 to 1024, `.ico`, `.icns`, hicolor set), regenerated by `assets/icon/build.py`; also the site favicon
Expand Down
4 changes: 3 additions & 1 deletion crates/gui/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ fn run(launch: Launch) -> Result<()> {
return Ok(());
}
Launch::UnregisterShell => {
shell::unregister()?;
for skipped in shell::unregister()? {
println!("{skipped}");
}
println!("Context menu entries removed.");
return Ok(());
}
Expand Down
30 changes: 16 additions & 14 deletions crates/gui/src/main_window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -930,20 +930,22 @@ impl App {
let result = shell::set_menu(on);
post(move |app| {
let (text, bad) = match result {
Ok(()) if on => (
app.ui()
.global::<Messages>()
.invoke_menu_added()
.to_string(),
false,
),
Ok(()) => (
app.ui()
.global::<Messages>()
.invoke_menu_removed()
.to_string(),
false,
),
Ok(skipped) => {
let ui = app.ui();
let messages = ui.global::<Messages>();
let mut text = if on {
messages.invoke_menu_added()
} else {
messages.invoke_menu_removed()
}
.to_string();
// The other menus went through; say which one didn't.
for line in &skipped {
text.push(' ');
text.push_str(&sentence(line));
}
(text, !skipped.is_empty())
}
Err(e) => {
// Show the switch as it really is.
app.ui().set_shell_menu_on(!on);
Expand Down
2 changes: 1 addition & 1 deletion crates/gui/src/platform/linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::path::PathBuf;
/// The settings switch, named after this system's file manager.
pub const SHELL_MENU_NAME: super::ShellMenuName = super::ShellMenuName::Files;

/// The file managers hatchzip-shell knows (Dolphin, GNOME Files, Nemo).
/// The file managers hatchzip-shell knows (Dolphin, GNOME Files, Nemo, Thunar).
pub const SHELL_MENU: bool = true;

/// `$XDG_CONFIG_HOME/hatchzip`, or `~/.config/hatchzip`.
Expand Down
14 changes: 11 additions & 3 deletions crates/gui/src/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,21 @@ pub fn register() -> Result<Vec<String>> {
hatchzip_shell::register(&dirs, &launcher()?)
}

pub fn unregister() -> Result<()> {
/// Returns a line for each menu that was skipped.
pub fn unregister() -> Result<Vec<String>> {
hatchzip_shell::unregister(&hatchzip_shell::Dirs::current()?)
}

pub fn set_menu(on: bool) -> Result<()> {
/// Returns the lines for menus that were skipped, such as a Thunar file
/// HatchZip can't edit, so the switch can say so.
pub fn set_menu(on: bool) -> Result<Vec<String>> {
if on {
register().map(drop)
register().map(|places| {
places
.into_iter()
.filter(|p| p.contains(": skipped, "))
.collect()
})
} else {
unregister()
}
Expand Down
12 changes: 8 additions & 4 deletions crates/gui/tests/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@

use std::process::Command;

fn gui() -> Command {
/// The app with no display, and its config folders inside `home`, so a test
/// never reads or writes the real user's Thunar actions.
fn gui(home: &std::path::Path) -> Command {
let mut cmd = Command::new(env!("CARGO_BIN_EXE_hatchzip-gui"));
// No display to open a window on, so any attempt would fail the run.
cmd.env_remove("DISPLAY").env_remove("WAYLAND_DISPLAY");
cmd.env("XDG_CONFIG_HOME", home.join("config"))
.env("XDG_CONFIG_DIRS", home.join("system-config"));
cmd
}

Expand All @@ -20,7 +24,7 @@ fn register_and_unregister_without_a_window() {
let data = tempfile::tempdir().unwrap();
let menu = data.path().join("kio/servicemenus/hatchzip.desktop");

let out = gui()
let out = gui(data.path())
.arg("--register-shell")
.env("XDG_DATA_HOME", data.path())
.env_remove("APPIMAGE")
Expand All @@ -35,7 +39,7 @@ fn register_and_unregister_without_a_window() {
"{entry}"
);

let out = gui()
let out = gui(data.path())
.arg("--unregister-shell")
.env("XDG_DATA_HOME", data.path())
.output()
Expand All @@ -50,7 +54,7 @@ fn an_appimage_registers_itself_not_its_mount() {
return;
}
let data = tempfile::tempdir().unwrap();
let out = gui()
let out = gui(data.path())
.arg("--register-shell")
.env("XDG_DATA_HOME", data.path())
.env("APPIMAGE", "/home/sam/Apps/HatchZip-x86_64.AppImage")
Expand Down
7 changes: 6 additions & 1 deletion crates/gui/tests/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1296,7 +1296,12 @@ fn windows_end_to_end() {
let linux = std::env::consts::OS == "linux";
if linux {
// SAFETY: no other thread exists yet in this one-test binary.
unsafe { std::env::set_var("XDG_DATA_HOME", data.path()) };
unsafe {
std::env::set_var("XDG_DATA_HOME", data.path());
// The Thunar actions too, never the real user's.
std::env::set_var("XDG_CONFIG_HOME", data.path().join("config"));
std::env::set_var("XDG_CONFIG_DIRS", data.path().join("system-config"));
}
}
slint::platform::set_platform(Box::new(TestingBackend::new(TestingBackendOptions {
mock_time: false,
Expand Down
8 changes: 7 additions & 1 deletion crates/shell/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ pub struct Dirs {
/// `$XDG_DATA_HOME` on Linux. Unused on Windows, where entries go to the
/// per-user registry hive.
pub data: PathBuf,
/// `$XDG_CONFIG_HOME` on Linux, where Thunar keeps its actions. Unused
/// elsewhere.
pub config: PathBuf,
/// `$XDG_CONFIG_DIRS` on Linux, where Thunar's default actions come
/// from. Unused elsewhere.
pub system_config: Vec<PathBuf>,
}

impl Dirs {
Expand All @@ -94,7 +100,7 @@ pub fn register(dirs: &Dirs, gui: &Path) -> Result<Vec<String>> {
}

/// Removes every entry [`register`] could have written.
pub fn unregister(dirs: &Dirs) -> Result<()> {
pub fn unregister(dirs: &Dirs) -> Result<Vec<String>> {
platform::unregister(dirs)
}

Expand Down
Loading
Loading