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
89 changes: 89 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -210,6 +298,7 @@ jobs:
- changes
- rust
- check-macos
- desktop-app
- dotnet-tool
- dart-package
- actionlint
Expand Down
21 changes: 15 additions & 6 deletions packaging/app/scripts/check-tauri-config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
Expand All @@ -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 ?? []) {
Expand All @@ -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.
Expand Down
70 changes: 70 additions & 0 deletions packaging/app/src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 10 additions & 1 deletion packaging/app/src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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"

Expand Down
Binary file added packaging/app/src-tauri/icons/icon.ico
Binary file not shown.
8 changes: 7 additions & 1 deletion packaging/app/src-tauri/src/desktop/bookmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u8> {
path.to_string_lossy().into_owned().into_bytes()
}

#[cfg(not(target_os = "macos"))]
pub fn resolve(data: &[u8]) -> Result<Resolved, BookmarkError> {
let path = String::from_utf8(data.to_vec()).map_err(|e| BookmarkError(e.to_string()))?;
Expand All @@ -154,7 +160,7 @@ mod tests {

#[cfg(not(target_os = "macos"))]
fn create(path: &Path) -> Result<Vec<u8>, 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.
Expand Down
64 changes: 60 additions & 4 deletions packaging/app/src-tauri/src/desktop/power.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
//! 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
//! assertion tells the system the work is user initiated and must not be
//! 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")]
Expand Down Expand Up @@ -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) };

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning — If SetThreadExecutionState fails (returns 0), only an error is printed; the guard is still created and will call SetThreadExecutionState(ES_CONTINUOUS) on drop, which may not be safe if the initial call failed. This could lead to unexpected state if the API is unavailable or fails.

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;

Expand Down Expand Up @@ -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"));
}
}
Loading
Loading