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
1 change: 1 addition & 0 deletions apps/desktop/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"@fontsource/inter": "^5.3.0",
"@tauri-apps/api": "~2.12.4",
"@tauri-apps/plugin-notification": "^2.8.1",
"@tauri-apps/plugin-opener": "^2.7.3",
"@tauri-apps/plugin-process": "^2.4.0",
"@tauri-apps/plugin-updater": "^2.14.1",
"@timephy/rnnoise-wasm": "^1.0.0",
Expand Down
16 changes: 16 additions & 0 deletions apps/desktop/scripts/browserEntryGuard.d.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/** The part of an output chunk the guard reads (Rollup and Rolldown share it). */
export interface GuardedChunk {
type: 'chunk';
fileName: string;
isEntry: boolean;
imports?: readonly string[];
moduleIds?: readonly string[];
modules?: Record<string, unknown>;
}
export function isTauriModule(id: unknown): boolean;
export function tauriModulesAtStartup(bundle: Record<string, GuardedChunk | { type: 'asset'; fileName: string }>): string[];
export function browserEntryGuard(): {
name: string;
apply: 'build';
generateBundle(this: { error(message: string): never }, options: unknown, bundle: Record<string, unknown>): void;
};
58 changes: 58 additions & 0 deletions apps/desktop/scripts/browserEntryGuard.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// The desktop client is ONE bundle for the Tauri app and for the browser: it
// picks the desktop paths at run time ('__TAURI_INTERNALS__' in window), and
// every @tauri-apps/* module is loaded with import() inside such a path. A
// static import anywhere in the startup graph would put desktop-only code in
// what every browser session downloads and runs. This Vite plugin fails the
// production build when it does: the chunks a browser loads at startup are
// the entry chunks and the chunks they import statically, transitively (the
// ones index.html preloads); a chunk reached only through import() is loaded
// when that import runs, and may hold Tauri code.
//
// Pure functions here, so the desktop test suite can pin them; vite.config.ts
// registers the plugin.

/** A module of a @tauri-apps/* package (a path under node_modules, either separator). */
export function isTauriModule(id) {
return typeof id === 'string' && /[\\/]node_modules[\\/](?:.*[\\/])?@tauri-apps[\\/]/.test(id);
}

/**
* The @tauri-apps module ids in the chunks of `bundle` (Rollup/Rolldown's
* output bundle) that a browser loads at startup, sorted, each once.
*/
export function tauriModulesAtStartup(bundle) {
const chunks = Object.values(bundle).filter((output) => output && output.type === 'chunk');
const byFile = new Map(chunks.map((chunk) => [chunk.fileName, chunk]));
const queue = chunks.filter((chunk) => chunk.isEntry).map((chunk) => chunk.fileName);
const seen = new Set();
const found = new Set();
while (queue.length > 0) {
const fileName = queue.shift();
if (seen.has(fileName)) continue;
seen.add(fileName);
const chunk = byFile.get(fileName);
if (!chunk) continue;
for (const id of chunk.moduleIds ?? Object.keys(chunk.modules ?? {})) {
if (isTauriModule(id)) found.add(id);
}
queue.push(...(chunk.imports ?? []));
}
return [...found].sort();
}

/** The plugin: a production build whose startup chunks hold Tauri code fails, naming the package. */
export function browserEntryGuard() {
return {
name: 'voxium-browser-entry-guard',
apply: 'build',
generateBundle(_options, bundle) {
const found = tauriModulesAtStartup(bundle);
if (found.length === 0) return;
const packages = [...new Set(found.map((id) => /@tauri-apps[\\/][^\\/]+/.exec(id)?.[0].replace('\\', '/')))];
this.error(
`The chunks a browser loads at startup contain Tauri code (${packages.join(', ')}): ` +
'import @tauri-apps/* modules with import() inside the Tauri-only path (scripts/browserEntryGuard.mjs)'
);
},
};
}
85 changes: 19 additions & 66 deletions apps/desktop/src-tauri/Cargo.lock

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

6 changes: 5 additions & 1 deletion apps/desktop/src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ tauri-build = { version = "2", features = [] }

[dependencies]
tauri = { version = "2", features = ["image-png", "tray-icon"] }
tauri-plugin-shell = "2"
# External links (http, https, mailto) open in the system browser or mail
# client through this plugin's open_url: the webview's click handler is
# apps/desktop/src/utils/externalLinks.ts, the plugin's own injected one is
# off (src/lib.rs)
tauri-plugin-opener = "2"
tauri-plugin-notification = "2"
tauri-plugin-updater = "2"
tauri-plugin-process = "2"
Expand Down
5 changes: 4 additions & 1 deletion apps/desktop/src-tauri/capabilities/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@
"core:window:allow-unminimize",
"core:window:allow-destroy",
"core:webview:allow-webview-close",
"shell:allow-open",
{
"identifier": "opener:allow-open-url",
"allow": [{ "url": "http://*" }, { "url": "https://*" }, { "url": "mailto:*" }]
},
"notification:default",
"notification:allow-is-permission-granted",
"notification:allow-request-permission",
Expand Down
2 changes: 1 addition & 1 deletion apps/desktop/src-tauri/gen/schemas/acl-manifests.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion apps/desktop/src-tauri/gen/schemas/capabilities.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"default":{"identifier":"default","description":"Default capabilities for Voxium","local":true,"windows":["main","splash"],"permissions":["core:default","core:window:allow-start-dragging","core:window:allow-minimize","core:window:allow-toggle-maximize","core:window:allow-is-maximized","core:window:allow-close","core:window:allow-set-icon","core:window:allow-show","core:window:allow-hide","core:window:allow-set-focus","core:window:allow-unminimize","core:window:allow-destroy","core:webview:allow-webview-close","shell:allow-open","notification:default","notification:allow-is-permission-granted","notification:allow-request-permission","notification:allow-notify","notification:allow-show","updater:default","process:allow-restart"]}}
{"default":{"identifier":"default","description":"Default capabilities for Voxium","local":true,"windows":["main","splash"],"permissions":["core:default","core:window:allow-start-dragging","core:window:allow-minimize","core:window:allow-toggle-maximize","core:window:allow-is-maximized","core:window:allow-close","core:window:allow-set-icon","core:window:allow-show","core:window:allow-hide","core:window:allow-set-focus","core:window:allow-unminimize","core:window:allow-destroy","core:webview:allow-webview-close",{"identifier":"opener:allow-open-url","allow":[{"url":"http://*"},{"url":"https://*"},{"url":"mailto:*"}]},"notification:default","notification:allow-is-permission-granted","notification:allow-request-permission","notification:allow-notify","notification:allow-show","updater:default","process:allow-restart"]}}
Loading
Loading