feat(app): load heavy desktop assets on demand, update in place (#3343)

This commit is contained in:
Hampus authored and GitHub committed 2026-10-09 03:53:57 +02:00
1 parent 5072488f1e
commit fc60d05f17
47 files changed
+4414 -1190

No files matched your search

+39
View File
@@ -37,6 +37,24 @@ const ENTRY_STYLESHEET_LINK_PATTERN = /<link href="([^"]+\.css)" rel="stylesheet
const CSS_URL_PATTERN = /url\(\s*['"]?([^'")]+)/gu;
const DESKTOP_MODULE_ASSET_QUERY = /[?&]m=([a-z][a-z0-9_]{0,63})(?:&|$)/u;
const RESERVED_DESKTOP_MODULE_NAMES = new Set(['assets', 'fluxer_renderer']);
const DESKTOP_MODULE_ASSET_SOURCES = [
{
test: /[\\/]fonts[\\/]files[\\/]FluxerSans(JP|KR|SC|TC)[\\/][^\\/]+\.woff2$/u,
moduleName: (match) => `fluxer_fonts_${match[1].toLowerCase()}`,
},
{
test: /[\\/]@arborium[\\/]([a-z0-9-]+)[\\/]grammar_bg\.wasm$/u,
moduleName: (match) => `fluxer_grammar_${match[1].replace(/-/gu, '_')}`,
},
{
test: /[\\/]deepfilternet3[\\/](df_bg\.wasm|[^\\/]+\.tar\.gz)$/u,
moduleName: () => 'fluxer_deepfilter',
},
{
test: /[\\/]onnxruntime-web[\\/]dist[\\/][^\\/]+\.wasm$|[\\/]camera-effects[\\/]models[\\/][^\\/]+\.onnx$/u,
moduleName: () => 'fluxer_camera_effects',
},
];
class UnusableDesktopModuleQueryError extends Error {
constructor(resource) {
@@ -55,6 +73,26 @@ function desktopModuleAssetName(resource) {
return match[1];
}
function desktopModuleAssetRules(isProduction) {
return DESKTOP_MODULE_ASSET_SOURCES.map((source) => ({
test: source.test,
type: 'asset/resource',
generator: {
filename: (pathData) => {
const match = source.test.exec(pathData.filename ?? '');
if (match == null) {
throw new UnusableDesktopModuleQueryError(pathData.filename ?? '');
}
const moduleName = source.moduleName(match);
const extension = pathData.filename.endsWith('.tar.gz') ? '.tar.gz' : '[ext]';
return isProduction
? `assets/${moduleName}/[contenthash:16]${extension}`
: `assets/${moduleName}/[name].[hash]${extension}`;
},
},
}));
}
function resolveMode() {
const modeIndex = process.argv.indexOf('--mode');
if (modeIndex >= 0) {
@@ -632,6 +670,7 @@ export default () => {
filename: isProduction ? 'assets/[contenthash:16][ext]' : 'assets/[name].[hash][ext]',
},
},
...(isDesktopRenderer ? desktopModuleAssetRules(isProduction) : []),
{
resourceQuery: DESKTOP_MODULE_ASSET_QUERY,
type: 'asset/resource',