linux appimage build with docker, egl fallback, and webkitgtk fixes
This commit is contained in:
+63
-1
@@ -1,3 +1,5 @@
|
||||
import { invoke } from '@tauri-apps/api/core'
|
||||
|
||||
export type SoundEvent =
|
||||
| 'timer_start'
|
||||
| 'timer_stop'
|
||||
@@ -41,9 +43,59 @@ const DEFAULT_SETTINGS: AudioSettings = {
|
||||
events: { ...DEFAULT_EVENTS },
|
||||
}
|
||||
|
||||
// Tone description for the Rust backend
|
||||
interface SoundTone {
|
||||
freq: number
|
||||
duration_ms: number
|
||||
delay_ms: number
|
||||
freq_end?: number
|
||||
detune?: number
|
||||
}
|
||||
|
||||
// Map each sound event to its tone sequence (mirrors the Web Audio synthesis)
|
||||
const TONE_MAP: Record<SoundEvent, SoundTone[]> = {
|
||||
timer_start: [
|
||||
{ freq: 523, duration_ms: 100, delay_ms: 0, detune: 3 },
|
||||
{ freq: 659, duration_ms: 150, delay_ms: 10, detune: 3 },
|
||||
],
|
||||
timer_stop: [
|
||||
{ freq: 784, duration_ms: 250, delay_ms: 0, freq_end: 523 },
|
||||
],
|
||||
timer_pause: [
|
||||
{ freq: 440, duration_ms: 120, delay_ms: 0 },
|
||||
],
|
||||
timer_resume: [
|
||||
{ freq: 523, duration_ms: 120, delay_ms: 0 },
|
||||
],
|
||||
idle_alert: [
|
||||
{ freq: 880, duration_ms: 80, delay_ms: 0 },
|
||||
{ freq: 880, duration_ms: 80, delay_ms: 60 },
|
||||
],
|
||||
goal_reached: [
|
||||
{ freq: 523, duration_ms: 120, delay_ms: 0, detune: 3 },
|
||||
{ freq: 659, duration_ms: 120, delay_ms: 10, detune: 3 },
|
||||
{ freq: 784, duration_ms: 120, delay_ms: 10, detune: 3 },
|
||||
],
|
||||
break_reminder: [
|
||||
{ freq: 659, duration_ms: 200, delay_ms: 0 },
|
||||
],
|
||||
}
|
||||
|
||||
class AudioEngine {
|
||||
private ctx: AudioContext | null = null
|
||||
private settings: AudioSettings = { ...DEFAULT_SETTINGS, events: { ...DEFAULT_SETTINGS.events } }
|
||||
private _isLinux: boolean | null = null
|
||||
|
||||
private async isLinux(): Promise<boolean> {
|
||||
if (this._isLinux === null) {
|
||||
try {
|
||||
this._isLinux = (await invoke('get_platform')) === 'linux'
|
||||
} catch {
|
||||
this._isLinux = false
|
||||
}
|
||||
}
|
||||
return this._isLinux
|
||||
}
|
||||
|
||||
private ensureContext(): AudioContext {
|
||||
if (!this.ctx) {
|
||||
@@ -81,7 +133,17 @@ class AudioEngine {
|
||||
this.synthesize(event)
|
||||
}
|
||||
|
||||
private synthesize(event: SoundEvent) {
|
||||
private async synthesize(event: SoundEvent) {
|
||||
// On Linux, use the Rust backend which plays via paplay/pw-play/aplay
|
||||
if (await this.isLinux()) {
|
||||
const tones = TONE_MAP[event]
|
||||
if (tones) {
|
||||
invoke('play_sound', { tones, volume: this.gain }).catch(() => {})
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// On other platforms, use Web Audio API
|
||||
switch (event) {
|
||||
case 'timer_start':
|
||||
this.playTimerStart()
|
||||
|
||||
Reference in New Issue
Block a user