sparkbun 0.1.4 → 0.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist-linux-arm64/libNativeWrapper.so +0 -0
- package/dist-linux-arm64/{libElectrobunCore.so → libSparkBunCore.so} +0 -0
- package/dist-linux-x64/libNativeWrapper.so +0 -0
- package/dist-linux-x64/{libElectrobunCore.so → libSparkBunCore.so} +0 -0
- package/dist-macos-arm64/libNativeWrapper.dylib +0 -0
- package/dist-macos-arm64/libSparkBunCore.dylib +0 -0
- package/dist-macos-x64/libNativeWrapper.dylib +0 -0
- package/dist-macos-x64/libSparkBunCore.dylib +0 -0
- package/dist-macos-x64/libasar.dylib +0 -0
- package/dist-macos-x64/libwebgpu_dawn.dylib +0 -0
- package/dist-macos-x64/process_helper +0 -0
- package/dist-win-arm64/SparkBunCore.dll +0 -0
- package/dist-win-arm64/WebView2Loader.dll +0 -0
- package/dist-win-arm64/libNativeWrapper.dll +0 -0
- package/dist-win-arm64/zig-asar/arm64/libasar.dll +0 -0
- package/dist-win-arm64/zig-asar/x64/libasar.dll +0 -0
- package/dist-win-x64/SparkBunCore.dll +0 -0
- package/package.json +1 -1
- package/scripts/setup-win-arm64.ps1 +19 -0
- package/src/browser/global.d.ts +11 -11
- package/src/browser/index.ts +10 -10
- package/src/bun/core/BrowserView.ts +2 -2
- package/src/bun/core/Updater.ts +6 -56
- package/src/bun/preload/.generated/compiled.ts +2 -2
- package/src/bun/preload/dragRegions.ts +2 -2
- package/src/bun/preload/encryption.ts +4 -4
- package/src/bun/preload/events.ts +4 -4
- package/src/bun/preload/globals.d.ts +14 -14
- package/src/bun/preload/index-sandboxed.ts +3 -3
- package/src/bun/preload/index.ts +19 -19
- package/src/bun/preload/internalRpc.ts +3 -3
- package/src/bun/preload/webviewTag.ts +2 -2
- package/src/bun/preload/wgpuTag.ts +1 -1
- package/src/bun/proc/native.ts +6 -6
- package/src/cli/index.ts +47 -83
- package/src/core/build.zig +1 -1
- package/src/core/main.zig +25 -24
- package/src/installer/installer-template.ts +1 -1
- package/src/launcher/main.ts +10 -10
- package/src/native/linux/cef_process_helper_linux.cpp +4 -4
- package/src/native/linux/nativeWrapper.cpp +230 -230
- package/src/native/macos/cef_process_helper_mac.cc +4 -4
- package/src/native/macos/nativeWrapper.mm +100 -100
- package/src/native/shared/accelerator_parser.h +5 -5
- package/src/native/shared/app_paths.h +7 -7
- package/src/native/shared/asar.h +5 -5
- package/src/native/shared/cache_migration.h +14 -14
- package/src/native/shared/callbacks.h +5 -5
- package/src/native/shared/cef_response_filter.h +18 -18
- package/src/native/shared/chromium_flags.h +6 -6
- package/src/native/shared/config.h +5 -5
- package/src/native/shared/download_event.h +5 -5
- package/src/native/shared/ffi_helpers.h +6 -6
- package/src/native/shared/glob_match.h +5 -5
- package/src/native/shared/json_menu_parser.h +5 -5
- package/src/native/shared/mime_types.h +5 -5
- package/src/native/shared/navigation_rules.h +5 -5
- package/src/native/shared/partition_context.h +5 -5
- package/src/native/shared/permissions.h +5 -5
- package/src/native/shared/permissions_cef.h +5 -5
- package/src/native/shared/preload_script.h +5 -5
- package/src/native/shared/shutdown_guard.h +5 -5
- package/src/native/shared/thread_safe_map.h +5 -5
- package/src/native/shared/webview_storage.h +5 -5
- package/src/native/win/cef_process_helper_win.cpp +4 -4
- package/src/native/win/dcomp_compositor.h +1 -1
- package/src/native/win/nativeWrapper.cpp +288 -288
- package/src/shared/bsdiff.ts +236 -0
- package/src/shared/bspatch.ts +98 -0
- package/dist-linux-arm64/bsdiff +0 -0
- package/dist-linux-arm64/bspatch +0 -0
- package/dist-linux-x64/bsdiff +0 -0
- package/dist-linux-x64/bspatch +0 -0
- package/dist-macos-arm64/bsdiff +0 -0
- package/dist-macos-arm64/bspatch +0 -0
- package/dist-macos-arm64/libElectrobunCore.dylib +0 -0
- package/dist-macos-arm64/preload-full.js +0 -885
- package/dist-macos-arm64/preload-sandboxed.js +0 -111
- package/dist-win-x64/ElectrobunCore.dll +0 -0
- package/dist-win-x64/bsdiff.exe +0 -0
- package/dist-win-x64/bspatch.exe +0 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// Internal RPC System for webview tags, drag regions, etc.
|
|
2
|
-
// Communicates with Bun via
|
|
2
|
+
// Communicates with Bun via __sparkbunInternalBridge
|
|
3
3
|
|
|
4
4
|
import "./globals.d.ts";
|
|
5
5
|
|
|
@@ -23,7 +23,7 @@ function processQueue() {
|
|
|
23
23
|
isProcessingQueue = true;
|
|
24
24
|
const batch = JSON.stringify(sendQueue);
|
|
25
25
|
sendQueue.length = 0;
|
|
26
|
-
window.
|
|
26
|
+
window.__sparkbunInternalBridge?.postMessage(batch);
|
|
27
27
|
|
|
28
28
|
// 2ms delay to work around Bun JSCallback threading issue
|
|
29
29
|
setTimeout(() => {
|
|
@@ -48,7 +48,7 @@ export function request(type: string, payload: unknown): Promise<unknown> {
|
|
|
48
48
|
method: type,
|
|
49
49
|
id,
|
|
50
50
|
params: payload,
|
|
51
|
-
hostWebviewId: window.
|
|
51
|
+
hostWebviewId: window.__sparkbunWebviewId,
|
|
52
52
|
}),
|
|
53
53
|
);
|
|
54
54
|
processQueue();
|
|
@@ -126,8 +126,8 @@ export class SparkBunWebviewTag extends HTMLElement {
|
|
|
126
126
|
|
|
127
127
|
try {
|
|
128
128
|
const webviewInitParams = {
|
|
129
|
-
hostWebviewId: window.
|
|
130
|
-
windowId: window.
|
|
129
|
+
hostWebviewId: window.__sparkbunWebviewId,
|
|
130
|
+
windowId: window.__sparkbunWindowId,
|
|
131
131
|
renderer,
|
|
132
132
|
url,
|
|
133
133
|
html,
|
package/src/bun/proc/native.ts
CHANGED
|
@@ -75,7 +75,7 @@ function getWindowPtr(winId: number) {
|
|
|
75
75
|
}
|
|
76
76
|
|
|
77
77
|
function getCoreLastError(): string | null {
|
|
78
|
-
const error = core?.symbols.
|
|
78
|
+
const error = core?.symbols.sparkbun_core_last_error();
|
|
79
79
|
if (!error) {
|
|
80
80
|
return null;
|
|
81
81
|
}
|
|
@@ -110,11 +110,11 @@ const core = (() => {
|
|
|
110
110
|
const corePath = join(
|
|
111
111
|
binDir,
|
|
112
112
|
process.platform === "win32"
|
|
113
|
-
? "
|
|
114
|
-
: `
|
|
113
|
+
? "SparkBunCore.dll"
|
|
114
|
+
: `libSparkBunCore.${suffix}`,
|
|
115
115
|
);
|
|
116
116
|
return dlopen(corePath, {
|
|
117
|
-
|
|
117
|
+
sparkbun_core_last_error: {
|
|
118
118
|
args: [],
|
|
119
119
|
returns: FFIType.cstring,
|
|
120
120
|
},
|
|
@@ -620,7 +620,7 @@ const core = (() => {
|
|
|
620
620
|
},
|
|
621
621
|
});
|
|
622
622
|
} catch (err) {
|
|
623
|
-
throw new Error(`Failed to load
|
|
623
|
+
throw new Error(`Failed to load SparkBunCore: ${err}`);
|
|
624
624
|
}
|
|
625
625
|
})();
|
|
626
626
|
|
|
@@ -3066,7 +3066,7 @@ export const internalRpcHandlers = {
|
|
|
3066
3066
|
}
|
|
3067
3067
|
core_.symbols.updatePreloadScriptToWebView(
|
|
3068
3068
|
params.id,
|
|
3069
|
-
toCString("
|
|
3069
|
+
toCString("sparkbun_custom_preload_script"),
|
|
3070
3070
|
toCString(params.preload),
|
|
3071
3071
|
true,
|
|
3072
3072
|
);
|
package/src/cli/index.ts
CHANGED
|
@@ -33,7 +33,6 @@ import {
|
|
|
33
33
|
getMacOSBundleDisplayName,
|
|
34
34
|
} from "../shared/naming";
|
|
35
35
|
import { getTemplate, getTemplateNames } from "./templates/embedded";
|
|
36
|
-
// import { loadBsdiff, loadBspatch } from 'bsdiff-wasm';
|
|
37
36
|
// MacOS named pipes hang at around 4KB
|
|
38
37
|
// @ts-expect-error - reserved for future use
|
|
39
38
|
const _MAX_CHUNK_SIZE = 1024 * 2;
|
|
@@ -115,17 +114,15 @@ function getPlatformPaths(
|
|
|
115
114
|
BUN_BINARY: join(platformDistDir, "bun") + binExt,
|
|
116
115
|
LAUNCHER_DEV: join(platformDistDir, "sparkbun") + binExt,
|
|
117
116
|
LAUNCHER_RELEASE: join(platformDistDir, "launcher") + binExt,
|
|
118
|
-
CORE_MACOS: join(platformDistDir, "
|
|
119
|
-
CORE_WIN: join(platformDistDir, "
|
|
120
|
-
CORE_LINUX: join(platformDistDir, "
|
|
117
|
+
CORE_MACOS: join(platformDistDir, "libSparkBunCore.dylib"),
|
|
118
|
+
CORE_WIN: join(platformDistDir, "SparkBunCore.dll"),
|
|
119
|
+
CORE_LINUX: join(platformDistDir, "libSparkBunCore.so"),
|
|
121
120
|
NATIVE_WRAPPER_MACOS: join(platformDistDir, "libNativeWrapper.dylib"),
|
|
122
121
|
NATIVE_WRAPPER_WIN: join(platformDistDir, "libNativeWrapper.dll"),
|
|
123
122
|
NATIVE_WRAPPER_LINUX: join(platformDistDir, "libNativeWrapper.so"),
|
|
124
123
|
NATIVE_WRAPPER_LINUX_CEF: join(platformDistDir, "libNativeWrapper_cef.so"),
|
|
125
124
|
WEBVIEW2LOADER_WIN: join(platformDistDir, "WebView2Loader.dll"),
|
|
126
|
-
BSPATCH: join(platformDistDir, "bspatch") + binExt,
|
|
127
125
|
EXTRACTOR: join(platformDistDir, "extractor") + binExt,
|
|
128
|
-
BSDIFF: join(platformDistDir, "bsdiff") + binExt,
|
|
129
126
|
CEF_FRAMEWORK_MACOS: join(
|
|
130
127
|
platformDistDir,
|
|
131
128
|
"cef",
|
|
@@ -136,8 +133,6 @@ function getPlatformPaths(
|
|
|
136
133
|
CEF_HELPER_LINUX: join(platformDistDir, "process_helper"),
|
|
137
134
|
CEF_DIR: join(platformDistDir, "cef"),
|
|
138
135
|
|
|
139
|
-
PRELOAD_FULL_JS: join(platformDistDir, "preload-full.js"),
|
|
140
|
-
PRELOAD_SANDBOXED_JS: join(platformDistDir, "preload-sandboxed.js"),
|
|
141
136
|
};
|
|
142
137
|
}
|
|
143
138
|
|
|
@@ -2086,31 +2081,39 @@ usageDescriptions : ""}${urlTypes ? "\n" + urlTypes : ""}${documentTypes ?
|
|
|
2086
2081
|
};
|
|
2087
2082
|
|
|
2088
2083
|
if (targetOS === "win") {
|
|
2089
|
-
|
|
2090
|
-
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
:
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
|
|
2101
|
-
|
|
2084
|
+
if (OS !== "win") {
|
|
2085
|
+
console.warn(
|
|
2086
|
+
`\n⚠️ Cross-compiling for Windows: icon, hideConsole, and PE metadata (title, version, publisher, etc.) will be ignored.\n` +
|
|
2087
|
+
` Bun's Windows-specific compile options require building on a Windows host.\n` +
|
|
2088
|
+
` See: https://bun.com/docs/bundler/executables#windows-specific-flags\n`
|
|
2089
|
+
);
|
|
2090
|
+
} else {
|
|
2091
|
+
let icoPath: string | undefined;
|
|
2092
|
+
if (config.build.win?.icon) {
|
|
2093
|
+
const iconSrc = config.build.win.icon.startsWith("/") || config.build.win.icon.match(/^[a-zA-Z]:/)
|
|
2094
|
+
? config.build.win.icon
|
|
2095
|
+
: join(projectRoot, config.build.win.icon);
|
|
2096
|
+
if (existsSync(iconSrc)) {
|
|
2097
|
+
icoPath = iconSrc;
|
|
2098
|
+
if (iconSrc.toLowerCase().endsWith(".png")) {
|
|
2099
|
+
const pngToIco = (await import("png-to-ico")).default;
|
|
2100
|
+
const tempIcoPath = join(buildFolder, "temp-launcher-icon.ico");
|
|
2101
|
+
const icoBuffer = await pngToIco(iconSrc);
|
|
2102
|
+
writeFileSync(tempIcoPath, new Uint8Array(icoBuffer));
|
|
2103
|
+
icoPath = tempIcoPath;
|
|
2104
|
+
}
|
|
2102
2105
|
}
|
|
2103
2106
|
}
|
|
2107
|
+
compileOptions.windows = {
|
|
2108
|
+
hideConsole: true,
|
|
2109
|
+
...(icoPath && { icon: icoPath }),
|
|
2110
|
+
title: config.app.name,
|
|
2111
|
+
version: config.app.version,
|
|
2112
|
+
description: config.app.name,
|
|
2113
|
+
publisher: config.app.publisher || " ",
|
|
2114
|
+
copyright: config.app.copyright || " ",
|
|
2115
|
+
};
|
|
2104
2116
|
}
|
|
2105
|
-
compileOptions.windows = {
|
|
2106
|
-
hideConsole: true,
|
|
2107
|
-
...(icoPath && { icon: icoPath }),
|
|
2108
|
-
title: config.app.name,
|
|
2109
|
-
version: config.app.version,
|
|
2110
|
-
description: config.app.name,
|
|
2111
|
-
publisher: config.app.publisher || " ",
|
|
2112
|
-
copyright: config.app.copyright || " ",
|
|
2113
|
-
};
|
|
2114
2117
|
}
|
|
2115
2118
|
|
|
2116
2119
|
console.log(`Compiling launcher with Bun.build()...`);
|
|
@@ -2128,21 +2131,11 @@ usageDescriptions : ""}${urlTypes ? "\n" + urlTypes : ""}${documentTypes ?
|
|
|
2128
2131
|
patchPeSubsystem(bunCliLauncherDestination);
|
|
2129
2132
|
}
|
|
2130
2133
|
|
|
2131
|
-
cpSync(targetPaths.PRELOAD_FULL_JS, join(appBundleFolderResourcesPath, "preload-full.js"), {
|
|
2132
|
-
dereference: true,
|
|
2133
|
-
});
|
|
2134
|
-
cpSync(
|
|
2135
|
-
targetPaths.PRELOAD_SANDBOXED_JS,
|
|
2136
|
-
join(appBundleFolderResourcesPath, "preload-sandboxed.js"),
|
|
2137
|
-
{
|
|
2138
|
-
dereference: true,
|
|
2139
|
-
},
|
|
2140
|
-
);
|
|
2141
2134
|
|
|
2142
2135
|
|
|
2143
2136
|
// copy native wrapper dynamic library
|
|
2144
2137
|
if (targetOS === "macos") {
|
|
2145
|
-
cpSync(targetPaths.CORE_MACOS, join(appBundleMacOSPath, "
|
|
2138
|
+
cpSync(targetPaths.CORE_MACOS, join(appBundleMacOSPath, "libSparkBunCore.dylib"), {
|
|
2146
2139
|
dereference: true,
|
|
2147
2140
|
});
|
|
2148
2141
|
|
|
@@ -2155,7 +2148,7 @@ usageDescriptions : ""}${urlTypes ? "\n" + urlTypes : ""}${documentTypes ?
|
|
|
2155
2148
|
dereference: true,
|
|
2156
2149
|
});
|
|
2157
2150
|
} else if (targetOS === "win") {
|
|
2158
|
-
cpSync(targetPaths.CORE_WIN, join(appBundleMacOSPath, "
|
|
2151
|
+
cpSync(targetPaths.CORE_WIN, join(appBundleMacOSPath, "SparkBunCore.dll"), {
|
|
2159
2152
|
dereference: true,
|
|
2160
2153
|
});
|
|
2161
2154
|
|
|
@@ -2178,7 +2171,7 @@ usageDescriptions : ""}${urlTypes ? "\n" + urlTypes : ""}${documentTypes ?
|
|
|
2178
2171
|
} else if (targetOS === "linux") {
|
|
2179
2172
|
// Choose the appropriate native wrapper based on bundleCEF setting
|
|
2180
2173
|
const useCEF = config.build.linux?.bundleCEF;
|
|
2181
|
-
cpSync(targetPaths.CORE_LINUX, join(appBundleMacOSPath, "
|
|
2174
|
+
cpSync(targetPaths.CORE_LINUX, join(appBundleMacOSPath, "libSparkBunCore.so"), {
|
|
2182
2175
|
dereference: true,
|
|
2183
2176
|
});
|
|
2184
2177
|
const nativeWrapperLinuxSource = useCEF
|
|
@@ -2555,21 +2548,7 @@ usageDescriptions : ""}${urlTypes ? "\n" + urlTypes : ""}${documentTypes ?
|
|
|
2555
2548
|
}
|
|
2556
2549
|
}
|
|
2557
2550
|
|
|
2558
|
-
//
|
|
2559
|
-
const bsPatchSource = targetPaths.BSPATCH;
|
|
2560
|
-
const bsPatchDestination =
|
|
2561
|
-
join(appBundleMacOSPath, "bspatch") + targetBinExt;
|
|
2562
|
-
const bsPatchDestFolder = dirname(bsPatchDestination);
|
|
2563
|
-
if (!existsSync(bsPatchDestFolder)) {
|
|
2564
|
-
mkdirSync(bsPatchDestFolder, { recursive: true });
|
|
2565
|
-
}
|
|
2566
|
-
|
|
2567
|
-
cpSync(bsPatchSource, bsPatchDestination, {
|
|
2568
|
-
recursive: true,
|
|
2569
|
-
dereference: true,
|
|
2570
|
-
});
|
|
2571
|
-
|
|
2572
|
-
// libasar is still loaded by ElectrobunCore at runtime — needed until
|
|
2551
|
+
// libasar is still loaded by SparkBunCore at runtime — needed until
|
|
2573
2552
|
// native wrappers are recompiled without ASAR support
|
|
2574
2553
|
const libExt = targetOS === "win" ? ".dll" : targetOS === "macos" ? ".dylib" : ".so";
|
|
2575
2554
|
const asarLibSource = join(dirname(targetPaths.BSPATCH), "libasar" + libExt);
|
|
@@ -2945,39 +2924,25 @@ usageDescriptions : ""}${urlTypes ? "\n" + urlTypes : ""}${documentTypes ?
|
|
|
2945
2924
|
|
|
2946
2925
|
if (canGeneratePatch) {
|
|
2947
2926
|
console.log("diff previous and new tarballs...");
|
|
2948
|
-
// Run it as a separate process to leverage multi-threadedness
|
|
2949
|
-
// especially for creating multiple diffs in parallel
|
|
2950
|
-
const bsdiffpath = targetPaths.BSDIFF;
|
|
2951
2927
|
const patchFilePath = join(buildFolder, `${prevHash}.patch`);
|
|
2952
|
-
|
|
2953
|
-
|
|
2954
|
-
|
|
2955
|
-
|
|
2956
|
-
|
|
2957
|
-
|
|
2958
|
-
|
|
2959
|
-
|
|
2960
|
-
cwd: buildFolder,
|
|
2961
|
-
stdout: "inherit",
|
|
2962
|
-
stderr: "inherit",
|
|
2963
|
-
},
|
|
2964
|
-
);
|
|
2965
|
-
if (!result.success) {
|
|
2966
|
-
// Patch generation is non-critical - users will just download full updates instead of delta patches
|
|
2928
|
+
try {
|
|
2929
|
+
const { createPatch } = await import("../shared/bsdiff.ts");
|
|
2930
|
+
const oldData = new Uint8Array(await Bun.file(prevTarballPath).arrayBuffer());
|
|
2931
|
+
const newData = new Uint8Array(await Bun.file(tarPath).arrayBuffer());
|
|
2932
|
+
const patch = createPatch(oldData, newData);
|
|
2933
|
+
await Bun.write(patchFilePath, patch);
|
|
2934
|
+
artifactsToUpload.push(patchFilePath);
|
|
2935
|
+
} catch (error) {
|
|
2967
2936
|
console.error("\n" + "=".repeat(80));
|
|
2968
2937
|
console.error(
|
|
2969
|
-
"WARNING: Patch generation failed
|
|
2970
|
-
|
|
2971
|
-
")",
|
|
2938
|
+
"WARNING: Patch generation failed: " +
|
|
2939
|
+
(error as Error).message,
|
|
2972
2940
|
);
|
|
2973
2941
|
console.error(
|
|
2974
2942
|
"Delta updates will not be available for this release.",
|
|
2975
2943
|
);
|
|
2976
2944
|
console.error("Users will download the full update instead.");
|
|
2977
2945
|
console.error("=".repeat(80) + "\n");
|
|
2978
|
-
} else {
|
|
2979
|
-
// Only add patch to artifacts if it was successfully created
|
|
2980
|
-
artifactsToUpload.push(patchFilePath);
|
|
2981
2946
|
}
|
|
2982
2947
|
|
|
2983
2948
|
// Clean up previous tarball now that bsdiff is done
|
|
@@ -4212,7 +4177,6 @@ Description: ${shortDesc}${longDesc}
|
|
|
4212
4177
|
// postinst
|
|
4213
4178
|
writeFileSync(join(controlDir, "postinst"), `#!/bin/sh
|
|
4214
4179
|
chmod +x ${installDir}/bin/${exeName}
|
|
4215
|
-
chmod +x ${installDir}/bin/bspatch 2>/dev/null || true
|
|
4216
4180
|
gtk-update-icon-cache -f -t /usr/share/icons/hicolor 2>/dev/null || true
|
|
4217
4181
|
update-desktop-database /usr/share/applications 2>/dev/null || true
|
|
4218
4182
|
`);
|
package/src/core/build.zig
CHANGED
package/src/core/main.zig
CHANGED
|
@@ -185,7 +185,7 @@ fn freeTrayState(state: *TrayState) void {
|
|
|
185
185
|
}
|
|
186
186
|
}
|
|
187
187
|
|
|
188
|
-
export fn
|
|
188
|
+
export fn sparkbun_core_last_error() [*:0]const u8 {
|
|
189
189
|
if (last_error) |message| {
|
|
190
190
|
return message.ptr;
|
|
191
191
|
}
|
|
@@ -216,7 +216,7 @@ fn rememberDefaultWebviewCallbacks(
|
|
|
216
216
|
}
|
|
217
217
|
|
|
218
218
|
fn ensureHostMessageWakeupInitialized() bool {
|
|
219
|
-
if (builtin.os.tag == .windows) {
|
|
219
|
+
if (comptime builtin.os.tag == .windows) {
|
|
220
220
|
return false;
|
|
221
221
|
}
|
|
222
222
|
|
|
@@ -236,6 +236,7 @@ fn ensureHostMessageWakeupInitialized() bool {
|
|
|
236
236
|
}
|
|
237
237
|
|
|
238
238
|
fn signalHostMessageWakeup() void {
|
|
239
|
+
if (comptime builtin.os.tag == .windows) return;
|
|
239
240
|
if (!ensureHostMessageWakeupInitialized()) {
|
|
240
241
|
return;
|
|
241
242
|
}
|
|
@@ -837,7 +838,7 @@ fn startHostTransportServer(requested_port: u32) bool {
|
|
|
837
838
|
return false;
|
|
838
839
|
}
|
|
839
840
|
|
|
840
|
-
fn
|
|
841
|
+
fn buildSparkBunPreload(
|
|
841
842
|
webview_id: u32,
|
|
842
843
|
window_id: u32,
|
|
843
844
|
secret_key: [*:0]const u8,
|
|
@@ -851,10 +852,10 @@ fn buildElectrobunPreload(
|
|
|
851
852
|
const sandboxed_preload_script = webview_runtime_state.preload_script_sandboxed.?;
|
|
852
853
|
return std.fmt.allocPrintZ(
|
|
853
854
|
allocator,
|
|
854
|
-
\\window.
|
|
855
|
-
\\window.
|
|
856
|
-
\\window.
|
|
857
|
-
\\window.
|
|
855
|
+
\\window.__sparkbunWebviewId = {d};
|
|
856
|
+
\\window.__sparkbunWindowId = {d};
|
|
857
|
+
\\window.__sparkbunEventBridge = window.__sparkbunEventBridge || window.webkit?.messageHandlers?.eventBridge || window.eventBridge || window.chrome?.webview?.hostObjects?.eventBridge;
|
|
858
|
+
\\window.__sparkbunInternalBridge = window.__sparkbunInternalBridge || window.webkit?.messageHandlers?.internalBridge || window.internalBridge || window.chrome?.webview?.hostObjects?.internalBridge;
|
|
858
859
|
\\{s}
|
|
859
860
|
,
|
|
860
861
|
.{ webview_id, window_id, sandboxed_preload_script },
|
|
@@ -867,15 +868,15 @@ fn buildElectrobunPreload(
|
|
|
867
868
|
const preload_script = webview_runtime_state.preload_script.?;
|
|
868
869
|
return std.fmt.allocPrintZ(
|
|
869
870
|
allocator,
|
|
870
|
-
\\window.
|
|
871
|
-
\\window.
|
|
872
|
-
\\window.
|
|
873
|
-
\\window.
|
|
874
|
-
\\window.
|
|
875
|
-
\\window.
|
|
876
|
-
\\window.
|
|
877
|
-
\\window.
|
|
878
|
-
\\window.
|
|
871
|
+
\\window.__sparkbunWebviewId = {d};
|
|
872
|
+
\\window.__sparkbunWindowId = {d};
|
|
873
|
+
\\window.__sparkbunHostSocketPort = {d};
|
|
874
|
+
\\window.__sparkbunRpcSocketPort = {d};
|
|
875
|
+
\\window.__sparkbunSecretKeyBytes = [{s}];
|
|
876
|
+
\\window.__sparkbunEventBridge = window.__sparkbunEventBridge || window.webkit?.messageHandlers?.eventBridge || window.eventBridge || window.chrome?.webview?.hostObjects?.eventBridge;
|
|
877
|
+
\\window.__sparkbunInternalBridge = window.__sparkbunInternalBridge || window.webkit?.messageHandlers?.internalBridge || window.internalBridge || window.chrome?.webview?.hostObjects?.internalBridge;
|
|
878
|
+
\\window.__sparkbunHostBridge = window.__sparkbunHostBridge || window.__sparkbunBunBridge || window.webkit?.messageHandlers?.hostBridge || window.webkit?.messageHandlers?.bunBridge || window.hostBridge || window.bunBridge || window.chrome?.webview?.hostObjects?.hostBridge || window.chrome?.webview?.hostObjects?.bunBridge;
|
|
879
|
+
\\window.__sparkbunBunBridge = window.__sparkbunBunBridge || window.webkit?.messageHandlers?.bunBridge || window.bunBridge || window.chrome?.webview?.hostObjects?.bunBridge;
|
|
879
880
|
\\{s}
|
|
880
881
|
,
|
|
881
882
|
.{
|
|
@@ -1185,7 +1186,7 @@ fn buildHostWebviewEventJavascript(
|
|
|
1185
1186
|
const event_name_slice = std.mem.span(event_name);
|
|
1186
1187
|
if (std.mem.eql(u8, event_name_slice, "new-window-open") or std.mem.eql(u8, event_name_slice, "host-message")) {
|
|
1187
1188
|
return allocateOwnedJavascriptString(
|
|
1188
|
-
"document.querySelector('#
|
|
1189
|
+
"document.querySelector('#sparkbun-webview-{d}').emit({s}, {s});",
|
|
1189
1190
|
.{ webview_id, encoded_event_name, std.mem.span(detail) },
|
|
1190
1191
|
);
|
|
1191
1192
|
}
|
|
@@ -1194,14 +1195,14 @@ fn buildHostWebviewEventJavascript(
|
|
|
1194
1195
|
defer allocator.free(encoded_detail);
|
|
1195
1196
|
|
|
1196
1197
|
return allocateOwnedJavascriptString(
|
|
1197
|
-
"document.querySelector('#
|
|
1198
|
+
"document.querySelector('#sparkbun-webview-{d}').emit({s}, {s});",
|
|
1198
1199
|
.{ webview_id, encoded_event_name, encoded_detail },
|
|
1199
1200
|
);
|
|
1200
1201
|
}
|
|
1201
1202
|
|
|
1202
1203
|
fn buildInternalMessageJavascript(message_json: [*:0]const u8) ?[:0]u8 {
|
|
1203
1204
|
return allocateOwnedJavascriptString(
|
|
1204
|
-
"window.
|
|
1205
|
+
"window.__sparkbun.receiveInternalMessageFromHost({s});",
|
|
1205
1206
|
.{std.mem.span(message_json)},
|
|
1206
1207
|
);
|
|
1207
1208
|
}
|
|
@@ -1540,7 +1541,7 @@ fn handleInternalMessage(message_id: []const u8, payload: std.json.Value) void {
|
|
|
1540
1541
|
const preload = jsonString(payload_object.get("preload") orelse return) orelse return;
|
|
1541
1542
|
const preload_z = duplicateSentinelString(preload) orelse return;
|
|
1542
1543
|
defer allocator.free(preload_z);
|
|
1543
|
-
updatePreloadScriptToWebView(webview_id, "
|
|
1544
|
+
updatePreloadScriptToWebView(webview_id, "sparkbun_custom_preload_script", preload_z.ptr, true);
|
|
1544
1545
|
return;
|
|
1545
1546
|
}
|
|
1546
1547
|
|
|
@@ -1806,7 +1807,7 @@ fn managedQuitRequestedTrampoline() callconv(.C) void {
|
|
|
1806
1807
|
}
|
|
1807
1808
|
}
|
|
1808
1809
|
|
|
1809
|
-
export fn
|
|
1810
|
+
export fn sparkbun_core_run_main_thread(
|
|
1810
1811
|
identifier: [*:0]const u8,
|
|
1811
1812
|
name: [*:0]const u8,
|
|
1812
1813
|
channel: [*:0]const u8,
|
|
@@ -2293,7 +2294,7 @@ export fn createWebview(
|
|
|
2293
2294
|
};
|
|
2294
2295
|
webview_registry_mutex.unlock();
|
|
2295
2296
|
|
|
2296
|
-
const
|
|
2297
|
+
const sparkbun_preload_script = buildSparkBunPreload(
|
|
2297
2298
|
webview_id,
|
|
2298
2299
|
window_id,
|
|
2299
2300
|
secret_key,
|
|
@@ -2304,7 +2305,7 @@ export fn createWebview(
|
|
|
2304
2305
|
webview_registry_mutex.unlock();
|
|
2305
2306
|
return 0;
|
|
2306
2307
|
};
|
|
2307
|
-
defer allocator.free(
|
|
2308
|
+
defer allocator.free(sparkbun_preload_script);
|
|
2308
2309
|
|
|
2309
2310
|
set_next_webview_flags(start_transparent, start_passthrough);
|
|
2310
2311
|
|
|
@@ -2324,7 +2325,7 @@ export fn createWebview(
|
|
|
2324
2325
|
event_bridge_handler,
|
|
2325
2326
|
hostBridgeQueueTrampoline,
|
|
2326
2327
|
internalBridgeCoreTrampoline,
|
|
2327
|
-
|
|
2328
|
+
sparkbun_preload_script.ptr,
|
|
2328
2329
|
custom_preload_script,
|
|
2329
2330
|
views_root,
|
|
2330
2331
|
window_state.transparent,
|
|
@@ -119,7 +119,7 @@ async function createWindowsShortcuts(appDir: string, meta: Metadata) {
|
|
|
119
119
|
|
|
120
120
|
function fixPermissions(appDir: string) {
|
|
121
121
|
const exeBaseName = appDir.split("/").pop()?.replace(/ /g, "") || "app";
|
|
122
|
-
const executables = [`bin/${exeBaseName}
|
|
122
|
+
const executables = [`bin/${exeBaseName}`];
|
|
123
123
|
for (const exe of executables) {
|
|
124
124
|
const path = join(appDir, exe);
|
|
125
125
|
if (existsSync(path)) {
|
package/src/launcher/main.ts
CHANGED
|
@@ -8,8 +8,8 @@ const pathToMacOS = dirname(process.argv0);
|
|
|
8
8
|
process.chdir(pathToMacOS);
|
|
9
9
|
const coreLibFileName =
|
|
10
10
|
process.platform === "win32"
|
|
11
|
-
? "
|
|
12
|
-
: `
|
|
11
|
+
? "SparkBunCore.dll"
|
|
12
|
+
: `libSparkBunCore.${suffix}`;
|
|
13
13
|
const coreLibPath = join(pathToMacOS, coreLibFileName);
|
|
14
14
|
const absoluteCoreLibPath = resolve(coreLibPath);
|
|
15
15
|
|
|
@@ -148,28 +148,28 @@ function main() {
|
|
|
148
148
|
try {
|
|
149
149
|
|
|
150
150
|
lib = dlopen(coreLibPath, {
|
|
151
|
-
|
|
151
|
+
sparkbun_core_run_main_thread: {
|
|
152
152
|
args: ["cstring", "cstring", "cstring", "i32"],
|
|
153
153
|
returns: "i32",
|
|
154
154
|
},
|
|
155
|
-
|
|
155
|
+
sparkbun_core_last_error: {
|
|
156
156
|
args: [],
|
|
157
157
|
returns: "cstring",
|
|
158
158
|
},
|
|
159
159
|
});
|
|
160
160
|
} catch (error) {
|
|
161
161
|
console.error(
|
|
162
|
-
`[LAUNCHER] Failed to load
|
|
162
|
+
`[LAUNCHER] Failed to load SparkBunCore: ${(error as Error).message}`,
|
|
163
163
|
);
|
|
164
164
|
|
|
165
165
|
// Try with absolute path as fallback
|
|
166
166
|
try {
|
|
167
167
|
lib = dlopen(absoluteCoreLibPath, {
|
|
168
|
-
|
|
168
|
+
sparkbun_core_run_main_thread: {
|
|
169
169
|
args: ["cstring", "cstring", "cstring", "i32"],
|
|
170
170
|
returns: "i32",
|
|
171
171
|
},
|
|
172
|
-
|
|
172
|
+
sparkbun_core_last_error: {
|
|
173
173
|
args: [],
|
|
174
174
|
returns: "cstring",
|
|
175
175
|
},
|
|
@@ -201,7 +201,7 @@ function main() {
|
|
|
201
201
|
// preload: [''];
|
|
202
202
|
});
|
|
203
203
|
|
|
204
|
-
const runStatus = lib.symbols.
|
|
204
|
+
const runStatus = lib.symbols.sparkbun_core_run_main_thread(
|
|
205
205
|
ptr(new Uint8Array(Buffer.from(identifier + "\0", "utf8"))),
|
|
206
206
|
ptr(new Uint8Array(Buffer.from(name + "\0", "utf8"))),
|
|
207
207
|
ptr(new Uint8Array(Buffer.from(channel + "\0", "utf8"))),
|
|
@@ -209,9 +209,9 @@ function main() {
|
|
|
209
209
|
);
|
|
210
210
|
|
|
211
211
|
if (runStatus !== 0) {
|
|
212
|
-
const coreError = lib.symbols.
|
|
212
|
+
const coreError = lib.symbols.sparkbun_core_last_error();
|
|
213
213
|
console.error(
|
|
214
|
-
`[LAUNCHER]
|
|
214
|
+
`[LAUNCHER] SparkBunCore failed: ${coreError ? coreError.toString() : "Unknown error"}`,
|
|
215
215
|
);
|
|
216
216
|
process.exit(runStatus);
|
|
217
217
|
}
|
|
@@ -68,7 +68,7 @@ public:
|
|
|
68
68
|
CefRefPtr<CefV8Value> eventBridge = CefV8Value::CreateObject(nullptr, nullptr);
|
|
69
69
|
CefRefPtr<CefV8Value> eventPostMessage = CreatePostMessageFunction(browser, "EventBridgeMessage");
|
|
70
70
|
eventBridge->SetValue("postMessage", eventPostMessage, V8_PROPERTY_ATTRIBUTE_NONE);
|
|
71
|
-
window->SetValue("
|
|
71
|
+
window->SetValue("__sparkbunEventBridge", eventBridge, V8_PROPERTY_ATTRIBUTE_NONE);
|
|
72
72
|
|
|
73
73
|
// Only create hostBridge/bunBridge aliases and internalBridge for non-sandboxed webviews
|
|
74
74
|
if (!is_sandboxed) {
|
|
@@ -76,14 +76,14 @@ public:
|
|
|
76
76
|
CefRefPtr<CefV8Value> bunBridge = CefV8Value::CreateObject(nullptr, nullptr);
|
|
77
77
|
CefRefPtr<CefV8Value> bunPostMessage = CreatePostMessageFunction(browser, "BunBridgeMessage");
|
|
78
78
|
bunBridge->SetValue("postMessage", bunPostMessage, V8_PROPERTY_ATTRIBUTE_NONE);
|
|
79
|
-
window->SetValue("
|
|
80
|
-
window->SetValue("
|
|
79
|
+
window->SetValue("__sparkbunHostBridge", bunBridge, V8_PROPERTY_ATTRIBUTE_NONE);
|
|
80
|
+
window->SetValue("__sparkbunBunBridge", bunBridge, V8_PROPERTY_ATTRIBUTE_NONE);
|
|
81
81
|
|
|
82
82
|
// Create internalBridge - internal RPC bridge
|
|
83
83
|
CefRefPtr<CefV8Value> internalBridge = CefV8Value::CreateObject(nullptr, nullptr);
|
|
84
84
|
CefRefPtr<CefV8Value> internalPostMessage = CreatePostMessageFunction(browser, "internalMessage");
|
|
85
85
|
internalBridge->SetValue("postMessage", internalPostMessage, V8_PROPERTY_ATTRIBUTE_NONE);
|
|
86
|
-
window->SetValue("
|
|
86
|
+
window->SetValue("__sparkbunInternalBridge", internalBridge, V8_PROPERTY_ATTRIBUTE_NONE);
|
|
87
87
|
}
|
|
88
88
|
|
|
89
89
|
v8Context->Exit();
|