Skip to content

Private AI meeting notes that stay on your computer. No meeting bot. Free and open source for Mac, Windows and Linux. An alternative to Granola, Otter and Fireflies.

Linux: notes load with the runAsNode fuse off (#9), the AppImage starts on Wayland (#8)

christianmat526d321ce80d
diff --git a/app/build/linux-launcher.sh b/app/build/linux-launcher.sh
new file mode 100644
index 00000000..648ebf78
--- /dev/null
+++ b/app/build/linux-launcher.sh
@@ -0,0 +1,9 @@
+#!/bin/sh
+# Starts Yogurt (yogurt-bin) on X11 through XWayland on a Wayland desktop, where the recorder widget and the
+# "Take notes" card can float (src/main/display.ts). The switch has to be there before Electron starts, and an
+# in-app relaunch can't mount the AppImage again, so it's added here. A switch given by hand wins.
+here=$(dirname "$(readlink -f "$0")")
+case " $* " in *" --ozone-platform"*) ;; *)
+ [ -n "$WAYLAND_DISPLAY" ] && [ -n "$DISPLAY" ] && set -- --ozone-platform=x11 "$@" ;;
+esac
+exec "$here/yogurt-bin" "$@"
diff --git a/app/electron-builder.yml b/app/electron-builder.yml
index c47fec9e..04211efd 100644
--- a/app/electron-builder.yml
+++ b/app/electron-builder.yml
@@ -47,6 +47,8 @@ electronFuses:
enableNodeCliInspectArguments: false
onlyLoadAppFromAsar: true
enableEmbeddedAsarIntegrityValidation: true
+# Linux: `yogurt` becomes a launcher that starts Electron on X11 on a Wayland desktop (build/linux-launcher.sh)
+afterPack: scripts/linux-launcher.cjs
asarUnpack:
# the notes model's engine loads native binaries; they can't run from inside the asar archive
- "**/node_modules/node-llama-cpp/**"
diff --git a/app/scripts/linux-launcher.cjs b/app/scripts/linux-launcher.cjs
new file mode 100644
index 00000000..a9bb1c09
--- /dev/null
+++ b/app/scripts/linux-launcher.cjs
@@ -0,0 +1,21 @@
+// electron-builder afterPack: on Linux, `yogurt` becomes build/linux-launcher.sh and Electron moves to yogurt-bin (#8)
+const { chmodSync, copyFileSync, existsSync, renameSync } = require('node:fs')
+const { join } = require('node:path')
+
+function wrapLinuxBinary(dir, name) {
+ const bin = join(dir, `${name}-bin`)
+ if (existsSync(bin)) throw new Error(`${bin} is already there: wrapped twice`)
+ renameSync(join(dir, name), bin)
+ copyFileSync(join(__dirname, '../build/linux-launcher.sh'), join(dir, name))
+ chmodSync(join(dir, name), 0o755)
+}
+
+module.exports = async (context) => {
+ if (context.electronPlatformName !== 'linux') return
+ const { packager, appOutDir } = context
+ wrapLinuxBinary(appOutDir, packager.executableName)
+ // electron-builder flips the fuses after this hook, on `yogurt`: they belong on the Electron the launcher starts
+ const { flipFuses } = require(require.resolve('@electron/fuses', { paths: [require.resolve('app-builder-lib')] }))
+ packager.addElectronFuses = (ctx, fuses) => flipFuses(join(ctx.appOutDir, `${packager.executableName}-bin`), fuses)
+}
+module.exports.wrapLinuxBinary = wrapLinuxBinary
diff --git a/app/scripts/linux-launcher.d.cts b/app/scripts/linux-launcher.d.cts
new file mode 100644
index 00000000..146c99cf
--- /dev/null
+++ b/app/scripts/linux-launcher.d.cts
@@ -0,0 +1 @@
+export function wrapLinuxBinary(dir: string, name: string): void
diff --git a/app/src/main/display.ts b/app/src/main/display.ts
index 087459c0..844ed4ab 100644
--- a/app/src/main/display.ts
+++ b/app/src/main/display.ts
@@ -3,12 +3,12 @@
* windows nor keep them above others, so the recorder widget and the "Take notes" card couldn't float, and browser
* call titles can't be read. The switch must be on the command line before Electron starts (appendSwitch is too late
* for the display server), so a Wayland launch starts once more with it. Its arguments (--hidden) are kept.
+ * The AppImage never does: its launcher (build/linux-launcher.sh) adds the switch, and a relaunch couldn't mount it again.
*/
export function x11Relaunch(platform: string, argv: string[], env: Record<string, string | undefined>, execPath: string): { execPath: string; args: string[] } | null {
if (platform !== 'linux' || env.YOGURT_FAKE === '1') return null
// XWayland is there only with DISPLAY; without it, Wayland is all there is
if (!env.WAYLAND_DISPLAY || !env.DISPLAY) return null
- if (argv.some((a) => a.startsWith('--ozone-platform'))) return null
- // the AppImage's own mount goes away when it quits: start the AppImage itself
- return { execPath: env.APPIMAGE || execPath, args: [...argv.slice(1), '--ozone-platform=x11'] }
+ if (env.APPIMAGE || argv.some((a) => a.startsWith('--ozone-platform'))) return null
+ return { execPath, args: [...argv.slice(1), '--ozone-platform=x11'] }
}
diff --git a/app/test/builderConfig.test.ts b/app/test/builderConfig.test.ts
index 053efa5e..127217ca 100644
--- a/app/test/builderConfig.test.ts
+++ b/app/test/builderConfig.test.ts
@@ -27,3 +27,7 @@ it("only Windows and Linux carry the speed check's clip: a Mac never times its s
for (const os of ['win', 'linux']) expect(block(os)).toContain('{ from: resources/speed, to: speed }')
expect(config.split(/^win:$/m)[0]).not.toContain('resources/speed')
})
+
+it('the Linux build starts through the launcher that picks X11 on Wayland (#8)', () => {
+ expect(config).toMatch(/^afterPack: scripts\/linux-launcher\.cjs$/m)
+})
diff --git a/app/test/display.test.ts b/app/test/display.test.ts
index 8907190f..b26eeff0 100644
--- a/app/test/display.test.ts
+++ b/app/test/display.test.ts
@@ -4,8 +4,6 @@ import { x11Relaunch } from '../src/main/display'
const wayland = { WAYLAND_DISPLAY: 'wayland-0', DISPLAY: ':0' }
it('Linux on Wayland starts again through XWayland, where the widget and the card can float and stay put', () => {
- expect(x11Relaunch('linux', ['/opt/Yogurt/yogurt', '--hidden'], { ...wayland, APPIMAGE: '/home/sam/Yogurt.AppImage' }, '/tmp/.mount_x/yogurt'))
- .toEqual({ execPath: '/home/sam/Yogurt.AppImage', args: ['--hidden', '--ozone-platform=x11'] })
expect(x11Relaunch('linux', ['/usr/lib/electron', '.'], wayland, '/usr/lib/electron')).toEqual({ execPath: '/usr/lib/electron', args: ['.', '--ozone-platform=x11'] })
})
@@ -17,4 +15,6 @@ it('never twice, never without XWayland, never on X11, a Mac or Windows, and nev
expect(x11Relaunch('darwin', ['y'], wayland, 'y')).toBeNull()
expect(x11Relaunch('win32', ['y'], wayland, 'y')).toBeNull()
expect(x11Relaunch('linux', ['y'], { ...wayland, YOGURT_FAKE: '1' }, 'y')).toBeNull()
+ // the AppImage's launcher picks X11 itself: starting it again couldn't mount it (#8)
+ expect(x11Relaunch('linux', ['/tmp/.mount_x/yogurt-bin'], { ...wayland, APPIMAGE: '/home/sam/Yogurt.AppImage' }, '/tmp/.mount_x/yogurt-bin')).toBeNull()
})
diff --git a/app/test/linuxLauncher.test.ts b/app/test/linuxLauncher.test.ts
new file mode 100644
index 00000000..be007c28
--- /dev/null
+++ b/app/test/linuxLauncher.test.ts
@@ -0,0 +1,34 @@
+import { execFileSync } from 'node:child_process'
+import { chmodSync, copyFileSync, mkdtempSync, writeFileSync } from 'node:fs'
+import { tmpdir } from 'node:os'
+import { join } from 'node:path'
+import { expect, it } from 'vitest'
+import { wrapLinuxBinary } from '../scripts/linux-launcher.cjs'
+
+// The AppImage starts build/linux-launcher.sh as `yogurt`, which picks X11 before Electron starts (#8):
+// an in-app relaunch couldn't mount the AppImage again on Wayland
+function launch(env: Record<string, string>, args: string[] = []): string[] {
+ const dir = mkdtempSync(join(tmpdir(), 'yogurt-launcher-'))
+ writeFileSync(join(dir, 'yogurt'), '#!/bin/sh\nfor a in "$@"; do echo "$a"; done\n')
+ chmodSync(join(dir, 'yogurt'), 0o755)
+ wrapLinuxBinary(dir, 'yogurt')
+ const out = execFileSync(join(dir, 'yogurt'), args, { env: { PATH: process.env.PATH!, ...env }, encoding: 'utf8' })
+ return out.split('\n').filter(Boolean)
+}
+
+it.skipIf(process.platform === 'win32')('on Wayland with XWayland it starts Electron on X11, keeping the arguments', () => {
+ expect(launch({ WAYLAND_DISPLAY: 'wayland-0', DISPLAY: ':0' }, ['--hidden', 'a b'])).toEqual(['--ozone-platform=x11', '--hidden', 'a b'])
+})
+
+it.skipIf(process.platform === 'win32')('X11 alone, Wayland without XWayland, or a switch given by hand: Electron starts as asked', () => {
+ expect(launch({ DISPLAY: ':0' }, ['--hidden'])).toEqual(['--hidden'])
+ expect(launch({ WAYLAND_DISPLAY: 'wayland-0' })).toEqual([])
+ expect(launch({ WAYLAND_DISPLAY: 'wayland-0', DISPLAY: ':0' }, ['--ozone-platform=wayland'])).toEqual(['--ozone-platform=wayland'])
+})
+
+it.skipIf(process.platform === 'win32')('wrapping twice keeps the real binary', () => {
+ const dir = mkdtempSync(join(tmpdir(), 'yogurt-launcher-'))
+ copyFileSync('/bin/echo', join(dir, 'yogurt'))
+ wrapLinuxBinary(dir, 'yogurt')
+ expect(() => wrapLinuxBinary(dir, 'yogurt')).toThrow()
+})
diff --git a/patches/[email protected] b/patches/[email protected]
new file mode 100644
index 00000000..4a380d15
--- /dev/null
+++ b/patches/[email protected]
@@ -0,0 +1,19 @@
+diff --git a/dist/bindings/utils/testBindingBinary.js b/dist/bindings/utils/testBindingBinary.js
+index fc2ed379662d4d5cc7282a9d01faf3c327caa593..755ff2e216960846739a8bcb1f8f3d3baf5dce63 100644
+--- a/dist/bindings/utils/testBindingBinary.js
++++ b/dist/bindings/utils/testBindingBinary.js
+@@ -22,6 +22,11 @@ export async function testBindingBinary(bindingBinaryPath, extBackendsPath, gpu,
+ 'To resolve this issue, make sure that "node-llama-cpp" is not bundled together with other code and is imported as an external module with its original file structure.');
+ return true;
+ }
++ // Yogurt: the engine runs in an Electron utility process, which can't import utilityProcess, and child_process.fork()
++ // needs the runAsNode fuse a shipped app turns off. Load untested: if a graphics driver crashes the engine,
++ // the app starts it again without the graphics card (src/main/engine.ts).
++ if (runningInElectron && process.parentPort != null)
++ return true;
+ try {
+ const runningInsideSnapOnLinux = getPlatform() === "linux" && process.env.SNAP != null;
+ if (runningInsideSnapOnLinux && !runningInBun && !runningInElectron) {
+diff --git a/templates/README.md b/templates/README.md
+deleted file mode 100644
+index c47d3c3ae991accbfae308db67101ef5bc66c4c2..0000000000000000000000000000000000000000
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index ced1d42c..e94af2c8 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -4,6 +4,11 @@ settings:
autoInstallPeers: true
excludeLinksFromLockfile: false
+patchedDependencies:
+ hash: fb1b72ef61aee31b92af3fbf2624ad8cd9db513628681b7d141f463433c6ef4c
+ path: patches/[email protected]
+
importers:
.: {}
@@ -15,7 +20,7 @@ importers:
version: 6.8.10
node-llama-cpp:
specifier: 3.22.1
- version: 3.22.1([email protected])
+ version: 3.22.1(patch_hash=fb1b72ef61aee31b92af3fbf2624ad8cd9db513628681b7d141f463433c6ef4c)([email protected])
devDependencies:
'@animate-ui/react':
specifier: 2.0.0
@@ -4722,7 +4727,7 @@ snapshots:
+ [email protected](patch_hash=fb1b72ef61aee31b92af3fbf2624ad8cd9db513628681b7d141f463433c6ef4c)([email protected]):
dependencies:
'@huggingface/jinja': 0.5.11
async-retry: 1.3.3
diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml
index eb268a99..2bae9cb0 100644
--- a/pnpm-workspace.yaml
+++ b/pnpm-workspace.yaml
@@ -5,3 +5,5 @@ onlyBuiltDependencies:
- electron
- esbuild
- node-llama-cpp
+patchedDependencies: