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
20 changes: 15 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ jobs:
python test/integration/release.py backend/target/debug/omarchy-audio-service
python test/integration/packaging.py backend/target/debug/omarchy-audio-service
python packaging/build-release.py --output "$RUNNER_TEMP/audio-upgrade-candidate" --binary backend/target/debug/omarchy-audio-service
python test/integration/native_startup.py "$RUNNER_TEMP/audio-upgrade-candidate"
python "$RUNNER_TEMP/audio-upgrade-candidate/test/integration/runtime.py" "$RUNNER_TEMP/audio-upgrade-candidate/bin/omarchy-audio-service"
python "$RUNNER_TEMP/audio-upgrade-candidate/test/integration/routed_audio.py" "$RUNNER_TEMP/audio-upgrade-candidate/bin/omarchy-audio-service"
python "$RUNNER_TEMP/audio-upgrade-candidate/test/integration/profiles.py" "$RUNNER_TEMP/audio-upgrade-candidate/bin/omarchy-audio-service"
Expand All @@ -113,9 +114,16 @@ jobs:
python test/integration/upgrade.py "$RUNNER_TEMP/audio-upgrade-candidate" legacy-plugin

release-candidate:
name: Build self-contained plugin candidate
name: Build self-contained plugin candidate (${{ matrix.arch }})
needs: [test, qml-runtime]
runs-on: ubuntu-24.04
runs-on: ${{ matrix.runner }}
strategy:
matrix:
include:
- runner: ubuntu-24.04
arch: x86_64
- runner: ubuntu-24.04-arm
arch: aarch64
timeout-minutes: 15
steps:
- name: Check out plugin
Expand All @@ -131,12 +139,14 @@ jobs:
python3 packaging/build-release.py --output "$RUNNER_TEMP/audio-plugin"
python3 packaging/build-release.py --check "$RUNNER_TEMP/audio-plugin"
python3 test/integration/lifecycle.py "$RUNNER_TEMP/audio-plugin/bin/omarchy-audio-service"
tar -C "$RUNNER_TEMP/audio-plugin" -czf "$RUNNER_TEMP/omarchy-audio-control-linux-x86_64.tar.gz" .
python3 test/integration/release.py "$RUNNER_TEMP/audio-plugin/bin/omarchy-audio-service"
python3 test/integration/native_backend.py
tar -C "$RUNNER_TEMP/audio-plugin" -czf "$RUNNER_TEMP/omarchy-audio-control-linux-${{ matrix.arch }}.tar.gz" .
- name: Upload candidate for review
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
with:
name: omarchy-audio-control-linux-x86_64
path: ${{ runner.temp }}/omarchy-audio-control-linux-x86_64.tar.gz
name: omarchy-audio-control-linux-${{ matrix.arch }}
path: ${{ runner.temp }}/omarchy-audio-control-linux-${{ matrix.arch }}.tar.gz
if-no-files-found: error
retention-days: 14

Expand Down
22 changes: 20 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,26 @@ until discarded or until the advanced window closes.

## Install

Requires **Omarchy Quattro on x86_64 Linux**, PipeWire and WirePlumber, with
Omarchy's usual audio and desktop tools. Installation needs no Rust toolchain.
Requires **Omarchy Quattro on x86_64 or aarch64 Linux**, PipeWire and WirePlumber,
with Omarchy's usual audio and desktop tools. The Git checkout includes an
x86_64 backend, so x86_64 installation needs no Rust toolchain.

On **aarch64** (including Asahi Linux), install Rust/Cargo **1.85+**, libclang,
pkg-config, and the PipeWire and libpulse development headers before enabling
the plugin. For Arch-based systems:

```bash
sudo pacman -S --needed rust clang pkgconf pipewire libpulse
```

The plugin builds a native backend on first startup and after updates that
change runtime sources. The panel shows **Preparing audio service…** until the
build finishes. Builds stay under
`${XDG_CACHE_HOME:-~/.cache}/omarchy-audio-control/`; dependencies are reused
across updates, and the plugin checkout remains unchanged. Later starts use
the cached executable. If preparation fails, install the requirements above
and reload the plugin. Manual binary replacement after each update is no
longer needed.

```bash
omarchy plugin add https://github.com/ssupt/omarchy-audio-control.git --enable
Expand Down
4 changes: 2 additions & 2 deletions backend-release.json

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

1 change: 1 addition & 0 deletions backend/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ fn main() {
"backend/build.rs".into(),
"packaging/manifest.template.json".into(),
"packaging/build-release.py".into(),
"packaging/launch-backend.py".into(),
];
collect_sources(root, &root.join("backend/src"), &mut files);
println!(
Expand Down
Binary file modified bin/omarchy-audio-service
Binary file not shown.
6 changes: 3 additions & 3 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
"service"
],
"entryPoints": {
"barWidget": "runtime/3b9a83e019dc97d72fc5811b677ffca8800577e0aad56b3ed924b393c0871d84/qml/panels/Panel.qml",
"panel": "runtime/3b9a83e019dc97d72fc5811b677ffca8800577e0aad56b3ed924b393c0871d84/qml/panels/AdvancedAudio.qml",
"service": "runtime/3b9a83e019dc97d72fc5811b677ffca8800577e0aad56b3ed924b393c0871d84/qml/core/Service.qml"
"barWidget": "runtime/3b427ced50a7f5b6ee554fb64f8f92e682b8f09aa8777112d27a84eec53d787d/qml/panels/Panel.qml",
"panel": "runtime/3b427ced50a7f5b6ee554fb64f8f92e682b8f09aa8777112d27a84eec53d787d/qml/panels/AdvancedAudio.qml",
"service": "runtime/3b427ced50a7f5b6ee554fb64f8f92e682b8f09aa8777112d27a84eec53d787d/qml/core/Service.qml"
},
"barWidget": {
"displayName": "Advanced Audio Control",
Expand Down
7 changes: 4 additions & 3 deletions packaging/build-release.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@

def source_id(root):
names = ['backend/Cargo.toml', 'backend/Cargo.lock', 'backend/build.rs',
'packaging/manifest.template.json', 'packaging/build-release.py']
'packaging/manifest.template.json', 'packaging/build-release.py',
'packaging/launch-backend.py']
for directory in ('qml', 'backend/src', 'scripts'):
paths = ((root / directory).rglob('*') if directory != 'scripts'
else (root / directory).iterdir())
Expand Down Expand Up @@ -76,8 +77,8 @@ def verify(root):
info = inspect(binary)
if info['buildId'] != source_id(root) or metadata['buildId'] != info['buildId']:
raise ValueError('Backend does not match the plugin sources; rebuild the release')
if info['target'] != 'x86_64-unknown-linux-gnu' or metadata['target'] != info['target']:
raise ValueError('This release targets Omarchy on x86_64 Linux')
if info['target'] not in ('x86_64-unknown-linux-gnu', 'aarch64-unknown-linux-gnu') or metadata['target'] != info['target']:
raise ValueError('This release requires a native x86_64 or aarch64 Linux backend')
if any(metadata.get(key) != info.get(key) for key in ('version', 'protocolVersion')):
raise ValueError('Backend version metadata does not match the executable')
if not os.access(binary, os.X_OK):
Expand Down
139 changes: 139 additions & 0 deletions packaging/launch-backend.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
#!/usr/bin/env python3
"""Prepare a backend for this CPU without changing the installed plugin."""
import fcntl
import importlib.util
import json
import os
from pathlib import Path
import platform
import shutil
import stat
import struct
import subprocess
import sys
import tempfile

TARGETS = {
'x86_64': ('x86_64-unknown-linux-gnu', 62),
'aarch64': ('aarch64-unknown-linux-gnu', 183),
}


def release_tools(root):
spec = importlib.util.spec_from_file_location('audio_release', root/'packaging/build-release.py')
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
return module


def matches(binary, target, machine, build_id, tools, cached=False):
try:
descriptor = os.open(binary, os.O_RDONLY | os.O_NOFOLLOW | os.O_NONBLOCK)
with os.fdopen(descriptor, 'rb') as stream:
metadata = os.fstat(stream.fileno())
if not stat.S_ISREG(metadata.st_mode):
return False
if cached and (metadata.st_uid != os.getuid() or metadata.st_nlink != 1
or metadata.st_mode & 0o022):
return False
header = stream.read(20)
# Never execute a foreign ELF (including via binfmt/QEMU).
if (len(header) != 20 or header[:6] != b'\x7fELF\x02\x01'
or struct.unpack_from('<H', header, 18)[0] != machine
or not os.access(binary, os.X_OK)):
return False
info = tools.inspect(binary)
return (isinstance(info, dict) and info.get('buildId') == build_id and info.get('target') == target
and info.get('protocolVersion') == 1)
except (OSError, ValueError, subprocess.SubprocessError):
return False


def cache_directory(path, parents=False):
path.mkdir(parents=parents, exist_ok=True, mode=0o700)
metadata = path.lstat()
if (not stat.S_ISDIR(metadata.st_mode) or metadata.st_uid != os.getuid()
or metadata.st_mode & 0o022):
raise ValueError('Native audio cache directory must be owned by this user '
'and not writable by other users')


def prepare(root, machine=None, cache_home=None):
machine = platform.machine() if machine is None else machine
if platform.system() != 'Linux' or machine not in TARGETS:
raise ValueError(f'Unsupported audio backend platform: {platform.system()} {machine}')
target, elf_machine = TARGETS[machine]
tools = release_tools(root)
build_id = tools.source_id(root)
bundled = root/'bin/omarchy-audio-service'
if matches(bundled, target, elf_machine, build_id, tools):
return bundled
base = Path(cache_home or os.environ.get('XDG_CACHE_HOME') or Path.home()/'.cache')
if not base.is_absolute():
raise ValueError('XDG_CACHE_HOME must be an absolute path')
# Resolve the configured cache home for dotfiles setups, then keep every
# plugin-owned directory on a trusted, non-redirected path before execution.
base = base.resolve()
cache_directory(base, parents=True)
plugin_cache = base/'omarchy-audio-control'
cache_directory(plugin_cache)
cache = plugin_cache/target
cache_directory(cache)
cached = cache/build_id/'omarchy-audio-service'
cache_directory(cached.parent)
if matches(cached, target, elf_machine, build_id, tools, cached=True):
return cached
# A shared Cargo target directory reuses dependencies across UI updates.
# Serialize preparations and recheck after locking for concurrent panels.
lock_fd = os.open(cache/'.build.lock', os.O_CREAT | os.O_RDWR | os.O_NOFOLLOW | os.O_NONBLOCK, 0o600)
with os.fdopen(lock_fd, 'w') as lock:
info = os.fstat(lock.fileno())
if (not stat.S_ISREG(info.st_mode) or info.st_uid != os.getuid()
or info.st_nlink != 1 or info.st_mode & 0o022):
raise ValueError('Native audio build lock is not a private regular file')
os.fchmod(lock.fileno(), 0o600)
fcntl.flock(lock, fcntl.LOCK_EX)
if matches(cached, target, elf_machine, build_id, tools, cached=True):
return cached
if not shutil.which('cargo'):
raise ValueError('This CPU needs a native audio backend. Install Rust/Cargo 1.85+, '
'libclang, pkg-config, and PipeWire/libpulse development headers, '
'then reload the plugin (see README).')
cache_directory(cache/'target')
print(f'Building native audio backend for {target}; later launches use the cached build', file=sys.stderr)
result = subprocess.run([
'cargo', 'build', '--locked', '--release', '--manifest-path', str(root/'backend/Cargo.toml'),
'--target', target, '--target-dir', str(cache/'target'),
'--message-format=json-render-diagnostics',
], check=True, stdin=subprocess.DEVNULL, stdout=subprocess.PIPE, text=True)
artifacts = [Path(item['executable']) for line in result.stdout.splitlines()
if (item := json.loads(line)).get('reason') == 'compiler-artifact'
and item.get('executable') and item.get('target', {}).get('name') == 'omarchy-audio-service']
if len(artifacts) != 1 or not matches(artifacts[0], target, elf_machine, build_id, tools):
raise ValueError('Native backend does not match this plugin release; reload and retry')
# Do not publish a build if the plugin changed while Cargo was running.
if tools.source_id(root) != build_id:
raise ValueError('Plugin updated while building the audio backend; reload and retry')
with tempfile.NamedTemporaryFile(dir=cached.parent, prefix='.backend-', delete=False) as stage:
temporary = Path(stage.name)
try:
shutil.copyfile(artifacts[0], temporary)
temporary.chmod(0o755)
temporary.replace(cached)
finally:
temporary.unlink(missing_ok=True)
return cached


if __name__ == '__main__':
try:
root = Path(sys.argv[1]).resolve()
arguments = sys.argv[2:]
binary = prepare(root)
if arguments == ['--prepare']:
print(binary)
else:
os.execv(binary, [str(binary), *arguments])
except (ValueError, OSError, subprocess.SubprocessError) as error:
print(f'Audio backend preparation failed: {error}', file=sys.stderr)
raise SystemExit(1)
40 changes: 35 additions & 5 deletions qml/core/Service.qml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ Item {
property var shell: null
property var manifest: null
property string omarchyPath: ""
// Release checkouts include this executable. Tests can inject an isolated
// binary; users never need a compiler or a separately installed user unit.
property var backendCommand: [decodeURIComponent(Qt.resolvedUrl(ReleasePaths.root + "bin/omarchy-audio-service").toString().replace(/^file:\/\//, "")), "--plugin"]
// Tests can inject a backend. Normal launches prepare a matching native
// executable before starting the protocol's five-second hello deadline.
property var backendCommand: []
property var backendPreparationCommand: [decodeURIComponent(Qt.resolvedUrl(ReleasePaths.root + "scripts/audio-service").toString().replace(/^file:\/\//, "")), "--prepare"]
readonly property bool connected: backend.running
property bool ready: false
property string backendVersion: ""
Expand Down Expand Up @@ -103,14 +104,43 @@ Item {
},
callbackError: function() { console.warn("Audio command callback failed") }
})
launchTimer.start()
if (backendCommand.length) launchTimer.start()
else {
root.error = "Preparing audio service…"
prepareBackend.running = true
}
}
Component.onDestruction: {
destroying = true
reconnectTimer.stop()
backend.running = false
prepareBackend.running = false
if (client) client.reset(Protocol.failure("disconnected", "Audio plugin closed", false))
}
Process {
id: prepareBackend
command: root.backendPreparationCommand
stdout: StdioCollector { id: preparedPath }
stderr: SplitParser {
splitMarker: "\n"
onRead: function(line) {
console.warn("Audio preparation:", String(line).slice(0, 1024))
if (String(line).indexOf("Audio backend preparation failed:") === 0)
root.error = String(line).slice(0, 1024)
}
}
onExited: function(code, _status) {
if (root.destroying) return
var path = preparedPath.text.trim()
if (code === 0 && path.charAt(0) === "/" && path.indexOf("\n") === -1) {
root.backendCommand = [path, "--plugin"]
root.error = ""
launchTimer.start()
} else if (root.error === "Preparing audio service…") {
root.error = "Audio service preparation failed; see the plugin README for native build requirements"
}
}
}
Process {
id: backend
command: root.backendCommand
Expand Down Expand Up @@ -159,6 +189,6 @@ Item {
Timer {
id: reconnectTimer
interval: 5000
onTriggered: if (!root.destroying && !backend.running) backend.running = true
onTriggered: if (!root.destroying && !backend.running && root.backendCommand.length) backend.running = true
}
}

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

Loading
Loading