diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6e794b7..0dfcbcd 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -63,6 +63,8 @@ jobs: run: | sudo apt-get update sudo apt-get install -y \ + appstream \ + desktop-file-utils \ libwebkit2gtk-4.1-dev \ libayatana-appindicator3-dev \ librsvg2-dev \ @@ -98,5 +100,15 @@ jobs: - name: Run Clippy run: cargo clippy --manifest-path src-tauri/Cargo.toml --all-targets -- -D warnings -D dead_code + - name: Run Clippy (Flatpak portal dialogs) + if: startsWith(matrix.os, 'ubuntu-') + run: cargo clippy --manifest-path src-tauri/Cargo.toml --all-targets --no-default-features --features flatpak -- -D warnings -D dead_code + + - name: Validate Linux desktop and AppStream metadata + if: startsWith(matrix.os, 'ubuntu-') + run: | + desktop-file-validate packaging/linux/com.codedead.deadhash.desktop + appstreamcli validate --pedantic --no-net packaging/linux/com.codedead.deadhash.metainfo.xml + - name: Run Rust tests run: cargo test --manifest-path src-tauri/Cargo.toml diff --git a/README.md b/README.md index e19c760..ce05b12 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -![DeadHash](https://i.imgur.com/4g0Jhrr.png) +![DeadHash](docs/screenshots/text.png) # DeadHash diff --git a/docs/screenshots/file.png b/docs/screenshots/file.png new file mode 100644 index 0000000..bad40f0 Binary files /dev/null and b/docs/screenshots/file.png differ diff --git a/docs/screenshots/light.png b/docs/screenshots/light.png new file mode 100644 index 0000000..bc6eca2 Binary files /dev/null and b/docs/screenshots/light.png differ diff --git a/docs/screenshots/main.png b/docs/screenshots/main.png new file mode 100644 index 0000000..4b73ec4 Binary files /dev/null and b/docs/screenshots/main.png differ diff --git a/docs/screenshots/settings.png b/docs/screenshots/settings.png new file mode 100644 index 0000000..7db3976 Binary files /dev/null and b/docs/screenshots/settings.png differ diff --git a/docs/screenshots/text.png b/docs/screenshots/text.png new file mode 100644 index 0000000..1799e59 Binary files /dev/null and b/docs/screenshots/text.png differ diff --git a/packaging/linux/com.codedead.deadhash.desktop b/packaging/linux/com.codedead.deadhash.desktop new file mode 100644 index 0000000..ea5ce28 --- /dev/null +++ b/packaging/linux/com.codedead.deadhash.desktop @@ -0,0 +1,11 @@ +[Desktop Entry] +Type=Application +Name=DeadHash +Comment=Calculate and verify file and text hashes and checksums +Exec=deadhash +Icon=com.codedead.deadhash +Terminal=false +Categories=Utility; +Keywords=hash;checksum;sha256;sha512;md5;blake3;crc32;verify; +StartupNotify=true +StartupWMClass=com.codedead.deadhash diff --git a/packaging/linux/com.codedead.deadhash.metainfo.xml b/packaging/linux/com.codedead.deadhash.metainfo.xml new file mode 100644 index 0000000..9fea442 --- /dev/null +++ b/packaging/linux/com.codedead.deadhash.metainfo.xml @@ -0,0 +1,83 @@ + + + com.codedead.deadhash + CC0-1.0 + GPL-3.0-only + + DeadHash + Calculate and verify file and text hashes and checksums + + + CodeDead + + + +

+ DeadHash is a free and open-source desktop utility for calculating and verifying file and + text hashes and checksums using fast, parallel native Rust implementations. +

+

Key features:

+ +
+ + com.codedead.deadhash.desktop + + https://codedead.com + https://github.com/CodeDead/DeadHash-js + https://github.com/CodeDead/DeadHash-js/issues + + + #d8e4f0 + #2f3e4e + + + + pointing + keyboard + + + + 640 + + + + + + + https://raw.githubusercontent.com/CodeDead/DeadHash-js/main/docs/screenshots/file.png + File hash calculation in dark theme + + + https://raw.githubusercontent.com/CodeDead/DeadHash-js/main/docs/screenshots/light.png + File hash calculation in light theme + + + https://raw.githubusercontent.com/CodeDead/DeadHash-js/main/docs/screenshots/text.png + Text hash calculation + + + https://raw.githubusercontent.com/CodeDead/DeadHash-js/main/docs/screenshots/settings.png + Configurable cryptographic, CRC, and non-cryptographic algorithms + + + https://raw.githubusercontent.com/CodeDead/DeadHash-js/main/docs/screenshots/main.png + Main file hash window + + + + + + https://github.com/CodeDead/DeadHash-js/releases + +

Beta release built with Tauri v2, Rust, React, and Mantine.

+
+
+
+
diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index bab0a02..abe5b45 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -839,6 +839,15 @@ dependencies = [ "syn 3.0.10", ] +[[package]] +name = "dlib" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab8ecd87370524b461f8557c119c405552c396ed91fc0a8eec68679eab26f94a" +dependencies = [ + "libloading 0.8.9", +] + [[package]] name = "dlopen2" version = "0.8.2" @@ -877,6 +886,12 @@ dependencies = [ "tendril", ] +[[package]] +name = "downcast-rs" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75b325c5dbd37f80359721ad39aca5a29fb04c89279657cffdda8736d0c0b9d2" + [[package]] name = "dpi" version = "0.1.2" @@ -2034,7 +2049,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0b76d3d67eb285f611b14654cd097f52eb7e83acc2b59913147f8ac695b61149" dependencies = [ "gtk-sys", - "libloading", + "libloading 0.9.1", ] [[package]] @@ -2052,6 +2067,16 @@ dependencies = [ "pkg-config", ] +[[package]] +name = "libloading" +version = "0.8.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d7c4b02199fee7c5d21a5ae7d8cfa79a6ef5bb2fc834d6e9058e89c825efdc55" +dependencies = [ + "cfg-if", + "windows-link 0.2.1", +] + [[package]] name = "libloading" version = "0.9.1" @@ -2693,7 +2718,7 @@ checksum = "cb7a42747bbcc4374e6922a15040dccacf720e4ce48a77e668f7116b9aa19a0a" dependencies = [ "base64 0.23.1", "indexmap 2.14.2", - "quick-xml", + "quick-xml 0.42.0", "serde", "time", ] @@ -2725,6 +2750,12 @@ dependencies = [ "windows-sys 0.101.0", ] +[[package]] +name = "pollster" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e9b9cf600136f5b976fbc5727d58c26e1ecab8ee23088d44ef1c7af793550ab" + [[package]] name = "portable-atomic" version = "1.15.0" @@ -2779,6 +2810,15 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "quick-xml" +version = "0.41.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e660451e55124f798a69a5af3f49ccfbefbd41910eefd25caf2393e1f3473ec1" +dependencies = [ + "memchr", +] + [[package]] name = "quick-xml" version = "0.42.0" @@ -2937,9 +2977,13 @@ dependencies = [ "objc2-foundation", "objc2-uniform-type-identifiers", "percent-encoding", + "pollster", "raw-window-handle", "wasm-bindgen", "wasm-bindgen-futures", + "wayland-backend", + "wayland-client", + "wayland-protocols", "web-sys", "windows-sys 0.61.2", ] @@ -3047,6 +3091,12 @@ dependencies = [ "syn 2.0.119", ] +[[package]] +name = "scoped-tls" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e1cf6437eb19a8f4a6cc0f7dca544973b0b78843adbfeb3683d1a94a0024a294" + [[package]] name = "scopeguard" version = "1.2.0" @@ -4378,6 +4428,66 @@ dependencies = [ "web-sys", ] +[[package]] +name = "wayland-backend" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38a91b4eaddff87b1cd1074985e3713da4af2c49742d1b356b2c01670a67a078" +dependencies = [ + "cc", + "downcast-rs", + "rustix", + "scoped-tls", + "smallvec", + "wayland-sys", +] + +[[package]] +name = "wayland-client" +version = "0.31.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3c36a0f861ad76d0901f2800b46321410d9f73f2ea88aac0650d86c32688073" +dependencies = [ + "bitflags", + "rustix", + "wayland-backend", + "wayland-scanner", +] + +[[package]] +name = "wayland-protocols" +version = "0.32.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23d0c813de3daa2ed6520af85a3bd49b0e722a3078506899aa9686fea58dc4b6" +dependencies = [ + "bitflags", + "wayland-backend", + "wayland-client", + "wayland-scanner", +] + +[[package]] +name = "wayland-scanner" +version = "0.31.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "338e30461b3a2b67d70eb30a6d89f8e0c93a833e07d2ae89085cd070c4a00ac0" +dependencies = [ + "proc-macro2", + "quick-xml 0.41.0", + "quote", +] + +[[package]] +name = "wayland-sys" +version = "0.31.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d8eab23fefc9e41f8e841df4a9c707e8a8c4ed26e944ef69297184de2785e3be" +dependencies = [ + "dlib", + "log", + "pkg-config", +] + [[package]] name = "web-sys" version = "0.3.107" diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 5b9caff..5e18986 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -6,18 +6,22 @@ authors = ["CodeDead "] license = "GPL-3.0-only" repository = "https://github.com/CodeDead/DeadHash-js" edition = "2024" -rust-version = "1.100.1" +rust-version = "1.94" [lib] name = "deadhash_lib" crate-type = ["rlib"] +[features] +default = ["tauri-plugin-dialog/gtk3"] +flatpak = ["tauri-plugin-dialog/xdg-portal"] + [build-dependencies] tauri-build = { version = "2.8.0", features = [] } [dependencies] tauri = { version = "2.13.0", features = [] } -tauri-plugin-dialog = "2.9.0" +tauri-plugin-dialog = { version = "2.9.0", default-features = false } tauri-plugin-opener = "2.7.3" tauri-plugin-os = "2.4.0" serde = { version = "1.0.229", features = ["derive"] } diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 9aa5100..37e6b9a 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -359,25 +359,54 @@ async fn export_hashes( .map_err(|err| format!("Export task failed: {err}"))? } +#[cfg(any(target_os = "linux", test))] +fn is_flatpak_env(flatpak_id: Option<&std::ffi::OsStr>, flatpak_info_exists: bool) -> bool { + flatpak_id.is_some_and(|value| !value.is_empty()) || flatpak_info_exists +} + +fn is_running_in_flatpak() -> bool { + #[cfg(target_os = "linux")] + { + is_flatpak_env( + std::env::var_os("FLATPAK_ID").as_deref(), + Path::new("/.flatpak-info").exists(), + ) + } + #[cfg(not(target_os = "linux"))] + { + false + } +} + +fn find_existing_file(candidates: impl IntoIterator) -> Option { + candidates.into_iter().find(|path| path.is_file()) +} + +#[tauri::command] +fn is_flatpak() -> bool { + is_running_in_flatpak() +} + #[tauri::command] async fn open_help_documentation(app: tauri::AppHandle) -> Result<(), String> { tokio::task::spawn_blocking(move || { - let resource_path = app - .path() - .resolve("docs/help.pdf", BaseDirectory::Resource) - .ok() - .filter(|path| path.is_file()); + let mut candidates = Vec::new(); + if let Ok(resource_path) = app.path().resolve("docs/help.pdf", BaseDirectory::Resource) { + candidates.push(resource_path); + } - #[cfg(debug_assertions)] - let help_path = resource_path.or_else(|| { - let dev_path = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("../docs/help.pdf"); - dev_path.is_file().then_some(dev_path) - }); + #[cfg(target_os = "linux")] + { + candidates.push(PathBuf::from("/app/lib/DeadHash/docs/help.pdf")); + candidates.push(PathBuf::from("/app/share/deadhash/docs/help.pdf")); + } - #[cfg(not(debug_assertions))] - let help_path = resource_path; + #[cfg(debug_assertions)] + { + candidates.push(PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("../docs/help.pdf")); + } - let help_path = help_path.ok_or_else(|| { + let help_path = find_existing_file(candidates).ok_or_else(|| { "Help documentation file (docs/help.pdf) could not be found".to_string() })?; @@ -402,6 +431,7 @@ pub fn run() { calculate_text_hash, cancel_text_hash, export_hashes, + is_flatpak, open_help_documentation ]) .run(tauri::generate_context!()) @@ -489,4 +519,32 @@ mod tests { let _ = fs::remove_file(&target); } + + #[test] + fn detects_flatpak_environment() { + use std::ffi::OsStr; + + assert!(!is_flatpak_env(None, false)); + assert!(!is_flatpak_env(Some(OsStr::new("")), false)); + assert!(is_flatpak_env( + Some(OsStr::new("com.codedead.deadhash")), + false + )); + assert!(is_flatpak_env(None, true)); + } + + #[test] + fn finds_first_existing_candidate_file() { + let missing = + std::env::temp_dir().join(format!("deadhash_missing_help_{}.pdf", std::process::id())); + let existing = + std::env::temp_dir().join(format!("deadhash_existing_help_{}.pdf", std::process::id())); + fs::write(&existing, b"%PDF-1.4").unwrap(); + + let resolved = find_existing_file([missing.clone(), existing.clone()]); + assert_eq!(resolved.as_deref(), Some(existing.as_path())); + assert_eq!(find_existing_file([missing]), None); + + let _ = fs::remove_file(&existing); + } } diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index 9d26476..e2db327 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -10,13 +10,12 @@ "frontendDist": "../dist" }, "app": { + "enableGTKAppId": true, "windows": [ { "title": "DeadHash", "width": 960, "height": 560, - "minWidth": 640, - "minHeight": 420, "decorations": true, "dragDropEnabled": true } diff --git a/src/App.jsx b/src/App.jsx index 499e60a..04251c3 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -9,7 +9,7 @@ import { DropZone } from './components/DropZone'; import { ErrorBoundary } from './components/ErrorBoundary'; import { UpdateModal } from './components/UpdateModal'; import FileHashPage from './pages/FileHashPage'; -import { checkForAppUpdates } from './services/updater'; +import { checkForAppUpdates, shouldCheckForUpdates } from './services/updater'; import { useHashActions } from './state/hashContext'; import { useSettings } from './state/settingsContext'; @@ -18,7 +18,7 @@ const SettingsPage = lazy(() => import('./pages/SettingsPage')); const AboutPage = lazy(() => import('./pages/AboutPage')); const App = () => { - const { canDragDrop, autoUpdate, t } = useSettings(); + const { canDragDrop, autoUpdate, isFlatpak, isFlatpakResolved, t } = useSettings(); const { setFilePath } = useHashActions(); const initialAutoUpdateRef = useRef(autoUpdate); const updateCheckedRef = useRef(false); @@ -27,7 +27,17 @@ const App = () => { const [navOpened, { toggle: toggleNav, close: closeNav }] = useDisclosure(false); useEffect(() => { - if (!initialAutoUpdateRef.current || updateCheckedRef.current) return undefined; + if (updateCheckedRef.current || !isFlatpakResolved) return undefined; + if ( + !shouldCheckForUpdates({ + autoUpdate: initialAutoUpdateRef.current, + isFlatpak, + isFlatpakResolved, + }) + ) { + updateCheckedRef.current = true; + return undefined; + } let active = true; const controller = new AbortController(); @@ -47,7 +57,7 @@ const App = () => { active = false; controller.abort(); }; - }, []); + }, [isFlatpak, isFlatpakResolved]); return ( diff --git a/src/pages/SettingsPage.jsx b/src/pages/SettingsPage.jsx index 433ee2d..8f4f5a1 100644 --- a/src/pages/SettingsPage.jsx +++ b/src/pages/SettingsPage.jsx @@ -36,6 +36,8 @@ const SettingsPage = () => { const { locale, autoUpdate, + isFlatpak, + isFlatpakResolved, canDragDrop, showHeaderThemeButton, showHeaderLanguageButton, @@ -51,6 +53,7 @@ const SettingsPage = () => { setUppercaseHashes, resetSettings, } = useSettings(); + const showUpdateControls = isFlatpakResolved && !isFlatpak; const { algorithms } = useHashAlgorithms(); const { setAlgorithmEnabled, resetAlgorithms } = useHashActions(); const { colorScheme, setColorScheme } = useMantineColorScheme(); @@ -68,13 +71,15 @@ const SettingsPage = () => { <> - + {showUpdateControls ? ( + + ) : null}
@@ -83,11 +88,13 @@ const SettingsPage = () => { - setAutoUpdate(e.currentTarget.checked)} - label={t.autoUpdate} - /> + {showUpdateControls ? ( + setAutoUpdate(e.currentTarget.checked)} + label={t.autoUpdate} + /> + ) : null} setCanDragDrop(e.currentTarget.checked)} @@ -212,10 +219,12 @@ const SettingsPage = () => {
- - + + {showUpdateControls ? ( + + ) : null} diff --git a/src/services/tauri.js b/src/services/tauri.js index 5769408..d1fb207 100644 --- a/src/services/tauri.js +++ b/src/services/tauri.js @@ -52,6 +52,11 @@ export const openExternalUrl = (url) => openUrl(url); export const openHelpDocumentation = () => invoke('open_help_documentation'); +export const isFlatpak = () => + invoke('is_flatpak') + .then((result) => Boolean(result)) + .catch(() => false); + export const getAppVersion = () => getVersion(); export const getPlatformName = () => platform(); diff --git a/src/services/updater.js b/src/services/updater.js index 5b0a337..83a3f61 100644 --- a/src/services/updater.js +++ b/src/services/updater.js @@ -179,6 +179,9 @@ const createRequestSignal = (externalSignal) => { return { signal: controller.signal, cleanup }; }; +export const shouldCheckForUpdates = ({ autoUpdate, isFlatpak, isFlatpakResolved }) => + Boolean(autoUpdate && isFlatpakResolved && !isFlatpak); + export const checkForAppUpdates = async ({ getVersion = getAppVersion, getPlatform = getPlatformName, diff --git a/src/state/SettingsProvider.jsx b/src/state/SettingsProvider.jsx index b1b277c..c481b3b 100644 --- a/src/state/SettingsProvider.jsx +++ b/src/state/SettingsProvider.jsx @@ -1,5 +1,6 @@ import { useCallback, useEffect, useMemo, useState } from 'react'; import { getMessages, isValidLocale, loadMessages } from '../i18n'; +import { isFlatpak } from '../services/tauri'; import { HashDisplayContext, LocaleContext, @@ -11,11 +12,27 @@ import { removeStoredValue, writeStoredValue } from './storage'; export const SettingsProvider = ({ children }) => { const [settings, setSettings] = useState(() => loadInitialSettings()); + const [flatpakState, setFlatpakState] = useState({ resolved: false, value: false }); const [loadedLocale, setLoadedLocale] = useState(() => ({ code: settings.locale, messages: getMessages(settings.locale), })); + useEffect(() => { + let active = true; + isFlatpak() + .then((value) => { + if (active) setFlatpakState({ resolved: true, value: Boolean(value) }); + }) + .catch(() => { + if (active) setFlatpakState({ resolved: true, value: false }); + }); + + return () => { + active = false; + }; + }, []); + useEffect(() => { document.documentElement.lang = settings.locale; }, [settings.locale]); @@ -145,10 +162,12 @@ export const SettingsProvider = ({ children }) => { const value = useMemo( () => ({ ...settings, + isFlatpak: flatpakState.value, + isFlatpakResolved: flatpakState.resolved, t, ...actionsValue, }), - [settings, t, actionsValue], + [settings, flatpakState, t, actionsValue], ); return ( diff --git a/tests/updater.test.js b/tests/updater.test.js index 11d282f..9775d9d 100644 --- a/tests/updater.test.js +++ b/tests/updater.test.js @@ -6,6 +6,7 @@ import { isNewerVersion, normalizeArch, sanitizeHttpUrl, + shouldCheckForUpdates, } from '../src/services/updater.js'; test('isNewerVersion follows SemVer precedence including prereleases', () => { @@ -185,3 +186,22 @@ test('findMatchingPlatform skips entries with invalid URLs in favor of valid por 'https://example.com/mac', ); }); + +test('shouldCheckForUpdates suppresses checks until Flatpak detection resolves and inside Flatpak', () => { + assert.equal( + shouldCheckForUpdates({ autoUpdate: true, isFlatpak: false, isFlatpakResolved: false }), + false, + ); + assert.equal( + shouldCheckForUpdates({ autoUpdate: true, isFlatpak: true, isFlatpakResolved: true }), + false, + ); + assert.equal( + shouldCheckForUpdates({ autoUpdate: false, isFlatpak: false, isFlatpakResolved: true }), + false, + ); + assert.equal( + shouldCheckForUpdates({ autoUpdate: true, isFlatpak: false, isFlatpakResolved: true }), + true, + ); +});