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
82 changes: 82 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
name: CI

on:
push:
branches: [main]
pull_request:

# Read the code, nothing else. No step needs a secret, a token or network
# access beyond the package registries.
permissions:
contents: read

concurrency:
group: ci-${{ github.ref }}
cancel-in-progress: true

env:
CARGO_TERM_COLOR: always
# Smaller builds and cache; backtraces keep their file and line.
CARGO_PROFILE_DEV_DEBUG: line-tables-only

jobs:
test:
name: test (${{ matrix.os }})
strategy:
fail-fast: false
matrix:
# ubuntu-24.04 is pinned: ubuntu-latest moves to 26.04 in November 2026
# (actions/runner-images#14748), and nothing has been built against its
# WebKitGTK yet. macos-latest is macOS 26 on Apple silicon.
os: [ubuntu-24.04, macos-latest, windows-latest]
runs-on: ${{ matrix.os }}
# Windows has never been run: its failures are listed, not hidden. Remove once green.
continue-on-error: ${{ matrix.os == 'windows-latest' }}
timeout-minutes: 60
steps:
- name: Keep line endings as committed
if: runner.os == 'Windows'
run: git config --global core.autocrlf false

- uses: actions/checkout@v7

- uses: actions/setup-node@v7
with:
node-version: 22
cache: npm

# The toolchain this was verified with on Linux and macOS. Moving to a
# newer one (new clippy lints included) is a change of its own.
- uses: dtolnay/rust-toolchain@1.97.0
with:
components: rustfmt, clippy

- uses: Swatinem/rust-cache@v2
with:
workspaces: src-tauri

- name: Linux packages
if: runner.os == 'Linux'
run: |
sudo apt-get update
sudo apt-get install -y pkg-config libwebkit2gtk-4.1-dev libgtk-3-dev \
libayatana-appindicator3-dev librsvg2-dev libdbus-1-dev libasound2-dev \
libxkbcommon-dev libxdo-dev libssl-dev

# Fast checks first (formatting, types, lint), then tests and builds.
- run: npm ci
- name: Type check
run: npm run typecheck
- name: Lint
run: npm run lint
- name: Rust format
run: cargo fmt --manifest-path src-tauri/Cargo.toml --check
- name: Clippy
run: cargo clippy --manifest-path src-tauri/Cargo.toml --all-targets -- -D warnings

- name: Frontend tests
run: npm test
- name: Frontend build
run: npm run build
- name: Rust tests
run: cargo test --manifest-path src-tauri/Cargo.toml --no-fail-fast
152 changes: 152 additions & 0 deletions VERIFICATION.md

Large diffs are not rendered by default.

7 changes: 6 additions & 1 deletion src-tauri/examples/dump_workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,14 @@
//! the contract fixture the TypeScript schemas are tested against.
//!
//! `cargo run --example dump_workspace > ../examples/default-workspace.json`
//!
//! The fixture is the Linux workspace on every system, so that refreshing it
//! on a Mac or on Windows writes the same file.

use launchdeck_lib::surfaces::{default_workspace_for, Platform};

fn main() {
let ws = launchdeck_lib::surfaces::default_workspace();
let ws = default_workspace_for(Platform::Linux);
println!(
"{}",
serde_json::to_string_pretty(&ws).expect("serialise workspace")
Expand Down
13 changes: 11 additions & 2 deletions src-tauri/src/context/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ pub struct Decision {
#[derive(Debug)]
pub struct Engine {
observer: ObserverStatus,
/// The kind of identity the observer reports, so that a rule of another
/// kind, which can never match, is pointed out.
namespace: Option<&'static str>,
/// The last thing the observer reported, whatever it was.
observed: Option<Seen>,
/// An application that came to the front and has not stayed there long enough yet.
Expand All @@ -126,9 +129,10 @@ pub struct Engine {
}

impl Engine {
pub fn new(observer: ObserverStatus, editing: bool) -> Engine {
pub fn new(observer: ObserverStatus, namespace: Option<&'static str>, editing: bool) -> Engine {
Engine {
observer,
namespace,
observed: None,
pending: None,
accepted: None,
Expand All @@ -147,6 +151,10 @@ impl Engine {
self.observer = status;
}

pub fn namespace(&self) -> Option<&'static str> {
self.namespace
}

/// What is in front now, as last reported. Not what rules are asked about.
pub fn observed(&self) -> Option<&Seen> {
self.observed.as_ref()
Expand Down Expand Up @@ -371,7 +379,7 @@ mod tests {
impl Deck {
fn new(rules: Vec<crate::context::rules::ContextRule>, fallback: Fallback) -> Deck {
Deck {
engine: Engine::new(ObserverStatus::available("test"), false),
engine: Engine::new(ObserverStatus::available("test"), Some(X11), false),
settings: ContextSettings {
auto: true,
rules,
Expand Down Expand Up @@ -921,6 +929,7 @@ mod tests {
let mut d = Deck::usual();
d.engine = Engine::new(
ObserverStatus::unavailable("Wayland does not say which application is in front."),
None,
false,
);
assert_eq!(d.mode(), Mode::Unavailable);
Expand Down
9 changes: 8 additions & 1 deletion src-tauri/src/context/observer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use std::sync::Arc;

use serde::Serialize;

use super::identity::ApplicationIdentity;
use super::identity::{native_namespace, ApplicationIdentity};

#[cfg(target_os = "macos")]
mod macos;
Expand Down Expand Up @@ -117,6 +117,13 @@ pub trait ForegroundObserver: Send {
/// What it can do on this system, known before it runs.
fn status(&self) -> ObserverStatus;

/// The kind of identity it reports (`macos`, `windows`, `x11`), so that a
/// rule written for another kind can be pointed out. An observer of the
/// system LaunchDeck was built for reports that system's kind.
fn namespace(&self) -> Option<&'static str> {
native_namespace()
}

/// Report the application in front now and every change after it, until
/// `sink.stopped()`. Blocks: the runtime gives it a thread of its own.
/// Never called when `status()` is unavailable.
Expand Down
6 changes: 6 additions & 0 deletions src-tauri/src/context/observer/scripted.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use std::sync::mpsc::{channel, Receiver, Sender};
use std::time::Duration;

use super::{ForegroundObserver, ObserverStatus, Report, Sink};
use crate::context::identity::X11;

pub struct ScriptedObserver {
status: ObserverStatus,
Expand Down Expand Up @@ -40,6 +41,11 @@ impl ForegroundObserver for ScriptedObserver {
self.status.clone()
}

/// X11 identities, whatever system the tests run on.
fn namespace(&self) -> Option<&'static str> {
Some(X11)
}

fn run(self: Box<Self>, sink: Sink) {
while !sink.stopped() {
match self.reports.recv_timeout(Duration::from_millis(50)) {
Expand Down
6 changes: 3 additions & 3 deletions src-tauri/src/context/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use serde::Serialize;

use super::engine::{Decision, Engine, Mode};
use super::identity::{native_namespace, ApplicationIdentity};
use super::identity::ApplicationIdentity;
use super::observer::{ObserverStatus, Seen};
use super::rules::ContextSettings;
use crate::core::model::Workspace;
Expand Down Expand Up @@ -100,7 +100,7 @@ pub fn rule_problems(
}

pub fn status(engine: &Engine, settings: &ContextSettings, workspace: &Workspace) -> ContextStatus {
let namespace = native_namespace();
let namespace = engine.namespace();
ContextStatus {
settings: settings.clone(),
observer: engine.observer().clone(),
Expand Down Expand Up @@ -167,7 +167,7 @@ mod tests {
fn the_status_says_what_is_in_front_without_keeping_any_of_it() {
let ws = default_workspace();
let settings = ContextSettings::default();
let mut engine = Engine::new(ObserverStatus::available("test"), false);
let mut engine = Engine::new(ObserverStatus::available("test"), Some(X11), false);
assert_eq!(
status(&engine, &settings, &ws).foreground,
Foreground::Unknown
Expand Down
2 changes: 1 addition & 1 deletion src-tauri/src/core/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ impl Runtime {
recent: VecDeque::new(),
external,
pending: BTreeMap::new(),
context: Engine::new(observing.clone(), false),
context: Engine::new(observing.clone(), observer.namespace(), false),
}),
bus: bus.clone(),
engine,
Expand Down
7 changes: 4 additions & 3 deletions src-tauri/src/persistence/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ fn write_file(path: &Path, bytes: &[u8], private: bool) -> std::io::Result<()> {
#[cfg(test)]
mod tests {
use super::*;
use crate::surfaces::default_workspace;
use crate::surfaces::{default_workspace, default_workspace_for, Platform};

#[test]
fn workspace_roundtrips_through_disk() {
Expand Down Expand Up @@ -361,14 +361,15 @@ mod tests {

/// The strongest check of the conversion: the schema 3 workspace the last
/// release shipped, migrated by the rules in [`bindings`], is the same
/// workspace the code builds by hand today, control by control.
/// workspace the code builds by hand today, control by control. The file
/// was saved on Linux, so it is compared with the Linux starter pads.
#[test]
fn a_real_v3_workspace_migrates_to_exactly_what_ships_now() {
let old: Value = serde_json::from_str(V3_FIXTURE).unwrap();
assert_eq!(old["schemaVersion"], 3);
let ws = migrate(old).unwrap();
assert_eq!(ws.schema_version, SCHEMA_VERSION);
let shipped = default_workspace();
let shipped = default_workspace_for(Platform::Linux);
assert_eq!(ws.surfaces.len(), shipped.surfaces.len());
for (a, b) in ws.surfaces.iter().zip(&shipped.surfaces) {
assert_eq!(a, b, "surface `{}` differs after migration", b.id);
Expand Down
Loading
Loading