sparkbun 0.1.5 → 0.1.7
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 +18 -53
- 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-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",
|
|
@@ -166,10 +163,7 @@ async function ensureCoreDependencies(
|
|
|
166
163
|
|
|
167
164
|
// Check platform-specific binaries
|
|
168
165
|
// BUN_BINARY not required — SparkBun compiles the launcher via bun build --compile
|
|
169
|
-
const requiredBinaries = [
|
|
170
|
-
platformPaths.BSDIFF,
|
|
171
|
-
platformPaths.BSPATCH,
|
|
172
|
-
];
|
|
166
|
+
const requiredBinaries: string[] = [];
|
|
173
167
|
if (platformOS === "macos") {
|
|
174
168
|
requiredBinaries.push(
|
|
175
169
|
platformPaths.NATIVE_WRAPPER_MACOS,
|
|
@@ -2138,7 +2132,7 @@ usageDescriptions : ""}${urlTypes ? "\n" + urlTypes : ""}${documentTypes ?
|
|
|
2138
2132
|
|
|
2139
2133
|
// copy native wrapper dynamic library
|
|
2140
2134
|
if (targetOS === "macos") {
|
|
2141
|
-
cpSync(targetPaths.CORE_MACOS, join(appBundleMacOSPath, "
|
|
2135
|
+
cpSync(targetPaths.CORE_MACOS, join(appBundleMacOSPath, "libSparkBunCore.dylib"), {
|
|
2142
2136
|
dereference: true,
|
|
2143
2137
|
});
|
|
2144
2138
|
|
|
@@ -2151,7 +2145,7 @@ usageDescriptions : ""}${urlTypes ? "\n" + urlTypes : ""}${documentTypes ?
|
|
|
2151
2145
|
dereference: true,
|
|
2152
2146
|
});
|
|
2153
2147
|
} else if (targetOS === "win") {
|
|
2154
|
-
cpSync(targetPaths.CORE_WIN, join(appBundleMacOSPath, "
|
|
2148
|
+
cpSync(targetPaths.CORE_WIN, join(appBundleMacOSPath, "SparkBunCore.dll"), {
|
|
2155
2149
|
dereference: true,
|
|
2156
2150
|
});
|
|
2157
2151
|
|
|
@@ -2174,7 +2168,7 @@ usageDescriptions : ""}${urlTypes ? "\n" + urlTypes : ""}${documentTypes ?
|
|
|
2174
2168
|
} else if (targetOS === "linux") {
|
|
2175
2169
|
// Choose the appropriate native wrapper based on bundleCEF setting
|
|
2176
2170
|
const useCEF = config.build.linux?.bundleCEF;
|
|
2177
|
-
cpSync(targetPaths.CORE_LINUX, join(appBundleMacOSPath, "
|
|
2171
|
+
cpSync(targetPaths.CORE_LINUX, join(appBundleMacOSPath, "libSparkBunCore.so"), {
|
|
2178
2172
|
dereference: true,
|
|
2179
2173
|
});
|
|
2180
2174
|
const nativeWrapperLinuxSource = useCEF
|
|
@@ -2551,21 +2545,7 @@ usageDescriptions : ""}${urlTypes ? "\n" + urlTypes : ""}${documentTypes ?
|
|
|
2551
2545
|
}
|
|
2552
2546
|
}
|
|
2553
2547
|
|
|
2554
|
-
//
|
|
2555
|
-
const bsPatchSource = targetPaths.BSPATCH;
|
|
2556
|
-
const bsPatchDestination =
|
|
2557
|
-
join(appBundleMacOSPath, "bspatch") + targetBinExt;
|
|
2558
|
-
const bsPatchDestFolder = dirname(bsPatchDestination);
|
|
2559
|
-
if (!existsSync(bsPatchDestFolder)) {
|
|
2560
|
-
mkdirSync(bsPatchDestFolder, { recursive: true });
|
|
2561
|
-
}
|
|
2562
|
-
|
|
2563
|
-
cpSync(bsPatchSource, bsPatchDestination, {
|
|
2564
|
-
recursive: true,
|
|
2565
|
-
dereference: true,
|
|
2566
|
-
});
|
|
2567
|
-
|
|
2568
|
-
// libasar is still loaded by ElectrobunCore at runtime — needed until
|
|
2548
|
+
// libasar is still loaded by SparkBunCore at runtime — needed until
|
|
2569
2549
|
// native wrappers are recompiled without ASAR support
|
|
2570
2550
|
const libExt = targetOS === "win" ? ".dll" : targetOS === "macos" ? ".dylib" : ".so";
|
|
2571
2551
|
const asarLibSource = join(dirname(targetPaths.BSPATCH), "libasar" + libExt);
|
|
@@ -2941,39 +2921,25 @@ usageDescriptions : ""}${urlTypes ? "\n" + urlTypes : ""}${documentTypes ?
|
|
|
2941
2921
|
|
|
2942
2922
|
if (canGeneratePatch) {
|
|
2943
2923
|
console.log("diff previous and new tarballs...");
|
|
2944
|
-
// Run it as a separate process to leverage multi-threadedness
|
|
2945
|
-
// especially for creating multiple diffs in parallel
|
|
2946
|
-
const bsdiffpath = targetPaths.BSDIFF;
|
|
2947
2924
|
const patchFilePath = join(buildFolder, `${prevHash}.patch`);
|
|
2948
|
-
|
|
2949
|
-
|
|
2950
|
-
|
|
2951
|
-
|
|
2952
|
-
|
|
2953
|
-
|
|
2954
|
-
|
|
2955
|
-
|
|
2956
|
-
cwd: buildFolder,
|
|
2957
|
-
stdout: "inherit",
|
|
2958
|
-
stderr: "inherit",
|
|
2959
|
-
},
|
|
2960
|
-
);
|
|
2961
|
-
if (!result.success) {
|
|
2962
|
-
// Patch generation is non-critical - users will just download full updates instead of delta patches
|
|
2925
|
+
try {
|
|
2926
|
+
const { createPatch } = await import("../shared/bsdiff.ts");
|
|
2927
|
+
const oldData = new Uint8Array(await Bun.file(prevTarballPath).arrayBuffer());
|
|
2928
|
+
const newData = new Uint8Array(await Bun.file(tarPath).arrayBuffer());
|
|
2929
|
+
const patch = createPatch(oldData, newData);
|
|
2930
|
+
await Bun.write(patchFilePath, patch);
|
|
2931
|
+
artifactsToUpload.push(patchFilePath);
|
|
2932
|
+
} catch (error) {
|
|
2963
2933
|
console.error("\n" + "=".repeat(80));
|
|
2964
2934
|
console.error(
|
|
2965
|
-
"WARNING: Patch generation failed
|
|
2966
|
-
|
|
2967
|
-
")",
|
|
2935
|
+
"WARNING: Patch generation failed: " +
|
|
2936
|
+
(error as Error).message,
|
|
2968
2937
|
);
|
|
2969
2938
|
console.error(
|
|
2970
2939
|
"Delta updates will not be available for this release.",
|
|
2971
2940
|
);
|
|
2972
2941
|
console.error("Users will download the full update instead.");
|
|
2973
2942
|
console.error("=".repeat(80) + "\n");
|
|
2974
|
-
} else {
|
|
2975
|
-
// Only add patch to artifacts if it was successfully created
|
|
2976
|
-
artifactsToUpload.push(patchFilePath);
|
|
2977
2943
|
}
|
|
2978
2944
|
|
|
2979
2945
|
// Clean up previous tarball now that bsdiff is done
|
|
@@ -4208,7 +4174,6 @@ Description: ${shortDesc}${longDesc}
|
|
|
4208
4174
|
// postinst
|
|
4209
4175
|
writeFileSync(join(controlDir, "postinst"), `#!/bin/sh
|
|
4210
4176
|
chmod +x ${installDir}/bin/${exeName}
|
|
4211
|
-
chmod +x ${installDir}/bin/bspatch 2>/dev/null || true
|
|
4212
4177
|
gtk-update-icon-cache -f -t /usr/share/icons/hicolor 2>/dev/null || true
|
|
4213
4178
|
update-desktop-database /usr/share/applications 2>/dev/null || true
|
|
4214
4179
|
`);
|
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();
|