diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2e9ac89..cc204e8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -43,6 +43,7 @@ jobs: dotnet: ${{ github.event_name == 'workflow_dispatch' || steps.filter.outputs.dotnet }} dart: ${{ github.event_name == 'workflow_dispatch' || steps.filter.outputs.dart }} workflows: ${{ github.event_name == 'workflow_dispatch' || steps.filter.outputs.workflows }} + desktop: ${{ github.event_name == 'workflow_dispatch' || steps.filter.outputs.desktop }} steps: - name: Checkout uses: actions/checkout@v6 @@ -75,6 +76,13 @@ jobs: - ".github/workflows/ci.yml" workflows: - ".github/workflows/**" + desktop: + - "packaging/app/**" + - "src/**" + - "build.rs" + - "Cargo.*" + - ".cargo/**" + - ".github/workflows/ci.yml" rust: name: Rust (fmt, clippy, test) @@ -150,6 +158,86 @@ jobs: - name: Cargo check run: cargo check --locked --target aarch64-apple-darwin + # Onde Desktop: the config checks and a lint of the Tauri crate on the two + # desktop platforms it ships on. `tauri::generate_context!` needs a frontend + # build, so the web build runs first. + desktop-app: + name: Desktop app (${{ matrix.name }}) + needs: changes + if: needs.changes.outputs.desktop == 'true' + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + include: + - name: macOS + os: macos-26 + - name: Windows + os: windows-latest + defaults: + run: + shell: bash + env: + ONDE_APP_ID: ${{ secrets.ONDE_APP_ID || 'ci-placeholder' }} + ONDE_APP_SECRET: ${{ secrets.ONDE_APP_SECRET || 'ci-placeholder' }} + GRESIQ_API_KEY: ${{ secrets.GRESIQ_API_KEY || 'ci-placeholder' }} + GRESIQ_API_SECRET: ${{ secrets.GRESIQ_API_SECRET || 'ci-placeholder' }} + HF_TOKEN: ${{ secrets.HF_TOKEN || 'ci-placeholder' }} + steps: + - name: Checkout + uses: actions/checkout@v6 + + - name: Install pnpm + uses: pnpm/action-setup@v4 + with: + version: 10 + + - name: Setup Node + uses: actions/setup-node@v5 + with: + node-version: 22 + cache: pnpm + cache-dependency-path: packaging/app/pnpm-lock.yaml + + - name: Install Rust toolchain + uses: dtolnay/rust-toolchain@stable + with: + components: clippy + + - name: Cache cargo registry and build artifacts + uses: Swatinem/rust-cache@v2 + with: + workspaces: packaging/app/src-tauri + + - name: Install frontend dependencies + working-directory: packaging/app + run: pnpm install --frozen-lockfile + + - name: Check the Tauri configs + working-directory: packaging/app + run: pnpm check:config + + - name: Build the frontend + working-directory: packaging/app + run: pnpm build + + # The app optimizes every dependency in dev builds so `tauri dev` can + # train at a usable speed. CI only lints and tests, so these two steps + # skip that and the debug info; with it the jobs took an hour or more. + - name: Lint + working-directory: packaging/app/src-tauri + run: >- + cargo clippy + --config 'profile.dev.package."*".opt-level=0' --config profile.dev.debug=0 + --locked --all-targets -- -D warnings + + - name: Test + working-directory: packaging/app/src-tauri + run: >- + cargo test + --config 'profile.dev.package."*".opt-level=0' --config profile.dev.debug=0 + --locked + dotnet-tool: name: .NET tool launcher build needs: changes @@ -210,6 +298,7 @@ jobs: - changes - rust - check-macos + - desktop-app - dotnet-tool - dart-package - actionlint diff --git a/packaging/app/scripts/check-tauri-config.mjs b/packaging/app/scripts/check-tauri-config.mjs index 0bf41c1..860db44 100644 --- a/packaging/app/scripts/check-tauri-config.mjs +++ b/packaging/app/scripts/check-tauri-config.mjs @@ -30,9 +30,10 @@ const pkgVersion = read(join(root, "package.json")).version; const appCargo = readFileSync(join(tauri, "Cargo.toml"), "utf8").match(/^version\s*=\s*"([^"]+)"/m)?.[1]; const base = read(join(tauri, "tauri.conf.json")); +// Each overlay names its platform; the checks below differ between them. const overlays = { - "tauri.prod-macos.conf.json": "com.ondeinference.desktop", - "tauri.prod-macos-appstore.conf.json": "com.ondeinference.desktop", + "tauri.prod-macos.conf.json": { platform: "macos", id: "com.ondeinference.desktop" }, + "tauri.prod-macos-appstore.conf.json": { platform: "macos", id: "com.ondeinference.desktop" }, }; if (base.identifier !== "com.ondeinference.desktop-Debug") fail(`base identifier is ${base.identifier}`); @@ -41,11 +42,13 @@ for (const [what, v] of [["package.json", pkgVersion], ["src-tauri/Cargo.toml", } const chrome = ["titleBarStyle", "hiddenTitle", "trafficLightPosition"]; -const check = (name, cfg, id) => { +const check = (name, cfg, id, platform = "macos") => { if (id && cfg.identifier !== id) fail(`${name}: identifier ${cfg.identifier}, expected ${id}`); if (cfg.version !== cargoVersion) fail(`${name}: version ${cfg.version} != ${cargoVersion}`); const win = cfg.app?.windows?.[0] ?? {}; - for (const k of chrome) if (!(k in win)) fail(`${name}: window is missing ${k}`); + if (platform === "macos") { + for (const k of chrome) if (!(k in win)) fail(`${name}: window is missing ${k}`); + } const ent = cfg.bundle?.macOS?.entitlements; if (ent && !existsSync(join(tauri, ent))) fail(`${name}: entitlements ${ent} not found`); for (const icon of cfg.bundle?.icon ?? []) { @@ -59,9 +62,15 @@ const check = (name, cfg, id) => { }; check("tauri.conf.json", base, null); -for (const [file, id] of Object.entries(overlays)) { +// Windows builds, including `tauri dev`, fail without an .ico. +if (!base.bundle?.icon?.some((i) => i.endsWith(".ico"))) fail("tauri.conf.json: bundle.icon lists no .ico"); +for (const [file, { platform, id }] of Object.entries(overlays)) { const merged = mergePatch(base, read(join(tauri, file))); - check(file, merged, id); + check(file, merged, id, platform); + if (platform === "windows") { + if (!merged.bundle?.icon?.some((i) => i.endsWith(".ico"))) fail(`${file}: bundle.icon lists no .ico`); + continue; + } const mac = merged.bundle?.macOS ?? {}; // Tauri exports this as MACOSX_DEPLOYMENT_TARGET (default 10.13), and the // mlx-sys build refuses anything below 14. diff --git a/packaging/app/src-tauri/Cargo.lock b/packaging/app/src-tauri/Cargo.lock index 94d0957..39f99f6 100644 --- a/packaging/app/src-tauri/Cargo.lock +++ b/packaging/app/src-tauri/Cargo.lock @@ -5132,12 +5132,14 @@ dependencies = [ "smbcloud-network 0.3.41", "tauri", "tauri-build", + "tauri-plugin-dialog", "tauri-plugin-oauth", "tauri-plugin-opener", "tauri-plugin-os", "tempfile", "tokio", "url", + "windows-sys 0.61.2", ] [[package]] @@ -6527,6 +6529,32 @@ dependencies = [ "web-sys", ] +[[package]] +name = "rfd" +version = "0.17.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "20dafead71c16a34e1ff357ddefc8afc11e7d51d6d2b9fbd07eaa48e3e540220" +dependencies = [ + "block2", + "dispatch2", + "glib-sys", + "gobject-sys", + "gtk-sys", + "js-sys", + "libc", + "log", + "objc2", + "objc2-app-kit", + "objc2-core-foundation", + "objc2-foundation", + "percent-encoding", + "raw-window-handle", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "windows-sys 0.61.2", +] + [[package]] name = "rgb" version = "0.8.53" @@ -8272,6 +8300,48 @@ dependencies = [ "walkdir", ] +[[package]] +name = "tauri-plugin-dialog" +version = "2.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce0fb9c2b6d34a9720627ed930ebc8af26f61e648695aecaeb03d5c33c5896f5" +dependencies = [ + "log", + "raw-window-handle", + "rfd", + "serde", + "serde_json", + "tauri", + "tauri-plugin", + "tauri-plugin-fs", + "thiserror 2.0.21", + "url", +] + +[[package]] +name = "tauri-plugin-fs" +version = "2.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d58eb1d4984e535f47a642ffec09a2da6f5c18a12b5902d12126cb7626d628b" +dependencies = [ + "anyhow", + "dunce", + "glob", + "log", + "objc2-foundation", + "percent-encoding", + "schemars 0.8.22", + "serde", + "serde_json", + "serde_repr", + "tauri", + "tauri-plugin", + "tauri-utils", + "thiserror 2.0.21", + "toml 1.2.1+spec-1.1.0", + "url", +] + [[package]] name = "tauri-plugin-oauth" version = "2.1.0" diff --git a/packaging/app/src-tauri/Cargo.toml b/packaging/app/src-tauri/Cargo.toml index 0abb5b8..ac5708d 100644 --- a/packaging/app/src-tauri/Cargo.toml +++ b/packaging/app/src-tauri/Cargo.toml @@ -2,7 +2,7 @@ name = "onde-desktop" version = "0.6.1" edition = "2024" -description = "Onde Desktop: fine-tune, chat with and publish models on your Mac." +description = "Onde Desktop: fine-tune, chat with and publish models on your computer." license = "MIT OR Apache-2.0" publish = false @@ -40,6 +40,15 @@ objc2 = "0.6" objc2-foundation = { version = "0.3", default-features = false, features = ["std", "NSArray", "NSData", "NSError", "NSObject", "NSProcessInfo", "NSString", "NSURL"] } objc2-app-kit = { version = "0.3", default-features = false, features = ["std", "NSOpenPanel", "NSSavePanel", "NSPanel", "NSWindow", "NSResponder", "NSApplication"] } +# Windows and Linux get their chooser from the dialog plugin, called from Rust +# only. The webview is still granted no dialog permission. +[target.'cfg(not(target_os = "macos"))'.dependencies] +tauri-plugin-dialog = "2" + +# Keeps the PC from sleeping while a training job runs. +[target.'cfg(windows)'.dependencies] +windows-sys = { version = "0.61", features = ["Win32_System_Power"] } + [dev-dependencies] tempfile = "3" diff --git a/packaging/app/src-tauri/icons/icon.ico b/packaging/app/src-tauri/icons/icon.ico new file mode 100644 index 0000000..6469873 Binary files /dev/null and b/packaging/app/src-tauri/icons/icon.ico differ diff --git a/packaging/app/src-tauri/src/desktop/bookmark.rs b/packaging/app/src-tauri/src/desktop/bookmark.rs index f0e3693..b356658 100644 --- a/packaging/app/src-tauri/src/desktop/bookmark.rs +++ b/packaging/app/src-tauri/src/desktop/bookmark.rs @@ -130,6 +130,12 @@ impl AccessGuard { } } +/// Without a sandbox the "bookmark" is the path itself. +#[cfg(not(target_os = "macos"))] +pub fn create(path: &std::path::Path) -> Vec { + path.to_string_lossy().into_owned().into_bytes() +} + #[cfg(not(target_os = "macos"))] pub fn resolve(data: &[u8]) -> Result { let path = String::from_utf8(data.to_vec()).map_err(|e| BookmarkError(e.to_string()))?; @@ -154,7 +160,7 @@ mod tests { #[cfg(not(target_os = "macos"))] fn create(path: &Path) -> Result, BookmarkError> { - Ok(path.to_string_lossy().into_owned().into_bytes()) + Ok(super::create(path)) } /// The refresh comes from the open guard, and it opens to the same folder. diff --git a/packaging/app/src-tauri/src/desktop/power.rs b/packaging/app/src-tauri/src/desktop/power.rs index a9d5c5f..9e8bf74 100644 --- a/packaging/app/src-tauri/src/desktop/power.rs +++ b/packaging/app/src-tauri/src/desktop/power.rs @@ -1,4 +1,4 @@ -//! Keep the Mac awake while a training job runs. +//! Keep the computer awake while a training job runs. //! //! A run takes minutes to hours. Left alone, macOS can put an idle Mac to sleep //! partway through, or slow a background app down (App Nap). An activity @@ -6,6 +6,9 @@ //! interrupted by idle sleep. It does not stop the display from sleeping and it //! does not stop the user closing the lid. //! +//! On Windows the guard asks the system to stay up the same way, with +//! `SetThreadExecutionState`. The display may still turn off. +//! //! Elsewhere there is nothing to hold, and the guard does nothing. #[cfg(target_os = "macos")] @@ -39,7 +42,43 @@ mod imp { } } -#[cfg(not(target_os = "macos"))] +#[cfg(windows)] +mod imp { + use std::marker::PhantomData; + + use windows_sys::Win32::System::Power::{ + ES_CONTINUOUS, ES_SYSTEM_REQUIRED, SetThreadExecutionState, + }; + + /// Ends the request when dropped. The state belongs to the calling thread, + /// so the guard is not `Send`. + pub struct KeepAwake { + _thread_bound: PhantomData<*const ()>, + } + + impl KeepAwake { + pub fn begin(_reason: &str) -> Self { + // SAFETY: the call takes flags only and changes nothing but this + // thread's execution state. + let previous = unsafe { SetThreadExecutionState(ES_CONTINUOUS | ES_SYSTEM_REQUIRED) }; + if previous == 0 { + eprintln!("could not ask Windows to stay awake"); + } + Self { + _thread_bound: PhantomData, + } + } + } + + impl Drop for KeepAwake { + fn drop(&mut self) { + // SAFETY: as above. `ES_CONTINUOUS` alone clears the request. + unsafe { SetThreadExecutionState(ES_CONTINUOUS) }; + } + } +} + +#[cfg(not(any(target_os = "macos", windows)))] mod imp { pub struct KeepAwake; @@ -78,9 +117,26 @@ mod tests { assert!(!listed(&reason), "the assertion should end on drop"); } - #[cfg(not(target_os = "macos"))] + /// The call returns the thread's previous state, so a second guard-free + /// call shows what the first one left behind. + #[cfg(windows)] + #[test] + fn the_request_is_set_while_held_and_cleared_after() { + use windows_sys::Win32::System::Power::{ + ES_CONTINUOUS, ES_SYSTEM_REQUIRED, SetThreadExecutionState, + }; + // SAFETY: flags only; the state is restored before returning. + let current = || unsafe { SetThreadExecutionState(ES_CONTINUOUS) }; + let guard = KeepAwake::begin("test"); + let held = current(); + assert_ne!(held & ES_SYSTEM_REQUIRED, 0, "set while held"); + drop(guard); + assert_eq!(current() & ES_SYSTEM_REQUIRED, 0, "cleared on drop"); + } + + #[cfg(not(any(target_os = "macos", windows)))] #[test] - fn it_does_nothing_off_macos() { + fn it_does_nothing_elsewhere() { drop(KeepAwake::begin("x")); } } diff --git a/packaging/app/src-tauri/src/lib.rs b/packaging/app/src-tauri/src/lib.rs index 365972d..64cbe45 100644 --- a/packaging/app/src-tauri/src/lib.rs +++ b/packaging/app/src-tauri/src/lib.rs @@ -24,7 +24,12 @@ pub fn run() { onde_cli::paths::set_projects_dir(Some(dir)); } - tauri::Builder::default() + let builder = tauri::Builder::default(); + // macOS drives NSOpenPanel itself (see `picker.rs`). + #[cfg(not(target_os = "macos"))] + let builder = builder.plugin(tauri_plugin_dialog::init()); + + builder .plugin(tauri_plugin_opener::init()) .plugin(tauri_plugin_os::init()) .manage(state::PendingSignIn::default()) diff --git a/packaging/app/src-tauri/src/picker.rs b/packaging/app/src-tauri/src/picker.rs index d8c0800..3f90ee2 100644 --- a/packaging/app/src-tauri/src/picker.rs +++ b/packaging/app/src-tauri/src/picker.rs @@ -27,6 +27,7 @@ pub struct Request { } /// Show the panel and wait for the answer. `Ok(None)` means the user cancelled. +#[cfg(target_os = "macos")] pub async fn pick(app: &AppHandle, request: Request) -> Result, String> { let (tx, rx) = tokio::sync::oneshot::channel(); app.run_on_main_thread(move || { @@ -78,7 +79,43 @@ fn run(request: Request) -> Result, String> { Ok(Some(Picked { path, bookmark })) } +/// Show the system dialog and wait for the answer. `Ok(None)` means the user +/// cancelled. The blocking calls must stay off the main thread. #[cfg(not(target_os = "macos"))] -fn run(_request: Request) -> Result, String> { - Err("choosing a file or folder is only available on macOS in this build".into()) +pub async fn pick(app: &AppHandle, request: Request) -> Result, String> { + let app = app.clone(); + tauri::async_runtime::spawn_blocking(move || run(&app, request)) + .await + .map_err(|e| format!("opening the chooser: {e}"))? +} + +#[cfg(not(target_os = "macos"))] +fn run(app: &AppHandle, request: Request) -> Result, String> { + use tauri::Manager; + use tauri_plugin_dialog::DialogExt; + + let mut dialog = app.dialog().file().set_title(request.title); + if let Some(window) = app.get_webview_window("main") { + dialog = dialog.set_parent(&window); + } + if let Some(start) = &request.start { + dialog = dialog.set_directory(start); + } + let chosen = match request.mode { + Mode::Folder => dialog.blocking_pick_folder(), + Mode::File { extensions } => dialog + .add_filter("Supported files", extensions) + .blocking_pick_file(), + }; + let Some(chosen) = chosen else { + return Ok(None); + }; + let path = chosen + .into_path() + .map_err(|e| format!("the chosen item has no path ({e})"))?; + // There is no sandbox here, so the "bookmark" is the path itself. + let bookmark = request + .want_bookmark + .then(|| crate::desktop::bookmark::create(&path)); + Ok(Some(Picked { path, bookmark })) } diff --git a/packaging/app/src-tauri/tauri.conf.json b/packaging/app/src-tauri/tauri.conf.json index fe98fa8..b6e7f49 100644 --- a/packaging/app/src-tauri/tauri.conf.json +++ b/packaging/app/src-tauri/tauri.conf.json @@ -31,7 +31,7 @@ "active": true, "targets": "all", "category": "DeveloperTool", - "icon": ["icons/32x32.png", "icons/128x128.png", "icons/128x128@2x.png", "icons/icon.icns"], + "icon": ["icons/32x32.png", "icons/128x128.png", "icons/128x128@2x.png", "icons/icon.icns", "icons/icon.ico"], "macOS": { "infoPlist": "./Info.plist" } } } diff --git a/packaging/app/src/features/projects/BaseModelCard.tsx b/packaging/app/src/features/projects/BaseModelCard.tsx index 511eb8e..1604ca7 100644 --- a/packaging/app/src/features/projects/BaseModelCard.tsx +++ b/packaging/app/src/features/projects/BaseModelCard.tsx @@ -120,7 +120,7 @@ export function BaseModelCard({ detail, onChanged }: { detail: ProjectDetail; on ) : (

{entry - ? "Not downloaded yet. Fine-tuning needs the weights on this Mac." + ? "Not downloaded yet. Fine-tuning needs the weights on this computer." : catalogError ? "The list of base models could not be loaded, so this one can't be downloaded from here." : catalog.length === 0