From 781bb20cc4b7cd777f9990a39c295fa8683c5544 Mon Sep 17 00:00:00 2001 From: alvinosh <38663469+alvinosh@users.noreply.github.com> Date: Tue, 9 Apr 2024 09:41:02 +0000 Subject: [PATCH] #8: Allow multiple selection (#23) * Added Windows Builds * Added Release Step To Release Workflow * updated workflows * linux fix * added more supported file types * removed outdated code * added tags * Revert for tag filter code * Enabling devtools * Quick Push * added support for folders * removed comment * Added Drag And Drop * added macos workflows * new build script * new build script fix * added upload * added build step * fixed order * upload macos * new mac fix * merge branch --------- Co-authored-by: Kawsar Ahmed Co-authored-by: Kirill Taran --- .github/workflows/build.yml | 110 ++++++++++---------- .github/workflows/release.yml | 37 +++++++ package.json | 1 + src-tauri/Cargo.lock | 101 ++++++++++++++++++ src-tauri/Cargo.toml | 8 +- src-tauri/src/main.rs | 50 +++++++++ src-tauri/tauri.conf.json | 154 ++++++++++++++++------------ src/lib/components/Gallery.svelte | 30 +++--- src/lib/store/index.ts | 2 +- src/routes/+page.svelte | 164 ++++++++++++++++++++++-------- 10 files changed, 477 insertions(+), 180 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 224a6c2..56a0a7a 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -6,74 +6,68 @@ env: on: [push] jobs: - build-linux: - runs-on: ubuntu-latest - + build-tauri: + permissions: + contents: write + strategy: + fail-fast: false + matrix: + settings: + - platform: 'macos-latest' # for Intel based macs. + args: '--target universal-apple-darwin' + - platform: 'ubuntu-22.04' # for Tauri v1 you could replace this with ubuntu-20.04. + args: '' + - platform: 'windows-latest' + args: '' + + runs-on: ${{ matrix.settings.platform }} steps: - - name: Checkout code - uses: actions/checkout@v4 + - uses: actions/checkout@v4 - - name: Install Rust - uses: dtolnay/rust-toolchain@stable + - name: setup node + uses: actions/setup-node@v4 with: - toolchain: stable - components: rustfmt, clippy + node-version: lts/* - - name: Setup Node.js - uses: actions/setup-node@v4 + - name: install Rust stable + uses: dtolnay/rust-toolchain@stable with: - node-version: '20.x' + # Those targets are only used on macos runners so it's in an `if` to slightly speed up windows and linux builds. + targets: ${{ matrix.settings.platform == 'macos-latest' && 'aarch64-apple-darwin,x86_64-apple-darwin' || '' }} - - name: Install dependencies + - name: install dependencies (ubuntu only) + if: matrix.settings.platform == 'ubuntu-22.04' # This must match the platform value defined above. run: | sudo apt-get update - sudo apt-get install -y libgtk-3-dev \ - webkit2gtk-4.0 javascriptcoregtk-4.1 libappindicator3-dev \ - librsvg2-dev patchelf libdbus-1-dev \ - pkg-config \ - - - name: Fetch Node.js Dependencies - run: yarn - - - name: Build Release version - run: yarn tauri build - - - name: Upload AppImage + sudo apt-get install -y libwebkit2gtk-4.0-dev libwebkit2gtk-4.1-dev libappindicator3-dev librsvg2-dev patchelf + # webkitgtk 4.0 is for Tauri v1 - webkitgtk 4.1 is for Tauri v2. + # You can remove the one that doesn't apply to your app to speed up the workflow a bit. + - name: install frontend dependencies + run: yarn install + + - uses: tauri-apps/tauri-action@v0 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + releaseBody: 'See the assets to download this version and install.' + releaseDraft: true + prerelease: false + args: ${{ matrix.settings.args }} + + - name: Upload Windows Build + uses: actions/upload-artifact@v4 + if: matrix.settings.platform == 'windows-latest' + with: + name: ark-gallery-Windows.zip + path: ./src-tauri/target/release/bundle/ + - name: Upload Linux AppImage + if: matrix.settings.platform == 'ubuntu-22.04' uses: actions/upload-artifact@v4 with: name: ark-gallery.AppImage path: ./src-tauri/target/release/bundle/appimage/ark-gallery_*_amd64.AppImage - - build-windows: - runs-on: windows-latest - - steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: Install Rust - uses: dtolnay/rust-toolchain@stable - with: - toolchain: stable - components: rustfmt, clippy - - - name: Setup Node.js - uses: actions/setup-node@v4 - with: - node-version: '20.x' - - - name: Install dependencies - run: | - choco install -y nodejs - - - name: Fetch Node.js Dependencies - run: yarn - - - name: Build Release version - run: yarn tauri build - - - name: Upload App - uses: actions/upload-artifact@v2 + - name: Upload MacOS App + if: matrix.settings.platform == 'macos-latest' + uses: actions/upload-artifact@v4 with: - name: ark-gallery-Windows.zip - path: ./src-tauri/target/release/bundle/ + name: ark-gallery.app + path: ./src-tauri/target/release/bundle/macos/ diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 1c7a83a..04559c9 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -77,3 +77,40 @@ jobs: with: artifacts: './target/release/bundle/*.exe' token: ${{ secrets.GITHUB_TOKEN }} + release-macos: + runs-on: macos-latest + environment: Development + steps: + - uses: actions/checkout@v4 + + - name: Install Rust + uses: dtolnay/rust-toolchain@stable + with: + toolchain: stable + override: true + components: rustfmt, clippy + + - name: Setup Node.js + uses: actions/setup-node@v3.2.0 + with: + node-version: '16.x' + + - name: Install dependencies (adjust as needed) + run: brew install pkg-config openssl webkit2gtk gtk+3 + + - name: Fetch Node.js dependencies + run: yarn + + - name: Build Release version + run: yarn tauri build + + - name: Create Release Archive (adjust filename/compression if needed) + run: | + cd src-tauri/target/release/bundle + zip -r ark-gallery-macOS.zip . + + - name: Release macOS App + uses: ncipollo/release-action@v1 + with: + artifacts: './ark-gallery-macOS.zip' + token: ${{ secrets.GITHUB_TOKEN }} diff --git a/package.json b/package.json index eefea98..92376f7 100644 --- a/package.json +++ b/package.json @@ -38,6 +38,7 @@ "type": "module", "dependencies": { "@sveltejs/adapter-vercel": "^5.1.0", + "@tauri-apps/api": "^1.5.3", "bits-ui": "^0.16.0", "clsx": "^2.1.0", "lucide-svelte": "^0.316.0", diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index 3836cfd..fc4d995 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -1634,6 +1634,17 @@ dependencies = [ "objc_exception", ] +[[package]] +name = "objc-foundation" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1add1b659e36c9607c7aab864a76c7a4c2760cd0cd2e120f3fb8b952c7e22bf9" +dependencies = [ + "block", + "objc", + "objc_id", +] + [[package]] name = "objc_exception" version = "0.1.2" @@ -2142,6 +2153,30 @@ version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" +[[package]] +name = "rfd" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0149778bd99b6959285b0933288206090c50e2327f47a9c463bfdbf45c8823ea" +dependencies = [ + "block", + "dispatch", + "glib-sys", + "gobject-sys", + "gtk-sys", + "js-sys", + "lazy_static", + "log", + "objc", + "objc-foundation", + "objc_id", + "raw-window-handle", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "windows 0.37.0", +] + [[package]] name = "rustc-demangle" version = "0.1.23" @@ -2622,6 +2657,7 @@ dependencies = [ "percent-encoding", "rand 0.8.5", "raw-window-handle", + "rfd", "semver", "serde", "serde_json", @@ -3188,6 +3224,18 @@ dependencies = [ "wasm-bindgen-shared", ] +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.42" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "76bc14366121efc8dbb487ab05bcc9d346b3b5ec0eaa76e46594cabbe51762c0" +dependencies = [ + "cfg-if", + "js-sys", + "wasm-bindgen", + "web-sys", +] + [[package]] name = "wasm-bindgen-macro" version = "0.2.92" @@ -3217,6 +3265,16 @@ version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "af190c94f2773fdb3729c55b007a722abb5384da03bc0986df4c289bf5567e96" +[[package]] +name = "web-sys" +version = "0.3.69" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77afa9a11836342370f4817622a2f0f418b134426d91a82dfb48f532d2ec13ef" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + [[package]] name = "webkit2gtk" version = "0.18.2" @@ -3333,6 +3391,19 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +[[package]] +name = "windows" +version = "0.37.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57b543186b344cc61c85b5aab0d2e3adf4e0f99bc076eff9aa5927bcc0b8a647" +dependencies = [ + "windows_aarch64_msvc 0.37.0", + "windows_i686_gnu 0.37.0", + "windows_i686_msvc 0.37.0", + "windows_x86_64_gnu 0.37.0", + "windows_x86_64_msvc 0.37.0", +] + [[package]] name = "windows" version = "0.39.0" @@ -3466,6 +3537,12 @@ version = "0.52.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bcf46cf4c365c6f2d1cc93ce535f2c8b244591df96ceee75d8e83deb70a9cac9" +[[package]] +name = "windows_aarch64_msvc" +version = "0.37.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2623277cb2d1c216ba3b578c0f3cf9cdebeddb6e66b1b218bb33596ea7769c3a" + [[package]] name = "windows_aarch64_msvc" version = "0.39.0" @@ -3484,6 +3561,12 @@ version = "0.52.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "da9f259dd3bcf6990b55bffd094c4f7235817ba4ceebde8e6d11cd0c5633b675" +[[package]] +name = "windows_i686_gnu" +version = "0.37.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3925fd0b0b804730d44d4b6278c50f9699703ec49bcd628020f46f4ba07d9e1" + [[package]] name = "windows_i686_gnu" version = "0.39.0" @@ -3502,6 +3585,12 @@ version = "0.52.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b474d8268f99e0995f25b9f095bc7434632601028cf86590aea5c8a5cb7801d3" +[[package]] +name = "windows_i686_msvc" +version = "0.37.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce907ac74fe331b524c1298683efbf598bb031bc84d5e274db2083696d07c57c" + [[package]] name = "windows_i686_msvc" version = "0.39.0" @@ -3520,6 +3609,12 @@ version = "0.52.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1515e9a29e5bed743cb4415a9ecf5dfca648ce85ee42e15873c3cd8610ff8e02" +[[package]] +name = "windows_x86_64_gnu" +version = "0.37.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2babfba0828f2e6b32457d5341427dcbb577ceef556273229959ac23a10af33d" + [[package]] name = "windows_x86_64_gnu" version = "0.39.0" @@ -3550,6 +3645,12 @@ version = "0.52.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "77ca79f2451b49fa9e2af39f0747fe999fcda4f5e241b2898624dca97a1f2177" +[[package]] +name = "windows_x86_64_msvc" +version = "0.37.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4dd6dc7df2d84cf7b33822ed5b86318fb1781948e9663bacd047fc9dd52259d" + [[package]] name = "windows_x86_64_msvc" version = "0.39.0" diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 14a35fe..f7794c7 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -17,7 +17,13 @@ tauri-build = { version = "1.5.1", features = [] } [dependencies] serde_json = "1.0" serde = { version = "1.0", features = ["derive"] } -tauri = { version = "1.6.1", features = [] } +tauri = { version = "1.6.1", features = [ + "protocol-asset", + "fs-read-file", + "fs-read-dir", + "dialog-open", + "devtools" +] } [features] # this feature is used for production builds or when `devPath` points to the filesystem and the built-in dev server is disabled. diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index e6ad770..529a661 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -1,8 +1,58 @@ // Prevents additional console window on Windows in release, DO NOT REMOVE!! #![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] +use std::{fs::{self}, time::{Duration, SystemTime}}; +use serde::Serialize; + + +#[tauri::command] +fn get_file_metadata(file_path: String) -> Result { + match fs::metadata(&file_path) { + Ok(metadata) => { + let file_type = metadata.file_type(); + let file_size = metadata.len(); + let created_time = metadata.created().unwrap_or( + SystemTime::UNIX_EPOCH + ); + let modified_time = metadata.modified().unwrap_or( + SystemTime::UNIX_EPOCH + ); + let accessed_time = metadata.accessed().unwrap_or( + SystemTime::UNIX_EPOCH + ); + + + + + Ok(MetadataInfo { + file_type: if file_type.is_dir() { + "directory".to_string() + } else { + "file".to_string() + }, + file_size, + created_time: created_time.duration_since(SystemTime::UNIX_EPOCH).unwrap_or(Duration::from_secs(0)).as_secs().to_string(), + modified_time: modified_time.duration_since(SystemTime::UNIX_EPOCH).unwrap_or(Duration::from_secs(0)).as_secs().to_string(), + accessed_time: accessed_time.duration_since(SystemTime::UNIX_EPOCH).unwrap_or(Duration::from_secs(0)).as_secs().to_string(), + }) + } + Err(err) => Err(err.to_string()), + } +} + +#[derive(Serialize)] +struct MetadataInfo { + file_type: String, + file_size: u64, + created_time: String, + modified_time: String, + accessed_time: String, +} + + fn main() { tauri::Builder::default() + .invoke_handler(tauri::generate_handler![get_file_metadata]) .run(tauri::generate_context!()) .expect("error while running tauri application"); } diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index e3d091b..a06f015 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -1,66 +1,92 @@ { - "$schema": "../node_modules/@tauri-apps/cli/schema.json", - "build": { - "beforeBuildCommand": "npm run build", - "beforeDevCommand": "npm run dev", - "devPath": "http://localhost:5173", - "distDir": "../build" - }, - "package": { - "productName": "ark-gallery", - "version": "0.1.0" - }, - "tauri": { - "allowlist": { - "all": false - }, - "bundle": { - "active": true, - "category": "DeveloperTool", - "copyright": "", - "deb": { - "depends": [] - }, - "externalBin": [], - "icon": [ - "icons/32x32.png", - "icons/128x128.png", - "icons/128x128@2x.png", - "icons/icon.icns", - "icons/icon.ico" - ], - "identifier": "dev.ark-builders.gallery", - "longDescription": "", - "macOS": { - "entitlements": null, - "exceptionDomain": "", - "frameworks": [], - "providerShortName": null, - "signingIdentity": null - }, - "resources": [], - "shortDescription": "", - "targets": "all", - "windows": { - "certificateThumbprint": null, - "digestAlgorithm": "sha256", - "timestampUrl": "" - } - }, - "security": { - "csp": null - }, - "updater": { - "active": false - }, - "windows": [ - { - "fullscreen": false, - "height": 600, - "resizable": true, - "title": "ARK Gallery", - "width": 800 - } - ] - } + "$schema": "../node_modules/@tauri-apps/cli/schema.json", + "build": { + "beforeBuildCommand": "npm run build", + "beforeDevCommand": "npm run dev", + "devPath": "http://localhost:5173", + "distDir": "../build" + }, + "package": { + "productName": "ark-gallery", + "version": "0.1.0" + }, + "tauri": { + "allowlist": { + "protocol": { + "all": false, + "asset": true, + "assetScope": ["asset://"] + }, + "all": false, + "dialog": { + "all": false, + "ask": false, + "confirm": false, + "message": false, + "open": true, + "save": false + }, + "fs": { + "all": false, + "copyFile": false, + "createDir": false, + "exists": false, + "readDir": true, + "readFile": true, + "removeDir": false, + "removeFile": false, + "renameFile": false, + "scope": [], + "writeFile": false + } + }, + "bundle": { + "active": true, + "category": "DeveloperTool", + "copyright": "", + "deb": { + "depends": [] + }, + "externalBin": [], + "icon": [ + "icons/32x32.png", + "icons/128x128.png", + "icons/128x128@2x.png", + "icons/icon.icns", + "icons/icon.ico" + ], + "identifier": "dev.ark-builders.gallery", + "longDescription": "", + "macOS": { + "entitlements": null, + "exceptionDomain": "", + "frameworks": [], + "providerShortName": null, + "signingIdentity": null + }, + "resources": [], + "shortDescription": "", + "targets": "all", + "windows": { + "certificateThumbprint": null, + "digestAlgorithm": "sha256", + "timestampUrl": "" + } + }, + "security": { + "csp": "default-src 'self'; img-src 'self' asset: https://asset.localhost" + }, + "updater": { + "active": false + }, + "windows": [ + { + "fullscreen": false, + "height": 600, + "resizable": true, + "title": "ARK Gallery", + "width": 800 + } + ] + } } diff --git a/src/lib/components/Gallery.svelte b/src/lib/components/Gallery.svelte index c7efe65..bea223f 100644 --- a/src/lib/components/Gallery.svelte +++ b/src/lib/components/Gallery.svelte @@ -7,20 +7,18 @@ $: noImage = $galleryStore.selectedTag && !$galleryStore.selectedFilteredImages.length -{#if $galleryStore.images?.length} -
- {#if noImage} - -

No Image Found

- {:else} - {#each $galleryStore.selectedFilteredImages.length ? $galleryStore.selectedFilteredImages : $galleryStore.images as image, i} - - {/each} - {/if} -
-{/if} + ? 'flex flex-col gap-5 items-center w-full justify-center' + : 'grid grid-cols-2 md:grid-cols-4 xl:grid-cols-6'}" +> + {#if noImage} + +

No Image Found

+ {:else} + {#each $galleryStore.selectedFilteredImages.length ? $galleryStore.selectedFilteredImages : $galleryStore.images as image, i} + + {/each} + {/if} + diff --git a/src/lib/store/index.ts b/src/lib/store/index.ts index fd86cc3..9fd113e 100644 --- a/src/lib/store/index.ts +++ b/src/lib/store/index.ts @@ -2,7 +2,7 @@ import { writable } from 'svelte/store' import type { ImageType } from '$lib/utils/types' const galleryInterface = { - images: [] as any[], + images: [] as ImageType[], selectedFilteredImages: [] as any[], tags: [] as string[], selectedTag: '' as string, diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte index aa1fcf2..c1c650e 100644 --- a/src/routes/+page.svelte +++ b/src/routes/+page.svelte @@ -1,57 +1,134 @@