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
4 changes: 3 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ jobs:
files: |
artifacts/**/*.dmg
artifacts/**/*.zip
artifacts/**/*.exe
artifacts/**/*-setup.exe
artifacts/**/*.AppImage
artifacts/**/*.deb
artifacts/**/latest*.yml
artifacts/**/*.blockmap
generate_release_notes: true
4 changes: 4 additions & 0 deletions electron-builder.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,8 @@ linux:
synopsis: Local voice notebook
appImage:
artifactName: ${name}-${version}.${ext}
publish:
provider: github
owner: adavila0703
repo: Lyra
npmRebuild: true
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
},
"dependencies": {
"@electron-toolkit/utils": "^4.0.0",
"@kutalia/whisper-node-addon": "^1.1.0"
"@kutalia/whisper-node-addon": "^1.1.0",
"electron-updater": "^6.8.9"
},
"devDependencies": {
"@electron-toolkit/tsconfig": "^2.0.0",
Expand Down
35 changes: 35 additions & 0 deletions pnpm-lock.yaml

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

2 changes: 2 additions & 0 deletions src/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { join } from 'node:path'
import { tmpdir } from 'node:os'
import { electronApp, optimizer, is } from '@electron-toolkit/utils'
import { createPage, deletePage, getPage, listPages, savePage } from './pages'
import { registerUpdater } from './updater'
import { broadcastStatus, ensureModel, pcmFromIpc, transcribePcm } from './whisper'
import type { Page } from '../shared/types'

Expand Down Expand Up @@ -181,6 +182,7 @@ app.whenReady().then(() => {
})

registerIpc()
registerUpdater()
createWindow()
broadcastStatus({ state: 'idle' })

Expand Down
121 changes: 121 additions & 0 deletions src/main/updater.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
import { app, BrowserWindow, ipcMain, shell } from 'electron'
import { spawnSync } from 'node:child_process'
import { join } from 'node:path'
import { autoUpdater } from 'electron-updater'
import type { UpdateStatus } from '../shared/types'

const RELEASES_URL = 'https://github.com/adavila0703/Lyra/releases'
const CHECK_EVERY_MS = 4 * 60 * 60 * 1000

let current: UpdateStatus = { state: 'idle' }
let checkTimer: ReturnType<typeof setInterval> | null = null
let userInitiated = false

function updaterEnabled(): boolean {
if (!app.isPackaged) return false
if (process.env.VOICE_PAGES_SMOKE === '1' || process.env.VOICE_PAGES_SCREENSHOT === '1') {
return false
}
return true
}

function macAppBundle(): string {
return join(app.getPath('exe'), '../../..')
}

function canInstallInPlace(): boolean {
if (process.platform !== 'darwin') return true
const result = spawnSync('codesign', ['-dv', '--verbose=2', macAppBundle()], {
encoding: 'utf8'
})
const text = `${result.stdout ?? ''}${result.stderr ?? ''}`
return /Authority=Developer ID Application/.test(text)
}

function broadcast(status: UpdateStatus): void {
current = status
for (const win of BrowserWindow.getAllWindows()) {
win.webContents.send('updater:status', status)
}
}

async function openReleases(): Promise<void> {
await shell.openExternal(RELEASES_URL)
}

async function checkForUpdates(): Promise<void> {
if (!updaterEnabled()) return
try {
await autoUpdater.checkForUpdates()
} catch {
if (userInitiated) {
broadcast({ state: 'error', message: 'Could not check for updates.' })
}
}
}

export async function startUpdate(): Promise<void> {
if (!updaterEnabled()) return
userInitiated = true
if (current.state === 'error' || !canInstallInPlace()) {
await openReleases()
return
}
if (current.state === 'ready') {
autoUpdater.quitAndInstall()
return
}
try {
await autoUpdater.downloadUpdate()
} catch {
broadcast({ state: 'error', message: 'Could not download the update.' })
}
}

export async function installUpdate(): Promise<void> {
if (!updaterEnabled()) return
if (!canInstallInPlace() || current.state !== 'ready') {
await openReleases()
return
}
autoUpdater.quitAndInstall()
}

export function registerUpdater(): void {
ipcMain.handle('updater:start', () => startUpdate())
ipcMain.handle('updater:install', () => installUpdate())
ipcMain.handle('updater:get', () => current)

if (!updaterEnabled()) return

autoUpdater.autoDownload = false
autoUpdater.autoInstallOnAppQuit = true
autoUpdater.allowPrerelease = false

autoUpdater.on('update-available', (info) => {
broadcast({ state: 'available', version: info.version })
})
autoUpdater.on('update-not-available', () => {
broadcast({ state: 'idle' })
})
autoUpdater.on('download-progress', (progress) => {
broadcast({ state: 'downloading', percent: Math.round(progress.percent) })
})
autoUpdater.on('update-downloaded', (info) => {
broadcast({ state: 'ready', version: info.version })
})
autoUpdater.on('error', (error) => {
if (!userInitiated) return
broadcast({
state: 'error',
message: error instanceof Error ? error.message : 'Update failed'
})
})

void checkForUpdates()
checkTimer = setInterval(() => {
userInitiated = false
void checkForUpdates()
}, CHECK_EVERY_MS)
checkTimer.unref?.()
}
16 changes: 15 additions & 1 deletion src/preload/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { clipboard, contextBridge, ipcRenderer } from 'electron'
import type { Page, VoicePagesApi, WhisperStatus } from '../shared/types'
import type { Page, UpdateStatus, VoicePagesApi, WhisperStatus } from '../shared/types'

const api: VoicePagesApi = {
listPages: () => ipcRenderer.invoke('pages:list'),
Expand All @@ -18,6 +18,20 @@ const api: VoicePagesApi = {
return () => {
ipcRenderer.removeListener('whisper:status', listener)
}
},
startUpdate: () => ipcRenderer.invoke('updater:start'),
installUpdate: () => ipcRenderer.invoke('updater:install'),
onUpdateStatus: (callback) => {
const listener = (_event: Electron.IpcRendererEvent, status: UpdateStatus): void => {
callback(status)
}
ipcRenderer.on('updater:status', listener)
void ipcRenderer.invoke('updater:get').then((status: UpdateStatus) => {
callback(status)
})
return () => {
ipcRenderer.removeListener('updater:status', listener)
}
}
}

Expand Down
44 changes: 42 additions & 2 deletions src/renderer/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useCallback, useEffect, useMemo, useRef, useState } from 'react'
import { startCapture, type CaptureHandle } from './audio/capture'
import lyraIcon from './assets/lyra-icon.png'
import type { Page, PageSummary, WhisperStatus } from '../../shared/types'
import type { Page, PageSummary, UpdateStatus, WhisperStatus } from '../../shared/types'

function formatUpdated(value: string): string {
const date = new Date(value)
Expand Down Expand Up @@ -41,6 +41,16 @@ function statusLabel(
return 'Idle · everything stays on this computer'
}

function updateChipLabel(status: UpdateStatus): string | null {
if (status.state === 'available') return 'Update'
if (status.state === 'downloading') {
return status.percent > 0 ? `Updating… ${status.percent}%` : 'Updating…'
}
if (status.state === 'ready') return 'Restart'
if (status.state === 'error') return 'Update failed'
return null
}

function appendTranscript(body: string, chunk: string): string {
const text = chunk.trim()
if (!text) return body
Expand All @@ -64,6 +74,7 @@ export default function App(): React.JSX.Element {
const [micName, setMicName] = useState('')
const [error, setError] = useState<string | null>(null)
const [copied, setCopied] = useState(false)
const [update, setUpdate] = useState<UpdateStatus>({ state: 'idle' })
const copiedTimer = useRef<ReturnType<typeof setTimeout> | null>(null)
const captureRef = useRef<CaptureHandle | null>(null)
const currentRef = useRef<Page | null>(null)
Expand Down Expand Up @@ -96,7 +107,12 @@ export default function App(): React.JSX.Element {

useEffect(() => {
void refreshList()
return window.api.onStatus(setStatus)
const stopStatus = window.api.onStatus(setStatus)
const stopUpdate = window.api.onUpdateStatus(setUpdate)
return () => {
stopStatus()
stopUpdate()
}
}, [refreshList])

const persist = useCallback((page: Page, immediate = false) => {
Expand Down Expand Up @@ -327,6 +343,17 @@ export default function App(): React.JSX.Element {
return Math.min(100, Math.round((status.received / status.total) * 100))
}, [status])

const updateLabel = updateChipLabel(update)

const onUpdateChip = (): void => {
if (update.state === 'downloading') return
if (update.state === 'ready') {
void window.api.installUpdate()
return
}
void window.api.startUpdate()
}

return (
<div className="app">
<aside className="sidebar">
Expand Down Expand Up @@ -394,6 +421,19 @@ export default function App(): React.JSX.Element {
))
)}
</div>
{updateLabel ? (
<div className="sidebar-update">
<button
className="update-chip"
type="button"
disabled={update.state === 'downloading'}
title={update.state === 'available' ? `Version ${update.version} is available` : undefined}
onClick={onUpdateChip}
>
{updateLabel}
</button>
</div>
) : null}
</aside>

<main className="workspace">
Expand Down
Loading
Loading