sparkbun 0.1.5 → 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 +17 -49
- 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
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
static bool wgpuDebugEnabled() {
|
|
21
21
|
static int cached = -1;
|
|
22
22
|
if (cached >= 0) return cached == 1;
|
|
23
|
-
const char* val = getenv("
|
|
23
|
+
const char* val = getenv("SPARKBUN_WGPU_DEBUG");
|
|
24
24
|
cached = (val && strcmp(val, "1") == 0) ? 1 : 0;
|
|
25
25
|
return cached == 1;
|
|
26
26
|
}
|
|
@@ -81,7 +81,7 @@ static bool wgpuDebugEnabled() {
|
|
|
81
81
|
#include "../shared/chromium_flags.h"
|
|
82
82
|
#include "../shared/cache_migration.h"
|
|
83
83
|
|
|
84
|
-
using namespace
|
|
84
|
+
using namespace sparkbun;
|
|
85
85
|
|
|
86
86
|
/*
|
|
87
87
|
* =============================================================================
|
|
@@ -96,8 +96,8 @@ static std::once_flag g_asarArchiveInitFlag;
|
|
|
96
96
|
|
|
97
97
|
CGFloat OFFSCREEN_OFFSET = -20000;
|
|
98
98
|
BOOL useCEF = false;
|
|
99
|
-
std::string
|
|
100
|
-
std::string
|
|
99
|
+
std::string g_sparkbunChannel = "";
|
|
100
|
+
std::string g_sparkbunIdentifier = "";
|
|
101
101
|
|
|
102
102
|
static BOOL isMovingWindow = NO;
|
|
103
103
|
static NSWindow *targetWindow = nil;
|
|
@@ -109,7 +109,7 @@ static id mouseUpMonitor = nil;
|
|
|
109
109
|
static int g_remoteDebugPort = 9222;
|
|
110
110
|
|
|
111
111
|
// Menu role to selector mapping
|
|
112
|
-
// This maps
|
|
112
|
+
// This maps SparkBun role strings to their corresponding Objective-C selectors.
|
|
113
113
|
// Roles are grouped by category for easier maintenance.
|
|
114
114
|
static NSDictionary<NSString*, NSString*>* getMenuRoleToSelectorMap() {
|
|
115
115
|
static NSDictionary<NSString*, NSString*>* map = nil;
|
|
@@ -317,9 +317,9 @@ class CefApp;
|
|
|
317
317
|
class CefClient;
|
|
318
318
|
class CefLifeSpanHandler;
|
|
319
319
|
class CefBrowser;
|
|
320
|
-
class
|
|
321
|
-
class
|
|
322
|
-
class
|
|
320
|
+
class SparkBunSchemeHandler;
|
|
321
|
+
class SparkBunSchemeHandlerFactory;
|
|
322
|
+
class SparkBunClient;
|
|
323
323
|
|
|
324
324
|
typedef void (*RemoteDevToolsClosedCallback)(void* ctx, int target_id);
|
|
325
325
|
void RemoteDevToolsClosed(void* ctx, int target_id);
|
|
@@ -976,7 +976,7 @@ static NSMutableDictionary<NSNumber *, AbstractView *> *globalAbstractViews = ni
|
|
|
976
976
|
eventBridgeHandler:(HandlePostMessage)eventBridgeHandler
|
|
977
977
|
bunBridgeHandler:(HandlePostMessage)bunBridgeHandler
|
|
978
978
|
internalBridgeHandler:(HandlePostMessage)internalBridgeHandler
|
|
979
|
-
|
|
979
|
+
sparkbunPreloadScript:(const char *)sparkbunPreloadScript
|
|
980
980
|
customPreloadScript:(const char *)customPreloadScript
|
|
981
981
|
viewsRoot:(const char *)viewsRoot
|
|
982
982
|
transparent:(bool)transparent
|
|
@@ -994,7 +994,7 @@ static NSMutableDictionary<NSNumber *, AbstractView *> *globalAbstractViews = ni
|
|
|
994
994
|
|
|
995
995
|
// ----------------------- Application & Window Delegates -----------------------
|
|
996
996
|
|
|
997
|
-
@interface
|
|
997
|
+
@interface SparkBunNSApplication : NSApplication <CefAppProtocol> {
|
|
998
998
|
@private
|
|
999
999
|
BOOL handlingSendEvent_;
|
|
1000
1000
|
}
|
|
@@ -1084,7 +1084,7 @@ static NSString *keyEquivalentFromString(NSString *key) {
|
|
|
1084
1084
|
|
|
1085
1085
|
// Convert shared AcceleratorParts to macOS NSEventModifierFlags.
|
|
1086
1086
|
// On macOS, CommandOrControl and Command both map to the Command key.
|
|
1087
|
-
static NSEventModifierFlags modifierFlagsFromAccelerator(const
|
|
1087
|
+
static NSEventModifierFlags modifierFlagsFromAccelerator(const sparkbun::AcceleratorParts& parts) {
|
|
1088
1088
|
NSEventModifierFlags flags = 0;
|
|
1089
1089
|
if (parts.commandOrControl || parts.command) flags |= NSEventModifierFlagCommand;
|
|
1090
1090
|
if (parts.control) flags |= NSEventModifierFlagControl;
|
|
@@ -1099,7 +1099,7 @@ static NSEventModifierFlags modifierFlagsFromAccelerator(const electrobun::Accel
|
|
|
1099
1099
|
static void parseMenuAccelerator(NSString *accelerator,
|
|
1100
1100
|
NSString **outKeyEquivalent,
|
|
1101
1101
|
NSEventModifierFlags *outModifiers) {
|
|
1102
|
-
auto parts =
|
|
1102
|
+
auto parts = sparkbun::parseAccelerator([accelerator UTF8String]);
|
|
1103
1103
|
|
|
1104
1104
|
*outModifiers = modifierFlagsFromAccelerator(parts);
|
|
1105
1105
|
|
|
@@ -1271,7 +1271,7 @@ NSArray<NSValue *> *addOverlapRects(NSArray<NSDictionary *> *rectsArray, CGFloat
|
|
|
1271
1271
|
|
|
1272
1272
|
- (void)evaluateJavaScriptWithNoCompletion:(const char*)jsString { [self doesNotRecognizeSelector:_cmd]; }
|
|
1273
1273
|
- (void)callAsyncJavascript:(const char*)messageId jsString:(const char*)jsString webviewId:(uint32_t)webviewId hostWebviewId:(uint32_t)hostWebviewId completionHandler:(callAsyncJavascriptCompletionHandler)completionHandler { [self doesNotRecognizeSelector:_cmd]; }
|
|
1274
|
-
// todo: we don't need this to be public since it's only used to set the internal
|
|
1274
|
+
// todo: we don't need this to be public since it's only used to set the internal sparkbun preview script
|
|
1275
1275
|
- (void)addPreloadScriptToWebView:(const char*)jsString { [self doesNotRecognizeSelector:_cmd]; }
|
|
1276
1276
|
- (void)updateCustomPreloadScript:(const char*)jsString { [self doesNotRecognizeSelector:_cmd]; }
|
|
1277
1277
|
|
|
@@ -1442,7 +1442,7 @@ NSArray<NSValue *> *addOverlapRects(NSArray<NSDictionary *> *rectsArray, CGFloat
|
|
|
1442
1442
|
NSString *pattern = isBlockRule ? [rule substringFromIndex:1] : rule;
|
|
1443
1443
|
std::string patternStr = [pattern UTF8String] ?: "";
|
|
1444
1444
|
|
|
1445
|
-
if (
|
|
1445
|
+
if (sparkbun::globMatch(patternStr, urlStr)) {
|
|
1446
1446
|
allowed = !isBlockRule; // Last match wins
|
|
1447
1447
|
}
|
|
1448
1448
|
}
|
|
@@ -2548,7 +2548,7 @@ runOpenPanelWithParameters:(WKOpenPanelParameters *)parameters
|
|
|
2548
2548
|
eventBridgeHandler:(HandlePostMessage)eventBridgeHandler
|
|
2549
2549
|
bunBridgeHandler:(HandlePostMessage)bunBridgeHandler
|
|
2550
2550
|
internalBridgeHandler:(HandlePostMessage)internalBridgeHandler
|
|
2551
|
-
|
|
2551
|
+
sparkbunPreloadScript:(const char *)sparkbunPreloadScript
|
|
2552
2552
|
customPreloadScript:(const char *)customPreloadScript
|
|
2553
2553
|
viewsRoot:(const char *)viewsRoot
|
|
2554
2554
|
transparent:(bool)transparent
|
|
@@ -2691,7 +2691,7 @@ runOpenPanelWithParameters:(WKOpenPanelParameters *)parameters
|
|
|
2691
2691
|
[self setPassthrough:YES];
|
|
2692
2692
|
}
|
|
2693
2693
|
|
|
2694
|
-
[self addPreloadScriptToWebView:
|
|
2694
|
+
[self addPreloadScriptToWebView:sparkbunPreloadScript];
|
|
2695
2695
|
|
|
2696
2696
|
// Note: For custom preload scripts we support either inline js or a views:// style
|
|
2697
2697
|
// url to a js file in the bundled views folder.
|
|
@@ -2908,7 +2908,7 @@ runOpenPanelWithParameters:(WKOpenPanelParameters *)parameters
|
|
|
2908
2908
|
|
|
2909
2909
|
- (void)updateCustomPreloadScript:(const char*)jsString {
|
|
2910
2910
|
WKUserContentController *contentController = self.webView.configuration.userContentController;
|
|
2911
|
-
NSString *identifierComment = [NSString stringWithFormat:@"// %@\n", [NSString stringWithUTF8String:"
|
|
2911
|
+
NSString *identifierComment = [NSString stringWithFormat:@"// %@\n", [NSString stringWithUTF8String:"sparkbun_custom_preload_script"]];
|
|
2912
2912
|
NSString *newScriptSource = [identifierComment stringByAppendingString:[NSString stringWithUTF8String:jsString ?: ""]];
|
|
2913
2913
|
NSMutableArray *newScripts = [NSMutableArray array];
|
|
2914
2914
|
for (WKUserScript *userScript in contentController.userScripts) {
|
|
@@ -4247,7 +4247,7 @@ static void requestDeviceCallback(WGPURequestDeviceStatus status, WGPUDevice dev
|
|
|
4247
4247
|
}
|
|
4248
4248
|
state->device = device;
|
|
4249
4249
|
if (p_wgpuDeviceSetLabel) {
|
|
4250
|
-
WGPUStringView label = { "
|
|
4250
|
+
WGPUStringView label = { "SparkBun WGPU Device", WGPU_STRLEN };
|
|
4251
4251
|
p_wgpuDeviceSetLabel(device, label);
|
|
4252
4252
|
}
|
|
4253
4253
|
state->queue = p_wgpuDeviceGetQueue(device);
|
|
@@ -4319,7 +4319,7 @@ extern "C" void wgpuToggleGPUTestShader(AbstractView* abstractView) {
|
|
|
4319
4319
|
|
|
4320
4320
|
// ----------------------- CEF and NSApplication Setup (C++ and ObjC) -----------------------
|
|
4321
4321
|
|
|
4322
|
-
@implementation
|
|
4322
|
+
@implementation SparkBunNSApplication
|
|
4323
4323
|
- (BOOL)isHandlingSendEvent {
|
|
4324
4324
|
return handlingSendEvent_;
|
|
4325
4325
|
}
|
|
@@ -4359,19 +4359,19 @@ extern "C" void wgpuToggleGPUTestShader(AbstractView* abstractView) {
|
|
|
4359
4359
|
// C++ classes for CEF:
|
|
4360
4360
|
|
|
4361
4361
|
|
|
4362
|
-
class
|
|
4362
|
+
class SparkBunHandler : public CefClient,
|
|
4363
4363
|
public CefDisplayHandler,
|
|
4364
4364
|
public CefLifeSpanHandler,
|
|
4365
4365
|
public CefLoadHandler {
|
|
4366
4366
|
public:
|
|
4367
|
-
static
|
|
4367
|
+
static SparkBunHandler* GetInstance() {
|
|
4368
4368
|
return g_instance;
|
|
4369
4369
|
}
|
|
4370
|
-
|
|
4370
|
+
SparkBunHandler() {
|
|
4371
4371
|
DCHECK(!g_instance);
|
|
4372
4372
|
g_instance = this;
|
|
4373
4373
|
}
|
|
4374
|
-
~
|
|
4374
|
+
~SparkBunHandler() {
|
|
4375
4375
|
g_instance = nullptr;
|
|
4376
4376
|
}
|
|
4377
4377
|
|
|
@@ -4404,41 +4404,41 @@ public:
|
|
|
4404
4404
|
}
|
|
4405
4405
|
|
|
4406
4406
|
private:
|
|
4407
|
-
static
|
|
4407
|
+
static SparkBunHandler* g_instance;
|
|
4408
4408
|
typedef std::list<CefRefPtr<CefBrowser>> BrowserList;
|
|
4409
4409
|
BrowserList browser_list_;
|
|
4410
4410
|
bool is_closing_ = false;
|
|
4411
4411
|
|
|
4412
|
-
IMPLEMENT_REFCOUNTING(
|
|
4413
|
-
DISALLOW_COPY_AND_ASSIGN(
|
|
4412
|
+
IMPLEMENT_REFCOUNTING(SparkBunHandler);
|
|
4413
|
+
DISALLOW_COPY_AND_ASSIGN(SparkBunHandler);
|
|
4414
4414
|
};
|
|
4415
4415
|
|
|
4416
|
-
|
|
4416
|
+
SparkBunHandler* SparkBunHandler::g_instance = nullptr;
|
|
4417
4417
|
|
|
4418
|
-
|
|
4418
|
+
sparkbun::ChromiumFlagConfig g_userChromiumFlags;
|
|
4419
4419
|
|
|
4420
|
-
class
|
|
4420
|
+
class SparkBunApp : public CefApp,
|
|
4421
4421
|
public CefBrowserProcessHandler,
|
|
4422
4422
|
public CefRenderProcessHandler {
|
|
4423
4423
|
public:
|
|
4424
|
-
|
|
4424
|
+
SparkBunApp() {
|
|
4425
4425
|
|
|
4426
4426
|
}
|
|
4427
4427
|
void OnBeforeCommandLineProcessing(const CefString& process_type, CefRefPtr<CefCommandLine> command_line) override {
|
|
4428
4428
|
command_line->AppendSwitchWithValue("custom-scheme", "views");
|
|
4429
4429
|
|
|
4430
4430
|
// macOS default flags — can be overridden via chromiumFlags in config
|
|
4431
|
-
static const std::vector<
|
|
4431
|
+
static const std::vector<sparkbun::DefaultFlag> defaults = {
|
|
4432
4432
|
{"use-mock-keychain", ""},
|
|
4433
4433
|
{"enable-features=PictureInPicture", ""},
|
|
4434
4434
|
{"enable-fullscreen", ""},
|
|
4435
4435
|
{"remote-allow-origins", "*"},
|
|
4436
4436
|
{"allow-insecure-localhost", ""},
|
|
4437
4437
|
};
|
|
4438
|
-
|
|
4438
|
+
sparkbun::applyDefaultFlags(defaults, g_userChromiumFlags.skip, command_line);
|
|
4439
4439
|
|
|
4440
4440
|
// Apply user-defined chromium flags from build.json
|
|
4441
|
-
|
|
4441
|
+
sparkbun::applyChromiumFlags(g_userChromiumFlags, command_line);
|
|
4442
4442
|
}
|
|
4443
4443
|
void OnRegisterCustomSchemes(CefRawPtr<CefSchemeRegistrar> registrar) override {
|
|
4444
4444
|
registrar->AddCustomScheme("views",
|
|
@@ -4479,30 +4479,30 @@ public:
|
|
|
4479
4479
|
// CefRegisterSchemeHandlerFactory("views", "", nullptr);
|
|
4480
4480
|
}
|
|
4481
4481
|
CefRefPtr<CefClient> GetDefaultClient() override {
|
|
4482
|
-
return
|
|
4482
|
+
return SparkBunHandler::GetInstance();
|
|
4483
4483
|
}
|
|
4484
4484
|
|
|
4485
4485
|
private:
|
|
4486
|
-
IMPLEMENT_REFCOUNTING(
|
|
4487
|
-
DISALLOW_COPY_AND_ASSIGN(
|
|
4486
|
+
IMPLEMENT_REFCOUNTING(SparkBunApp);
|
|
4487
|
+
DISALLOW_COPY_AND_ASSIGN(SparkBunApp);
|
|
4488
4488
|
};
|
|
4489
4489
|
|
|
4490
4490
|
// PreloadScript struct is now defined in shared/preload_script.h
|
|
4491
4491
|
|
|
4492
|
-
class
|
|
4492
|
+
class SparkBunResponseFilter : public CefResponseFilter {
|
|
4493
4493
|
private:
|
|
4494
4494
|
std::string buffer_;
|
|
4495
4495
|
bool has_head_;
|
|
4496
4496
|
bool injected_;
|
|
4497
|
-
PreloadScript
|
|
4497
|
+
PreloadScript sparkbun_script_;
|
|
4498
4498
|
PreloadScript custom_script_;
|
|
4499
4499
|
|
|
4500
4500
|
public:
|
|
4501
|
-
|
|
4501
|
+
SparkBunResponseFilter(const PreloadScript& sparkbunScript,
|
|
4502
4502
|
const PreloadScript& customScript)
|
|
4503
4503
|
: has_head_(false),
|
|
4504
4504
|
injected_(false),
|
|
4505
|
-
|
|
4505
|
+
sparkbun_script_(sparkbunScript),
|
|
4506
4506
|
custom_script_(customScript) {}
|
|
4507
4507
|
|
|
4508
4508
|
virtual FilterStatus Filter(void* data_in,
|
|
@@ -4513,7 +4513,7 @@ public:
|
|
|
4513
4513
|
size_t& data_out_written) override {
|
|
4514
4514
|
|
|
4515
4515
|
// Check if we have scripts to inject
|
|
4516
|
-
if (
|
|
4516
|
+
if (sparkbun_script_.code.empty() && custom_script_.code.empty()) {
|
|
4517
4517
|
// Nothing to inject, just copy the data
|
|
4518
4518
|
size_t copy_size = std::min(data_in_size, data_out_size);
|
|
4519
4519
|
memcpy(data_out, data_in, copy_size);
|
|
@@ -4550,7 +4550,7 @@ public:
|
|
|
4550
4550
|
|
|
4551
4551
|
// Inject our scripts after the <head> tag
|
|
4552
4552
|
std::string scripts = "<script>\n";
|
|
4553
|
-
scripts +=
|
|
4553
|
+
scripts += sparkbun_script_.code;
|
|
4554
4554
|
scripts += "\n</script>\n";
|
|
4555
4555
|
|
|
4556
4556
|
if (!custom_script_.code.empty()) {
|
|
@@ -4571,7 +4571,7 @@ public:
|
|
|
4571
4571
|
if (html_pos != std::string::npos) {
|
|
4572
4572
|
// Inject after <html> tag
|
|
4573
4573
|
std::string scripts = "<head>\n<script>\n";
|
|
4574
|
-
scripts +=
|
|
4574
|
+
scripts += sparkbun_script_.code;
|
|
4575
4575
|
scripts += "\n</script>\n";
|
|
4576
4576
|
|
|
4577
4577
|
if (!custom_script_.code.empty() ) {
|
|
@@ -4586,7 +4586,7 @@ public:
|
|
|
4586
4586
|
} else {
|
|
4587
4587
|
// As a last resort, inject at the beginning
|
|
4588
4588
|
std::string scripts = "<script>\n";
|
|
4589
|
-
scripts +=
|
|
4589
|
+
scripts += sparkbun_script_.code;
|
|
4590
4590
|
scripts += "\n</script>\n";
|
|
4591
4591
|
|
|
4592
4592
|
if (!custom_script_.code.empty() ) {
|
|
@@ -4618,12 +4618,12 @@ public:
|
|
|
4618
4618
|
return true;
|
|
4619
4619
|
}
|
|
4620
4620
|
|
|
4621
|
-
IMPLEMENT_REFCOUNTING(
|
|
4621
|
+
IMPLEMENT_REFCOUNTING(SparkBunResponseFilter);
|
|
4622
4622
|
};
|
|
4623
4623
|
|
|
4624
|
-
CefRefPtr<
|
|
4624
|
+
CefRefPtr<SparkBunApp> g_app;
|
|
4625
4625
|
|
|
4626
|
-
class
|
|
4626
|
+
class SparkBunClient : public CefClient,
|
|
4627
4627
|
public CefRenderHandler,
|
|
4628
4628
|
public CefLoadHandler,
|
|
4629
4629
|
public CefRequestHandler,
|
|
@@ -4649,7 +4649,7 @@ private:
|
|
|
4649
4649
|
int view_height_ = 600;
|
|
4650
4650
|
bool osr_enabled_ = false;
|
|
4651
4651
|
|
|
4652
|
-
PreloadScript
|
|
4652
|
+
PreloadScript sparkbun_script_;
|
|
4653
4653
|
PreloadScript custom_script_;
|
|
4654
4654
|
static const int MENU_ID_DEV_TOOLS = 1;
|
|
4655
4655
|
|
|
@@ -4901,7 +4901,7 @@ public:
|
|
|
4901
4901
|
}
|
|
4902
4902
|
}
|
|
4903
4903
|
|
|
4904
|
-
|
|
4904
|
+
SparkBunClient(uint32_t webviewId,
|
|
4905
4905
|
HandlePostMessage eventBridgeHandler,
|
|
4906
4906
|
HandlePostMessage bunBridgeHandler,
|
|
4907
4907
|
HandlePostMessage internalBridgeHandler,
|
|
@@ -4917,7 +4917,7 @@ public:
|
|
|
4917
4917
|
, is_sandboxed_(sandbox) {}
|
|
4918
4918
|
|
|
4919
4919
|
void AddPreloadScript(const std::string& script, bool mainFrameOnly = false) {
|
|
4920
|
-
|
|
4920
|
+
sparkbun_script_ = {script, false};
|
|
4921
4921
|
}
|
|
4922
4922
|
|
|
4923
4923
|
void UpdateCustomPreloadScript(const std::string& script) {
|
|
@@ -5213,7 +5213,7 @@ public:
|
|
|
5213
5213
|
if (frame->IsMain() &&
|
|
5214
5214
|
response->GetMimeType().ToString().find("html") != std::string::npos) {
|
|
5215
5215
|
NSLog(@"Creating response filter for HTML content");
|
|
5216
|
-
return new
|
|
5216
|
+
return new SparkBunResponseFilter(sparkbun_script_, custom_script_);
|
|
5217
5217
|
}
|
|
5218
5218
|
|
|
5219
5219
|
return nullptr;
|
|
@@ -5226,7 +5226,7 @@ public:
|
|
|
5226
5226
|
std::string frameUrl = frame->GetURL().ToString();
|
|
5227
5227
|
std::string scriptUrl = GetScriptExecutionUrl(frameUrl);
|
|
5228
5228
|
|
|
5229
|
-
// NSLog(@"OnLoadStart %s", frameUrl.c_str());//,
|
|
5229
|
+
// NSLog(@"OnLoadStart %s", frameUrl.c_str());//, sparkbun_script_.code.c_str());
|
|
5230
5230
|
}
|
|
5231
5231
|
|
|
5232
5232
|
void OnLoadEnd(CefRefPtr<CefBrowser> browser,
|
|
@@ -5312,7 +5312,7 @@ public:
|
|
|
5312
5312
|
OpenRemoteDevToolsFrontend(browser);
|
|
5313
5313
|
|
|
5314
5314
|
CefPoint inspect_at(params->GetXCoord(), params->GetYCoord());
|
|
5315
|
-
CefRefPtr<
|
|
5315
|
+
CefRefPtr<SparkBunClient> self(this);
|
|
5316
5316
|
CefRefPtr<CefBrowser> browser_ref(browser);
|
|
5317
5317
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
5318
5318
|
// Disabled for now due to crash in CEF 144 on macOS.
|
|
@@ -5389,7 +5389,7 @@ public:
|
|
|
5389
5389
|
(event.modifiers & EVENTFLAG_COMMAND_DOWN) &&
|
|
5390
5390
|
(event.modifiers & EVENTFLAG_ALT_DOWN)) {
|
|
5391
5391
|
CefPoint inspect_at(0, 0);
|
|
5392
|
-
CefRefPtr<
|
|
5392
|
+
CefRefPtr<SparkBunClient> self(this);
|
|
5393
5393
|
CefRefPtr<CefBrowser> browser_ref(browser);
|
|
5394
5394
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
5395
5395
|
self->ShowDevToolsWindow(browser_ref, inspect_at);
|
|
@@ -5506,7 +5506,7 @@ public:
|
|
|
5506
5506
|
} else {
|
|
5507
5507
|
// Unrecognized permission type — name what's being requested instead of
|
|
5508
5508
|
// a generic "additional permissions" dialog so the user can decide.
|
|
5509
|
-
std::string names =
|
|
5509
|
+
std::string names = sparkbun::describeCefPermissions(requested_permissions);
|
|
5510
5510
|
message = [NSString stringWithFormat:
|
|
5511
5511
|
@"This page is requesting permission for: %s.\n\nDo you want to allow this?",
|
|
5512
5512
|
names.c_str()];
|
|
@@ -5765,25 +5765,25 @@ public:
|
|
|
5765
5765
|
}
|
|
5766
5766
|
}
|
|
5767
5767
|
|
|
5768
|
-
IMPLEMENT_REFCOUNTING(
|
|
5769
|
-
DISALLOW_COPY_AND_ASSIGN(
|
|
5768
|
+
IMPLEMENT_REFCOUNTING(SparkBunClient);
|
|
5769
|
+
DISALLOW_COPY_AND_ASSIGN(SparkBunClient);
|
|
5770
5770
|
};
|
|
5771
5771
|
|
|
5772
5772
|
// Initialize static debounce timestamp for cmd+click handling
|
|
5773
|
-
NSTimeInterval
|
|
5773
|
+
NSTimeInterval SparkBunClient::lastCmdClickTime = 0;
|
|
5774
5774
|
|
|
5775
5775
|
void RemoteDevToolsClosed(void* ctx, int target_id) {
|
|
5776
5776
|
if (!ctx) {
|
|
5777
5777
|
return;
|
|
5778
5778
|
}
|
|
5779
|
-
static_cast<
|
|
5779
|
+
static_cast<SparkBunClient*>(ctx)->OnRemoteDevToolsClosed(target_id);
|
|
5780
5780
|
}
|
|
5781
5781
|
|
|
5782
5782
|
@interface CEFWebViewImpl : AbstractView
|
|
5783
5783
|
// @property (nonatomic, strong) WKWebView *webView;
|
|
5784
5784
|
|
|
5785
5785
|
@property (nonatomic, assign) CefRefPtr<CefBrowser> browser;
|
|
5786
|
-
@property (nonatomic, assign) CefRefPtr<
|
|
5786
|
+
@property (nonatomic, assign) CefRefPtr<SparkBunClient> client;
|
|
5787
5787
|
@property (nonatomic, strong) CEFOSRView *osrView; // For transparent/OSR mode
|
|
5788
5788
|
@property (nonatomic, assign) BOOL isOSRMode;
|
|
5789
5789
|
@property (nonatomic, copy) NSString *pendingURLString;
|
|
@@ -5804,7 +5804,7 @@ void RemoteDevToolsClosed(void* ctx, int target_id) {
|
|
|
5804
5804
|
eventBridgeHandler:(HandlePostMessage)eventBridgeHandler
|
|
5805
5805
|
bunBridgeHandler:(HandlePostMessage)bunBridgeHandler
|
|
5806
5806
|
internalBridgeHandler:(HandlePostMessage)internalBridgeHandler
|
|
5807
|
-
|
|
5807
|
+
sparkbunPreloadScript:(const char *)sparkbunPreloadScript
|
|
5808
5808
|
customPreloadScript:(const char *)customPreloadScript
|
|
5809
5809
|
viewsRoot:(const char *)viewsRoot
|
|
5810
5810
|
transparent:(bool)transparent
|
|
@@ -5816,8 +5816,8 @@ bool initializeCEF() {
|
|
|
5816
5816
|
static bool initialized = false;
|
|
5817
5817
|
if (initialized) return true;
|
|
5818
5818
|
|
|
5819
|
-
[
|
|
5820
|
-
if (![NSApp isKindOfClass:[
|
|
5819
|
+
[SparkBunNSApplication sharedApplication];
|
|
5820
|
+
if (![NSApp isKindOfClass:[SparkBunNSApplication class]]) {
|
|
5821
5821
|
return false;
|
|
5822
5822
|
}
|
|
5823
5823
|
|
|
@@ -5830,13 +5830,13 @@ bool initializeCEF() {
|
|
|
5830
5830
|
}
|
|
5831
5831
|
|
|
5832
5832
|
CefMainArgs main_args(argc, argv);
|
|
5833
|
-
g_app = new
|
|
5833
|
+
g_app = new SparkBunApp();
|
|
5834
5834
|
|
|
5835
5835
|
// Read user-defined chromium flags from build.json
|
|
5836
5836
|
NSString* buildJsonPath = [[NSBundle mainBundle] pathForResource:@"build" ofType:@"json"];
|
|
5837
5837
|
if (buildJsonPath) {
|
|
5838
|
-
std::string buildJsonContent =
|
|
5839
|
-
g_userChromiumFlags =
|
|
5838
|
+
std::string buildJsonContent = sparkbun::readFileToString([buildJsonPath UTF8String]);
|
|
5839
|
+
g_userChromiumFlags = sparkbun::parseChromiumFlags(buildJsonContent);
|
|
5840
5840
|
}
|
|
5841
5841
|
|
|
5842
5842
|
CefSettings settings;
|
|
@@ -5888,22 +5888,22 @@ bool initializeCEF() {
|
|
|
5888
5888
|
}
|
|
5889
5889
|
|
|
5890
5890
|
// Add cache path to prevent warnings and potential issues
|
|
5891
|
-
// Use app-specific cache directory to allow multiple
|
|
5891
|
+
// Use app-specific cache directory to allow multiple SparkBun apps to run simultaneously
|
|
5892
5892
|
NSString* appSupportPath = [NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES) firstObject];
|
|
5893
5893
|
|
|
5894
5894
|
// Build path with identifier/channel structure (consistent with CLI and updater)
|
|
5895
5895
|
std::string cachePathStr = buildAppDataPath(
|
|
5896
5896
|
[appSupportPath UTF8String],
|
|
5897
|
-
|
|
5898
|
-
|
|
5897
|
+
g_sparkbunIdentifier,
|
|
5898
|
+
g_sparkbunChannel,
|
|
5899
5899
|
"CEF"
|
|
5900
5900
|
);
|
|
5901
5901
|
NSString* cachePath = [NSString stringWithUTF8String:cachePathStr.c_str()];
|
|
5902
5902
|
NSLog(@"[CEF] Using path: %s", cachePathStr.c_str());
|
|
5903
5903
|
|
|
5904
|
-
// One-shot wipe if
|
|
5904
|
+
// One-shot wipe if SparkBun's cache format version has been bumped
|
|
5905
5905
|
// since the user's last launch. See cache_migration.h.
|
|
5906
|
-
|
|
5906
|
+
sparkbun::migrateCacheFolderIfNeeded(cachePathStr);
|
|
5907
5907
|
|
|
5908
5908
|
CefString(&settings.root_cache_path) = [cachePath UTF8String];
|
|
5909
5909
|
|
|
@@ -5918,7 +5918,7 @@ bool initializeCEF() {
|
|
|
5918
5918
|
CefString(&settings.accept_language_list) = "en-US,en";
|
|
5919
5919
|
|
|
5920
5920
|
// Register custom scheme
|
|
5921
|
-
// CefRegisterSchemeHandlerFactory("views", "", new
|
|
5921
|
+
// CefRegisterSchemeHandlerFactory("views", "", new SparkBunSchemeHandlerFactory(assetFileLoader, 0));
|
|
5922
5922
|
|
|
5923
5923
|
// Make CEF aware of the custom scheme
|
|
5924
5924
|
// CefCommandLine::GetGlobalCommandLine()->AppendSwitch("register-scheme-handler");
|
|
@@ -5948,9 +5948,9 @@ bool initializeCEF() {
|
|
|
5948
5948
|
|
|
5949
5949
|
|
|
5950
5950
|
// The main scheme handler class
|
|
5951
|
-
class
|
|
5951
|
+
class SparkBunSchemeHandler : public CefResourceHandler {
|
|
5952
5952
|
public:
|
|
5953
|
-
|
|
5953
|
+
SparkBunSchemeHandler(uint32_t webviewId)
|
|
5954
5954
|
: webviewId_(webviewId), hasResponse_(false), offset_(0) {}
|
|
5955
5955
|
|
|
5956
5956
|
bool Open(CefRefPtr<CefRequest> request,
|
|
@@ -6089,8 +6089,8 @@ public:
|
|
|
6089
6089
|
bool hasResponse_;
|
|
6090
6090
|
size_t offset_;
|
|
6091
6091
|
|
|
6092
|
-
IMPLEMENT_REFCOUNTING(
|
|
6093
|
-
DISALLOW_COPY_AND_ASSIGN(
|
|
6092
|
+
IMPLEMENT_REFCOUNTING(SparkBunSchemeHandler);
|
|
6093
|
+
DISALLOW_COPY_AND_ASSIGN(SparkBunSchemeHandler);
|
|
6094
6094
|
};
|
|
6095
6095
|
|
|
6096
6096
|
|
|
@@ -6099,9 +6099,9 @@ static std::map<int, uint32_t> browserToWebviewMap;
|
|
|
6099
6099
|
static std::mutex browserMapMutex;
|
|
6100
6100
|
|
|
6101
6101
|
// The factory class that creates scheme handlers
|
|
6102
|
-
class
|
|
6102
|
+
class SparkBunSchemeHandlerFactory : public CefSchemeHandlerFactory {
|
|
6103
6103
|
public:
|
|
6104
|
-
|
|
6104
|
+
SparkBunSchemeHandlerFactory() {}
|
|
6105
6105
|
|
|
6106
6106
|
CefRefPtr<CefResourceHandler> Create(CefRefPtr<CefBrowser> browser,
|
|
6107
6107
|
CefRefPtr<CefFrame> frame,
|
|
@@ -6124,11 +6124,11 @@ public:
|
|
|
6124
6124
|
NSLog(@" Browser %d -> Webview %u", pair.first, pair.second);
|
|
6125
6125
|
}
|
|
6126
6126
|
|
|
6127
|
-
return new
|
|
6127
|
+
return new SparkBunSchemeHandler(webviewId);
|
|
6128
6128
|
}
|
|
6129
6129
|
|
|
6130
|
-
IMPLEMENT_REFCOUNTING(
|
|
6131
|
-
DISALLOW_COPY_AND_ASSIGN(
|
|
6130
|
+
IMPLEMENT_REFCOUNTING(SparkBunSchemeHandlerFactory);
|
|
6131
|
+
DISALLOW_COPY_AND_ASSIGN(SparkBunSchemeHandlerFactory);
|
|
6132
6132
|
};
|
|
6133
6133
|
|
|
6134
6134
|
|
|
@@ -6142,7 +6142,7 @@ public:
|
|
|
6142
6142
|
// Platform implementation for partition_context.h — builds the on-disk
|
|
6143
6143
|
// cache_path for a persistent partition under the macOS Application Support
|
|
6144
6144
|
// directory, ensuring the directory exists.
|
|
6145
|
-
namespace
|
|
6145
|
+
namespace sparkbun {
|
|
6146
6146
|
std::string buildAndEnsurePartitionCachePath(const std::string& partitionName) {
|
|
6147
6147
|
NSString* appSupportPath = [NSSearchPathForDirectoriesInDomains(
|
|
6148
6148
|
NSApplicationSupportDirectory, NSUserDomainMask, YES) firstObject];
|
|
@@ -6150,8 +6150,8 @@ std::string buildAndEnsurePartitionCachePath(const std::string& partitionName) {
|
|
|
6150
6150
|
|
|
6151
6151
|
std::string cachePathStr = buildCEFPartitionPath(
|
|
6152
6152
|
[appSupportPath UTF8String],
|
|
6153
|
-
|
|
6154
|
-
|
|
6153
|
+
g_sparkbunIdentifier,
|
|
6154
|
+
g_sparkbunChannel,
|
|
6155
6155
|
"CEF",
|
|
6156
6156
|
partitionName);
|
|
6157
6157
|
|
|
@@ -6165,13 +6165,13 @@ std::string buildAndEnsurePartitionCachePath(const std::string& partitionName) {
|
|
|
6165
6165
|
}
|
|
6166
6166
|
return cachePathStr;
|
|
6167
6167
|
}
|
|
6168
|
-
} // namespace
|
|
6168
|
+
} // namespace sparkbun
|
|
6169
6169
|
|
|
6170
6170
|
CefRefPtr<CefRequestContext> CreateRequestContextForPartition(const char* partitionIdentifier,
|
|
6171
6171
|
uint32_t webviewId) {
|
|
6172
|
-
static CefRefPtr<
|
|
6173
|
-
new
|
|
6174
|
-
return
|
|
6172
|
+
static CefRefPtr<SparkBunSchemeHandlerFactory> schemeFactory =
|
|
6173
|
+
new SparkBunSchemeHandlerFactory();
|
|
6174
|
+
return sparkbun::getOrCreateRequestContextForPartition(
|
|
6175
6175
|
partitionIdentifier, webviewId, schemeFactory);
|
|
6176
6176
|
}
|
|
6177
6177
|
|
|
@@ -6191,7 +6191,7 @@ CefRefPtr<CefRequestContext> CreateRequestContextForPartition(const char* partit
|
|
|
6191
6191
|
eventBridgeHandler:(HandlePostMessage)eventBridgeHandler
|
|
6192
6192
|
bunBridgeHandler:(HandlePostMessage)bunBridgeHandler
|
|
6193
6193
|
internalBridgeHandler:(HandlePostMessage)internalBridgeHandler
|
|
6194
|
-
|
|
6194
|
+
sparkbunPreloadScript:(const char *)sparkbunPreloadScript
|
|
6195
6195
|
customPreloadScript:(const char *)customPreloadScript
|
|
6196
6196
|
viewsRoot:(const char *)viewsRoot
|
|
6197
6197
|
transparent:(bool)transparent
|
|
@@ -6254,7 +6254,7 @@ CefRefPtr<CefRequestContext> CreateRequestContextForPartition(const char* partit
|
|
|
6254
6254
|
|
|
6255
6255
|
// Global scheme handler is already registered in getOrCreateRequestContext()
|
|
6256
6256
|
|
|
6257
|
-
self.client = new
|
|
6257
|
+
self.client = new SparkBunClient(
|
|
6258
6258
|
webviewId,
|
|
6259
6259
|
eventBridgeHandler,
|
|
6260
6260
|
bunBridgeHandler,
|
|
@@ -6271,7 +6271,7 @@ CefRefPtr<CefRequestContext> CreateRequestContextForPartition(const char* partit
|
|
|
6271
6271
|
}
|
|
6272
6272
|
|
|
6273
6273
|
// store the script values
|
|
6274
|
-
[self addPreloadScriptToWebView:
|
|
6274
|
+
[self addPreloadScriptToWebView:sparkbunPreloadScript];
|
|
6275
6275
|
|
|
6276
6276
|
// Note: For custom preload scripts we support either inline js or a views:// style
|
|
6277
6277
|
// url to a js file in the bundled views folder.
|
|
@@ -6796,10 +6796,10 @@ extern "C" void startEventLoop(const char* identifier, const char* name, const c
|
|
|
6796
6796
|
|
|
6797
6797
|
// Store identifier and channel globally for use in CEF initialization
|
|
6798
6798
|
if (identifier && identifier[0]) {
|
|
6799
|
-
|
|
6799
|
+
g_sparkbunIdentifier = std::string(identifier);
|
|
6800
6800
|
}
|
|
6801
6801
|
if (channel && channel[0]) {
|
|
6802
|
-
|
|
6802
|
+
g_sparkbunChannel = std::string(channel);
|
|
6803
6803
|
}
|
|
6804
6804
|
|
|
6805
6805
|
useCEF = isCEFAvailable();
|
|
@@ -6970,7 +6970,7 @@ extern "C" AbstractView* initWebview(uint32_t webviewId,
|
|
|
6970
6970
|
HandlePostMessage eventBridgeHandler,
|
|
6971
6971
|
HandlePostMessage bunBridgeHandler,
|
|
6972
6972
|
HandlePostMessage internalBridgeHandler,
|
|
6973
|
-
const char *
|
|
6973
|
+
const char *sparkbunPreloadScript,
|
|
6974
6974
|
const char *customPreloadScript,
|
|
6975
6975
|
const char *viewsRoot,
|
|
6976
6976
|
bool transparent,
|
|
@@ -7017,7 +7017,7 @@ extern "C" AbstractView* initWebview(uint32_t webviewId,
|
|
|
7017
7017
|
eventBridgeHandler:eventBridgeHandler
|
|
7018
7018
|
bunBridgeHandler:bunBridgeHandler
|
|
7019
7019
|
internalBridgeHandler:internalBridgeHandler
|
|
7020
|
-
|
|
7020
|
+
sparkbunPreloadScript:strdup(sparkbunPreloadScript)
|
|
7021
7021
|
customPreloadScript:strdup(customPreloadScript)
|
|
7022
7022
|
viewsRoot:strdup(viewsRoot)
|
|
7023
7023
|
transparent:transparent
|
|
@@ -7429,10 +7429,10 @@ extern "C" NSRect createNSRectWrapper(double x, double y, double width, double h
|
|
|
7429
7429
|
}
|
|
7430
7430
|
|
|
7431
7431
|
|
|
7432
|
-
@interface
|
|
7432
|
+
@interface SparkBunWindow : NSWindow
|
|
7433
7433
|
@end
|
|
7434
7434
|
|
|
7435
|
-
@implementation
|
|
7435
|
+
@implementation SparkBunWindow
|
|
7436
7436
|
- (BOOL)canBecomeKeyWindow { return YES; }
|
|
7437
7437
|
- (BOOL)canBecomeMainWindow { return YES; }
|
|
7438
7438
|
@end
|
|
@@ -7450,7 +7450,7 @@ NSWindow *createNSWindowWithFrameAndStyle(uint32_t windowId,
|
|
|
7450
7450
|
NSRect screenFrame = [primaryScreen frame];
|
|
7451
7451
|
config.frame.origin.y = screenFrame.size.height - config.frame.origin.y;
|
|
7452
7452
|
|
|
7453
|
-
NSWindow *window = [[
|
|
7453
|
+
NSWindow *window = [[SparkBunWindow alloc] initWithContentRect:config.frame
|
|
7454
7454
|
styleMask:config.styleMask
|
|
7455
7455
|
backing:NSBackingStoreBuffered
|
|
7456
7456
|
defer:YES
|
|
@@ -8471,7 +8471,7 @@ extern "C" void setJSUtils(GetMimeType getMimeType, GetHTMLForWebviewSync getHTM
|
|
|
8471
8471
|
// create a dispatch queue on the current thread (worker thread) that
|
|
8472
8472
|
// can later be called from main
|
|
8473
8473
|
dispatch_queue_attr_t attr = dispatch_queue_attr_make_with_qos_class(DISPATCH_QUEUE_SERIAL, QOS_CLASS_DEFAULT, 0);
|
|
8474
|
-
jsWorkerQueue = dispatch_queue_create("com.
|
|
8474
|
+
jsWorkerQueue = dispatch_queue_create("com.sparkbun.jsworker", attr);
|
|
8475
8475
|
|
|
8476
8476
|
}
|
|
8477
8477
|
|
|
@@ -8532,7 +8532,7 @@ static NSLock *g_globalShortcutsLock = nil;
|
|
|
8532
8532
|
// Helper to parse modifier flags from accelerator string using the shared
|
|
8533
8533
|
// cross-platform parser from accelerator_parser.h.
|
|
8534
8534
|
static NSEventModifierFlags parseModifiers(NSString *accelerator, NSString **outKey) {
|
|
8535
|
-
auto parts =
|
|
8535
|
+
auto parts = sparkbun::parseAccelerator([accelerator UTF8String]);
|
|
8536
8536
|
*outKey = [NSString stringWithUTF8String:parts.key.c_str()];
|
|
8537
8537
|
return modifierFlagsFromAccelerator(parts);
|
|
8538
8538
|
}
|