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
|
@@ -75,7 +75,7 @@ struct DCompBridgeState;
|
|
|
75
75
|
static std::map<void*, std::unique_ptr<DCompBridgeState>> g_dcompBridges;
|
|
76
76
|
static std::mutex g_dcompBridgeMapMutex;
|
|
77
77
|
|
|
78
|
-
using namespace
|
|
78
|
+
using namespace sparkbun;
|
|
79
79
|
|
|
80
80
|
// Simple ASAR reader implementation for Windows (no external dependency)
|
|
81
81
|
#include <fstream>
|
|
@@ -391,7 +391,7 @@ using namespace Microsoft::WRL;
|
|
|
391
391
|
|
|
392
392
|
|
|
393
393
|
// Ensure the exported functions have appropriate visibility
|
|
394
|
-
#define
|
|
394
|
+
#define SPARKBUN_EXPORT __declspec(dllexport)
|
|
395
395
|
#define WM_EXECUTE_SYNC_BLOCK (WM_USER + 1)
|
|
396
396
|
#define WM_EXECUTE_ASYNC_BLOCK (WM_USER + 2)
|
|
397
397
|
#define WM_DEVTOOLS_CREATE (WM_USER + 3)
|
|
@@ -406,7 +406,7 @@ class MyScriptMessageHandlerWithReply;
|
|
|
406
406
|
class StatusItemTarget;
|
|
407
407
|
|
|
408
408
|
// CEF function declarations
|
|
409
|
-
|
|
409
|
+
SPARKBUN_EXPORT bool isCEFAvailable();
|
|
410
410
|
|
|
411
411
|
// Type definitions to match macOS types
|
|
412
412
|
typedef double CGFloat;
|
|
@@ -424,9 +424,9 @@ static GetMimeType g_getMimeType = nullptr;
|
|
|
424
424
|
static GetHTMLForWebviewSync g_getHTMLForWebviewSync = nullptr;
|
|
425
425
|
|
|
426
426
|
// Global variables for CEF cache path isolation
|
|
427
|
-
static std::string
|
|
428
|
-
static std::string
|
|
429
|
-
static std::string
|
|
427
|
+
static std::string g_sparkbunChannel = "";
|
|
428
|
+
static std::string g_sparkbunIdentifier = "";
|
|
429
|
+
static std::string g_sparkbunName = "";
|
|
430
430
|
|
|
431
431
|
// Webview content storage (replaces JSCallback approach)
|
|
432
432
|
static std::map<uint32_t, std::string> webviewHTMLContent;
|
|
@@ -443,8 +443,8 @@ static std::mutex g_abstractViewsMutex;
|
|
|
443
443
|
bool checkNavigationRules(AbstractView* view, const std::string& url);
|
|
444
444
|
|
|
445
445
|
// Forward declarations for HTML content management
|
|
446
|
-
extern "C"
|
|
447
|
-
extern "C"
|
|
446
|
+
extern "C" SPARKBUN_EXPORT const char* getWebviewHTMLContent(uint32_t webviewId);
|
|
447
|
+
extern "C" SPARKBUN_EXPORT void setWebviewHTMLContent(uint32_t webviewId, const char* htmlContent);
|
|
448
448
|
|
|
449
449
|
// Global mutex to serialize webview creation
|
|
450
450
|
static std::mutex g_webviewCreationMutex;
|
|
@@ -539,7 +539,7 @@ static int FindAvailableRemoteDebugPort(int startPort, int endPort) {
|
|
|
539
539
|
// CEF global variables
|
|
540
540
|
static bool g_cef_initialized = false;
|
|
541
541
|
static CefRefPtr<CefApp> g_cef_app;
|
|
542
|
-
static
|
|
542
|
+
static sparkbun::ChromiumFlagConfig g_userChromiumFlags;
|
|
543
543
|
static HANDLE g_job_object = nullptr; // Job object to track all child processes
|
|
544
544
|
|
|
545
545
|
// Quit/shutdown coordination
|
|
@@ -553,7 +553,7 @@ static DWORD g_mainThreadId = 0;
|
|
|
553
553
|
#define WM_CEF_SCHEDULE_WORK (WM_USER + 100)
|
|
554
554
|
static HWND g_cefPumpWindow = NULL;
|
|
555
555
|
|
|
556
|
-
class
|
|
556
|
+
class SparkBunCefApp : public CefApp, public CefBrowserProcessHandler {
|
|
557
557
|
public:
|
|
558
558
|
CefRefPtr<CefBrowserProcessHandler> GetBrowserProcessHandler() override {
|
|
559
559
|
return this;
|
|
@@ -576,16 +576,16 @@ public:
|
|
|
576
576
|
|
|
577
577
|
void OnBeforeCommandLineProcessing(const CefString& process_type, CefRefPtr<CefCommandLine> command_line) override {
|
|
578
578
|
// Windows default flags — can be overridden via chromiumFlags in config
|
|
579
|
-
static const std::vector<
|
|
579
|
+
static const std::vector<sparkbun::DefaultFlag> defaults = {
|
|
580
580
|
{"disable-web-security", ""},
|
|
581
581
|
{"disable-features=VizDisplayCompositor", ""},
|
|
582
582
|
{"remote-allow-origins", "*"},
|
|
583
583
|
{"allow-insecure-localhost", ""},
|
|
584
584
|
};
|
|
585
|
-
|
|
585
|
+
sparkbun::applyDefaultFlags(defaults, g_userChromiumFlags.skip, command_line);
|
|
586
586
|
|
|
587
587
|
// Apply user-defined chromium flags from build.json
|
|
588
|
-
|
|
588
|
+
sparkbun::applyChromiumFlags(g_userChromiumFlags, command_line);
|
|
589
589
|
}
|
|
590
590
|
|
|
591
591
|
void OnRegisterCustomSchemes(CefRawPtr<CefSchemeRegistrar> registrar) override {
|
|
@@ -599,24 +599,24 @@ public:
|
|
|
599
599
|
}
|
|
600
600
|
|
|
601
601
|
private:
|
|
602
|
-
IMPLEMENT_REFCOUNTING(
|
|
602
|
+
IMPLEMENT_REFCOUNTING(SparkBunCefApp);
|
|
603
603
|
};
|
|
604
604
|
|
|
605
605
|
// Forward declaration for CEF client (needed for load handler)
|
|
606
|
-
class
|
|
606
|
+
class SparkBunCefClient;
|
|
607
607
|
|
|
608
608
|
// CEF Load Handler for debugging navigation
|
|
609
|
-
class
|
|
609
|
+
class SparkBunLoadHandler : public CefLoadHandler {
|
|
610
610
|
public:
|
|
611
611
|
uint32_t webview_id_ = 0;
|
|
612
612
|
WebviewEventHandler webview_event_handler_ = nullptr;
|
|
613
|
-
CefRefPtr<
|
|
613
|
+
CefRefPtr<SparkBunCefClient> client_ = nullptr;
|
|
614
614
|
|
|
615
|
-
|
|
615
|
+
SparkBunLoadHandler() {}
|
|
616
616
|
|
|
617
617
|
void SetWebviewId(uint32_t id) { webview_id_ = id; }
|
|
618
618
|
void SetWebviewEventHandler(WebviewEventHandler handler) { webview_event_handler_ = handler; }
|
|
619
|
-
void SetClient(CefRefPtr<
|
|
619
|
+
void SetClient(CefRefPtr<SparkBunCefClient> client) { client_ = client; }
|
|
620
620
|
|
|
621
621
|
void OnLoadStart(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, TransitionType transition_type) override;
|
|
622
622
|
void OnLoadEnd(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, int httpStatusCode) override;
|
|
@@ -627,19 +627,19 @@ public:
|
|
|
627
627
|
}
|
|
628
628
|
|
|
629
629
|
private:
|
|
630
|
-
IMPLEMENT_REFCOUNTING(
|
|
630
|
+
IMPLEMENT_REFCOUNTING(SparkBunLoadHandler);
|
|
631
631
|
};
|
|
632
632
|
|
|
633
633
|
// Global map to store CEF clients for browser connection
|
|
634
|
-
static std::map<HWND, CefRefPtr<
|
|
634
|
+
static std::map<HWND, CefRefPtr<SparkBunCefClient>> g_cefClients;
|
|
635
635
|
|
|
636
636
|
// Forward declaration for helper functions (defined after class definitions)
|
|
637
|
-
void SetBrowserOnClient(CefRefPtr<
|
|
637
|
+
void SetBrowserOnClient(CefRefPtr<SparkBunCefClient> client, CefRefPtr<CefBrowser> browser);
|
|
638
638
|
void SetBrowserOnCEFView(HWND parentWindow, CefRefPtr<CefBrowser> browser);
|
|
639
639
|
void SetWebViewOnWebView2View(HWND containerWindow, void* webview);
|
|
640
640
|
|
|
641
641
|
// CEF Life Span Handler for async browser creation
|
|
642
|
-
class
|
|
642
|
+
class SparkBunLifeSpanHandler : public CefLifeSpanHandler {
|
|
643
643
|
public:
|
|
644
644
|
void OnAfterCreated(CefRefPtr<CefBrowser> browser) override {
|
|
645
645
|
// Note: Browser setup is now handled synchronously during CreateBrowserSync
|
|
@@ -683,11 +683,11 @@ public:
|
|
|
683
683
|
}
|
|
684
684
|
|
|
685
685
|
private:
|
|
686
|
-
IMPLEMENT_REFCOUNTING(
|
|
686
|
+
IMPLEMENT_REFCOUNTING(SparkBunLifeSpanHandler);
|
|
687
687
|
};
|
|
688
688
|
|
|
689
689
|
// Forward declaration for DevTools callback
|
|
690
|
-
class
|
|
690
|
+
class SparkBunCefClient;
|
|
691
691
|
typedef void (*RemoteDevToolsClosedCallback)(void* ctx, int target_id);
|
|
692
692
|
void RemoteDevToolsClosed(void* ctx, int target_id);
|
|
693
693
|
|
|
@@ -723,7 +723,7 @@ struct DevToolsWindowContext {
|
|
|
723
723
|
};
|
|
724
724
|
|
|
725
725
|
static std::once_flag g_devtoolsClassRegistered;
|
|
726
|
-
static const char* DEVTOOLS_WINDOW_CLASS = "
|
|
726
|
+
static const char* DEVTOOLS_WINDOW_CLASS = "SparkBunDevToolsClass";
|
|
727
727
|
|
|
728
728
|
static LRESULT CALLBACK DevToolsWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
|
|
729
729
|
DevToolsWindowContext* dtCtx = nullptr;
|
|
@@ -783,9 +783,9 @@ std::string loadViewsFile(const std::string& path);
|
|
|
783
783
|
std::string getMimeTypeForFile(const std::string& path);
|
|
784
784
|
|
|
785
785
|
// CEF Resource Handler for views:// scheme (based on Mac implementation)
|
|
786
|
-
class
|
|
786
|
+
class SparkBunSchemeHandler : public CefResourceHandler {
|
|
787
787
|
public:
|
|
788
|
-
|
|
788
|
+
SparkBunSchemeHandler(uint32_t webviewId)
|
|
789
789
|
: webviewId_(webviewId), offset_(0), hasResponse_(false) {}
|
|
790
790
|
|
|
791
791
|
bool Open(CefRefPtr<CefRequest> request, bool& handle_request, CefRefPtr<CefCallback> callback) override {
|
|
@@ -847,11 +847,11 @@ private:
|
|
|
847
847
|
std::vector<char> responseData_;
|
|
848
848
|
bool hasResponse_;
|
|
849
849
|
size_t offset_;
|
|
850
|
-
IMPLEMENT_REFCOUNTING(
|
|
850
|
+
IMPLEMENT_REFCOUNTING(SparkBunSchemeHandler);
|
|
851
851
|
};
|
|
852
852
|
|
|
853
853
|
// CEF Scheme Handler Factory
|
|
854
|
-
class
|
|
854
|
+
class SparkBunSchemeHandlerFactory : public CefSchemeHandlerFactory {
|
|
855
855
|
public:
|
|
856
856
|
CefRefPtr<CefResourceHandler> Create(CefRefPtr<CefBrowser> browser,
|
|
857
857
|
CefRefPtr<CefFrame> frame,
|
|
@@ -867,17 +867,17 @@ public:
|
|
|
867
867
|
webviewId = it->second;
|
|
868
868
|
}
|
|
869
869
|
}
|
|
870
|
-
return new
|
|
870
|
+
return new SparkBunSchemeHandler(webviewId);
|
|
871
871
|
}
|
|
872
872
|
|
|
873
873
|
private:
|
|
874
|
-
IMPLEMENT_REFCOUNTING(
|
|
874
|
+
IMPLEMENT_REFCOUNTING(SparkBunSchemeHandlerFactory);
|
|
875
875
|
};
|
|
876
876
|
|
|
877
877
|
// CEF Response Filter for script injection
|
|
878
|
-
class
|
|
878
|
+
class SparkBunResponseFilter : public CefResponseFilter {
|
|
879
879
|
public:
|
|
880
|
-
|
|
880
|
+
SparkBunResponseFilter(const std::string& script) : script_(script) {}
|
|
881
881
|
|
|
882
882
|
bool InitFilter() override {
|
|
883
883
|
return true;
|
|
@@ -950,18 +950,18 @@ private:
|
|
|
950
950
|
std::string processed_data_;
|
|
951
951
|
size_t output_offset_ = 0;
|
|
952
952
|
bool processed_ = false;
|
|
953
|
-
IMPLEMENT_REFCOUNTING(
|
|
953
|
+
IMPLEMENT_REFCOUNTING(SparkBunResponseFilter);
|
|
954
954
|
};
|
|
955
955
|
|
|
956
|
-
// Forward declaration for
|
|
957
|
-
class
|
|
956
|
+
// Forward declaration for SparkBunCefClient
|
|
957
|
+
class SparkBunCefClient;
|
|
958
958
|
|
|
959
959
|
// CEF Resource Request Handler to inject preload scripts via response filter
|
|
960
|
-
class
|
|
960
|
+
class SparkBunResourceRequestHandler : public CefResourceRequestHandler {
|
|
961
961
|
public:
|
|
962
|
-
CefRefPtr<
|
|
962
|
+
CefRefPtr<SparkBunCefClient> client_ = nullptr;
|
|
963
963
|
|
|
964
|
-
|
|
964
|
+
SparkBunResourceRequestHandler(CefRefPtr<SparkBunCefClient> client) : client_(client) {}
|
|
965
965
|
|
|
966
966
|
// Response filter to inject preload scripts into HTML before parsing
|
|
967
967
|
// This ensures scripts execute BEFORE any page JavaScript
|
|
@@ -971,26 +971,26 @@ public:
|
|
|
971
971
|
CefRefPtr<CefRequest> request,
|
|
972
972
|
CefRefPtr<CefResponse> response) override;
|
|
973
973
|
|
|
974
|
-
IMPLEMENT_REFCOUNTING(
|
|
974
|
+
IMPLEMENT_REFCOUNTING(SparkBunResourceRequestHandler);
|
|
975
975
|
};
|
|
976
976
|
|
|
977
977
|
// CEF Request Handler for views:// scheme support
|
|
978
|
-
class
|
|
978
|
+
class SparkBunRequestHandler : public CefRequestHandler {
|
|
979
979
|
public:
|
|
980
980
|
uint32_t webview_id_ = 0;
|
|
981
981
|
WebviewEventHandler webview_event_handler_ = nullptr;
|
|
982
982
|
AbstractView* abstract_view_ = nullptr;
|
|
983
|
-
CefRefPtr<
|
|
983
|
+
CefRefPtr<SparkBunCefClient> client_ = nullptr;
|
|
984
984
|
|
|
985
985
|
// Static debounce timestamp for ctrl+click handling
|
|
986
986
|
static double lastCtrlClickTime;
|
|
987
987
|
|
|
988
|
-
|
|
988
|
+
SparkBunRequestHandler() {}
|
|
989
989
|
|
|
990
990
|
void SetWebviewId(uint32_t id) { webview_id_ = id; }
|
|
991
991
|
void SetWebviewEventHandler(WebviewEventHandler handler) { webview_event_handler_ = handler; }
|
|
992
992
|
void SetAbstractView(AbstractView* view) { abstract_view_ = view; }
|
|
993
|
-
void SetClient(CefRefPtr<
|
|
993
|
+
void SetClient(CefRefPtr<SparkBunCefClient> client) { client_ = client; }
|
|
994
994
|
|
|
995
995
|
// Return resource request handler to enable response filtering
|
|
996
996
|
CefRefPtr<CefResourceRequestHandler> GetResourceRequestHandler(
|
|
@@ -1003,7 +1003,7 @@ public:
|
|
|
1003
1003
|
bool& disable_default_handling) override {
|
|
1004
1004
|
|
|
1005
1005
|
if (client_) {
|
|
1006
|
-
return new
|
|
1006
|
+
return new SparkBunResourceRequestHandler(client_);
|
|
1007
1007
|
}
|
|
1008
1008
|
return nullptr;
|
|
1009
1009
|
}
|
|
@@ -1082,16 +1082,16 @@ public:
|
|
|
1082
1082
|
}
|
|
1083
1083
|
|
|
1084
1084
|
private:
|
|
1085
|
-
IMPLEMENT_REFCOUNTING(
|
|
1085
|
+
IMPLEMENT_REFCOUNTING(SparkBunRequestHandler);
|
|
1086
1086
|
};
|
|
1087
1087
|
|
|
1088
1088
|
// Initialize static debounce timestamp
|
|
1089
|
-
double
|
|
1089
|
+
double SparkBunRequestHandler::lastCtrlClickTime = 0;
|
|
1090
1090
|
|
|
1091
1091
|
// CEF Context Menu Handler for devtools support
|
|
1092
|
-
class
|
|
1092
|
+
class SparkBunContextMenuHandler : public CefContextMenuHandler {
|
|
1093
1093
|
public:
|
|
1094
|
-
|
|
1094
|
+
SparkBunContextMenuHandler() {}
|
|
1095
1095
|
|
|
1096
1096
|
void OnBeforeContextMenu(CefRefPtr<CefBrowser> browser,
|
|
1097
1097
|
CefRefPtr<CefFrame> frame,
|
|
@@ -1102,7 +1102,7 @@ public:
|
|
|
1102
1102
|
model->AddItem(26501, "Inspect Element");
|
|
1103
1103
|
}
|
|
1104
1104
|
|
|
1105
|
-
// Defined out-of-line after
|
|
1105
|
+
// Defined out-of-line after SparkBunCefClient (needs full class definition)
|
|
1106
1106
|
bool OnContextMenuCommand(CefRefPtr<CefBrowser> browser,
|
|
1107
1107
|
CefRefPtr<CefFrame> frame,
|
|
1108
1108
|
CefRefPtr<CefContextMenuParams> params,
|
|
@@ -1110,11 +1110,11 @@ public:
|
|
|
1110
1110
|
EventFlags event_flags) override;
|
|
1111
1111
|
|
|
1112
1112
|
private:
|
|
1113
|
-
IMPLEMENT_REFCOUNTING(
|
|
1113
|
+
IMPLEMENT_REFCOUNTING(SparkBunContextMenuHandler);
|
|
1114
1114
|
};
|
|
1115
1115
|
|
|
1116
1116
|
// CEF Permission Handler for user media and other permissions
|
|
1117
|
-
class
|
|
1117
|
+
class SparkBunPermissionHandler : public CefPermissionHandler {
|
|
1118
1118
|
public:
|
|
1119
1119
|
bool OnRequestMediaAccessPermission(
|
|
1120
1120
|
CefRefPtr<CefBrowser> browser,
|
|
@@ -1214,7 +1214,7 @@ public:
|
|
|
1214
1214
|
// Unrecognized permission type — name what's being requested instead of
|
|
1215
1215
|
// a generic "additional permissions" dialog so the user can decide.
|
|
1216
1216
|
message = "This page is requesting permission for: " +
|
|
1217
|
-
|
|
1217
|
+
sparkbun::describeCefPermissions(requested_permissions) +
|
|
1218
1218
|
".\n\nDo you want to allow this?";
|
|
1219
1219
|
}
|
|
1220
1220
|
|
|
@@ -1266,7 +1266,7 @@ public:
|
|
|
1266
1266
|
}
|
|
1267
1267
|
|
|
1268
1268
|
private:
|
|
1269
|
-
IMPLEMENT_REFCOUNTING(
|
|
1269
|
+
IMPLEMENT_REFCOUNTING(SparkBunPermissionHandler);
|
|
1270
1270
|
};
|
|
1271
1271
|
|
|
1272
1272
|
// Helper functions for string conversion
|
|
@@ -1315,7 +1315,7 @@ std::string WStringToString(const std::wstring& wstr) {
|
|
|
1315
1315
|
}
|
|
1316
1316
|
|
|
1317
1317
|
// CEF Dialog Handler for file dialogs
|
|
1318
|
-
class
|
|
1318
|
+
class SparkBunDialogHandler : public CefDialogHandler {
|
|
1319
1319
|
public:
|
|
1320
1320
|
bool OnFileDialog(CefRefPtr<CefBrowser> browser,
|
|
1321
1321
|
FileDialogMode mode,
|
|
@@ -1462,13 +1462,13 @@ public:
|
|
|
1462
1462
|
}
|
|
1463
1463
|
|
|
1464
1464
|
private:
|
|
1465
|
-
IMPLEMENT_REFCOUNTING(
|
|
1465
|
+
IMPLEMENT_REFCOUNTING(SparkBunDialogHandler);
|
|
1466
1466
|
};
|
|
1467
1467
|
|
|
1468
1468
|
// CEF Download handler for Windows
|
|
1469
|
-
class
|
|
1469
|
+
class SparkBunDownloadHandler : public CefDownloadHandler {
|
|
1470
1470
|
public:
|
|
1471
|
-
|
|
1471
|
+
SparkBunDownloadHandler() {}
|
|
1472
1472
|
|
|
1473
1473
|
bool OnBeforeDownload(CefRefPtr<CefBrowser> browser,
|
|
1474
1474
|
CefRefPtr<CefDownloadItem> download_item,
|
|
@@ -1541,7 +1541,7 @@ public:
|
|
|
1541
1541
|
}
|
|
1542
1542
|
|
|
1543
1543
|
private:
|
|
1544
|
-
IMPLEMENT_REFCOUNTING(
|
|
1544
|
+
IMPLEMENT_REFCOUNTING(SparkBunDownloadHandler);
|
|
1545
1545
|
};
|
|
1546
1546
|
|
|
1547
1547
|
// OSR (Off-Screen Rendering) Window for transparent CEF windows
|
|
@@ -1740,9 +1740,9 @@ private:
|
|
|
1740
1740
|
};
|
|
1741
1741
|
|
|
1742
1742
|
// CEF Render Handler for off-screen rendering (OSR) mode
|
|
1743
|
-
class
|
|
1743
|
+
class SparkBunRenderHandler : public CefRenderHandler {
|
|
1744
1744
|
public:
|
|
1745
|
-
|
|
1745
|
+
SparkBunRenderHandler() : view_width_(800), view_height_(600), osr_window_(nullptr) {}
|
|
1746
1746
|
|
|
1747
1747
|
void SetOSRWindow(OSRWindow* window) {
|
|
1748
1748
|
osr_window_ = window;
|
|
@@ -1773,31 +1773,31 @@ private:
|
|
|
1773
1773
|
int view_height_;
|
|
1774
1774
|
OSRWindow* osr_window_;
|
|
1775
1775
|
|
|
1776
|
-
IMPLEMENT_REFCOUNTING(
|
|
1776
|
+
IMPLEMENT_REFCOUNTING(SparkBunRenderHandler);
|
|
1777
1777
|
};
|
|
1778
1778
|
|
|
1779
1779
|
// Forward declaration
|
|
1780
1780
|
void handleApplicationMenuSelection(UINT menuId);
|
|
1781
1781
|
|
|
1782
1782
|
// CEF Keyboard Handler for menu accelerators
|
|
1783
|
-
class
|
|
1783
|
+
class SparkBunKeyboardHandler : public CefKeyboardHandler {
|
|
1784
1784
|
public:
|
|
1785
|
-
// Defined out-of-line after
|
|
1785
|
+
// Defined out-of-line after SparkBunCefClient (needs full class definition)
|
|
1786
1786
|
bool OnPreKeyEvent(CefRefPtr<CefBrowser> browser,
|
|
1787
1787
|
const CefKeyEvent& event,
|
|
1788
1788
|
CefEventHandle os_event,
|
|
1789
1789
|
bool* is_keyboard_shortcut) override;
|
|
1790
1790
|
|
|
1791
1791
|
private:
|
|
1792
|
-
IMPLEMENT_REFCOUNTING(
|
|
1792
|
+
IMPLEMENT_REFCOUNTING(SparkBunKeyboardHandler);
|
|
1793
1793
|
};
|
|
1794
1794
|
|
|
1795
1795
|
// CEF Client class with load and life span handlers
|
|
1796
|
-
class
|
|
1796
|
+
class SparkBunCefClient : public CefClient, public CefDisplayHandler {
|
|
1797
1797
|
public:
|
|
1798
1798
|
WebviewEventHandler webview_event_handler_ = nullptr;
|
|
1799
1799
|
|
|
1800
|
-
|
|
1800
|
+
SparkBunCefClient(uint32_t webviewId,
|
|
1801
1801
|
HandlePostMessage eventBridgeHandler,
|
|
1802
1802
|
HandlePostMessage bunBridgeHandler,
|
|
1803
1803
|
HandlePostMessage internalBridgeHandler,
|
|
@@ -1808,23 +1808,23 @@ public:
|
|
|
1808
1808
|
webview_tag_handler_(internalBridgeHandler),
|
|
1809
1809
|
is_sandboxed_(sandbox),
|
|
1810
1810
|
osr_enabled_(false) {
|
|
1811
|
-
m_loadHandler = new
|
|
1811
|
+
m_loadHandler = new SparkBunLoadHandler();
|
|
1812
1812
|
m_loadHandler->SetClient(this); // Set client reference for load handler
|
|
1813
|
-
m_lifeSpanHandler = new
|
|
1814
|
-
m_requestHandler = new
|
|
1813
|
+
m_lifeSpanHandler = new SparkBunLifeSpanHandler();
|
|
1814
|
+
m_requestHandler = new SparkBunRequestHandler();
|
|
1815
1815
|
m_requestHandler->SetWebviewId(webviewId);
|
|
1816
1816
|
m_requestHandler->SetClient(this); // Set client reference for response filter
|
|
1817
|
-
m_contextMenuHandler = new
|
|
1818
|
-
m_permissionHandler = new
|
|
1819
|
-
m_dialogHandler = new
|
|
1820
|
-
m_downloadHandler = new
|
|
1821
|
-
m_keyboardHandler = new
|
|
1817
|
+
m_contextMenuHandler = new SparkBunContextMenuHandler();
|
|
1818
|
+
m_permissionHandler = new SparkBunPermissionHandler();
|
|
1819
|
+
m_dialogHandler = new SparkBunDialogHandler();
|
|
1820
|
+
m_downloadHandler = new SparkBunDownloadHandler();
|
|
1821
|
+
m_keyboardHandler = new SparkBunKeyboardHandler();
|
|
1822
1822
|
m_renderHandler = nullptr; // Created only when OSR is enabled
|
|
1823
1823
|
}
|
|
1824
1824
|
|
|
1825
1825
|
void EnableOSR(int width, int height) {
|
|
1826
1826
|
osr_enabled_ = true;
|
|
1827
|
-
m_renderHandler = new
|
|
1827
|
+
m_renderHandler = new SparkBunRenderHandler();
|
|
1828
1828
|
m_renderHandler->SetViewSize(width, height);
|
|
1829
1829
|
}
|
|
1830
1830
|
|
|
@@ -1862,7 +1862,7 @@ public:
|
|
|
1862
1862
|
}
|
|
1863
1863
|
|
|
1864
1864
|
void AddPreloadScript(const std::string& script) {
|
|
1865
|
-
|
|
1865
|
+
sparkbun_script_ = script;
|
|
1866
1866
|
}
|
|
1867
1867
|
|
|
1868
1868
|
void UpdateCustomPreloadScript(const std::string& script) {
|
|
@@ -1947,7 +1947,7 @@ public:
|
|
|
1947
1947
|
std::string GetCombinedScript() const {
|
|
1948
1948
|
// Inject webviewId into global scope before other scripts
|
|
1949
1949
|
std::string combined_script = "window.webviewId = " + std::to_string(webview_id_) + ";\n";
|
|
1950
|
-
combined_script +=
|
|
1950
|
+
combined_script += sparkbun_script_;
|
|
1951
1951
|
if (!custom_script_.empty()) {
|
|
1952
1952
|
combined_script += "\n" + custom_script_;
|
|
1953
1953
|
}
|
|
@@ -1996,12 +1996,12 @@ public:
|
|
|
1996
1996
|
int port = g_remoteDebugPort;
|
|
1997
1997
|
|
|
1998
1998
|
// Keep ref to self for the background thread
|
|
1999
|
-
CefRefPtr<
|
|
1999
|
+
CefRefPtr<SparkBunCefClient> self(this);
|
|
2000
2000
|
|
|
2001
2001
|
// Fetch /json on a background thread
|
|
2002
2002
|
std::thread([self, target_id, targetUrl, targetTitle, port]() {
|
|
2003
2003
|
// WinHTTP synchronous GET to http://127.0.0.1:{port}/json
|
|
2004
|
-
HINTERNET hSession = WinHttpOpen(L"
|
|
2004
|
+
HINTERNET hSession = WinHttpOpen(L"SparkBun/DevTools",
|
|
2005
2005
|
WINHTTP_ACCESS_TYPE_NO_PROXY,
|
|
2006
2006
|
WINHTTP_NO_PROXY_NAME,
|
|
2007
2007
|
WINHTTP_NO_PROXY_BYPASS, 0);
|
|
@@ -2121,13 +2121,13 @@ public:
|
|
|
2121
2121
|
// Post back to the UI thread via CefPostTask
|
|
2122
2122
|
class CreateDevToolsTask : public CefTask {
|
|
2123
2123
|
public:
|
|
2124
|
-
CreateDevToolsTask(CefRefPtr<
|
|
2124
|
+
CreateDevToolsTask(CefRefPtr<SparkBunCefClient> client, int tid, const std::string& url)
|
|
2125
2125
|
: client_(client), target_id_(tid), url_(url) {}
|
|
2126
2126
|
void Execute() override {
|
|
2127
2127
|
client_->CreateRemoteDevToolsWindow(target_id_, url_);
|
|
2128
2128
|
}
|
|
2129
2129
|
private:
|
|
2130
|
-
CefRefPtr<
|
|
2130
|
+
CefRefPtr<SparkBunCefClient> client_;
|
|
2131
2131
|
int target_id_;
|
|
2132
2132
|
std::string url_;
|
|
2133
2133
|
IMPLEMENT_REFCOUNTING(CreateDevToolsTask);
|
|
@@ -2233,18 +2233,18 @@ private:
|
|
|
2233
2233
|
HandlePostMessage bun_bridge_handler_;
|
|
2234
2234
|
HandlePostMessage webview_tag_handler_;
|
|
2235
2235
|
bool is_sandboxed_;
|
|
2236
|
-
std::string
|
|
2236
|
+
std::string sparkbun_script_;
|
|
2237
2237
|
std::string custom_script_;
|
|
2238
2238
|
CefRefPtr<CefBrowser> browser_;
|
|
2239
|
-
CefRefPtr<
|
|
2240
|
-
CefRefPtr<
|
|
2241
|
-
CefRefPtr<
|
|
2242
|
-
CefRefPtr<
|
|
2243
|
-
CefRefPtr<
|
|
2244
|
-
CefRefPtr<
|
|
2245
|
-
CefRefPtr<
|
|
2246
|
-
CefRefPtr<
|
|
2247
|
-
CefRefPtr<
|
|
2239
|
+
CefRefPtr<SparkBunLoadHandler> m_loadHandler;
|
|
2240
|
+
CefRefPtr<SparkBunLifeSpanHandler> m_lifeSpanHandler;
|
|
2241
|
+
CefRefPtr<SparkBunRequestHandler> m_requestHandler;
|
|
2242
|
+
CefRefPtr<SparkBunContextMenuHandler> m_contextMenuHandler;
|
|
2243
|
+
CefRefPtr<SparkBunPermissionHandler> m_permissionHandler;
|
|
2244
|
+
CefRefPtr<SparkBunDialogHandler> m_dialogHandler;
|
|
2245
|
+
CefRefPtr<SparkBunDownloadHandler> m_downloadHandler;
|
|
2246
|
+
CefRefPtr<SparkBunKeyboardHandler> m_keyboardHandler;
|
|
2247
|
+
CefRefPtr<SparkBunRenderHandler> m_renderHandler;
|
|
2248
2248
|
bool osr_enabled_;
|
|
2249
2249
|
std::function<void()> load_end_callback_; // Callback for page load completion
|
|
2250
2250
|
|
|
@@ -2259,27 +2259,27 @@ private:
|
|
|
2259
2259
|
std::map<int, DevToolsHost> devtools_hosts_;
|
|
2260
2260
|
std::string last_title_;
|
|
2261
2261
|
|
|
2262
|
-
IMPLEMENT_REFCOUNTING(
|
|
2262
|
+
IMPLEMENT_REFCOUNTING(SparkBunCefClient);
|
|
2263
2263
|
};
|
|
2264
2264
|
|
|
2265
|
-
// Free function callback for RemoteDevToolsClient ->
|
|
2265
|
+
// Free function callback for RemoteDevToolsClient -> SparkBunCefClient
|
|
2266
2266
|
void RemoteDevToolsClosed(void* ctx, int target_id) {
|
|
2267
2267
|
if (!ctx) return;
|
|
2268
|
-
static_cast<
|
|
2268
|
+
static_cast<SparkBunCefClient*>(ctx)->OnRemoteDevToolsClosed(target_id);
|
|
2269
2269
|
}
|
|
2270
2270
|
|
|
2271
|
-
// Out-of-line definitions for handlers that need
|
|
2271
|
+
// Out-of-line definitions for handlers that need SparkBunCefClient to be fully defined
|
|
2272
2272
|
|
|
2273
|
-
bool
|
|
2273
|
+
bool SparkBunContextMenuHandler::OnContextMenuCommand(
|
|
2274
2274
|
CefRefPtr<CefBrowser> browser,
|
|
2275
2275
|
CefRefPtr<CefFrame> frame,
|
|
2276
2276
|
CefRefPtr<CefContextMenuParams> params,
|
|
2277
2277
|
int command_id,
|
|
2278
2278
|
EventFlags event_flags) {
|
|
2279
2279
|
if (command_id == 26501) {
|
|
2280
|
-
// Open remote DevTools via the owning
|
|
2280
|
+
// Open remote DevTools via the owning SparkBunCefClient
|
|
2281
2281
|
CefRefPtr<CefClient> client = browser->GetHost()->GetClient();
|
|
2282
|
-
|
|
2282
|
+
SparkBunCefClient* ebClient = static_cast<SparkBunCefClient*>(client.get());
|
|
2283
2283
|
if (ebClient) {
|
|
2284
2284
|
ebClient->OpenRemoteDevToolsFrontend(browser);
|
|
2285
2285
|
}
|
|
@@ -2288,7 +2288,7 @@ bool ElectrobunContextMenuHandler::OnContextMenuCommand(
|
|
|
2288
2288
|
return false;
|
|
2289
2289
|
}
|
|
2290
2290
|
|
|
2291
|
-
bool
|
|
2291
|
+
bool SparkBunKeyboardHandler::OnPreKeyEvent(
|
|
2292
2292
|
CefRefPtr<CefBrowser> browser,
|
|
2293
2293
|
const CefKeyEvent& event,
|
|
2294
2294
|
CefEventHandle os_event,
|
|
@@ -2305,7 +2305,7 @@ bool ElectrobunKeyboardHandler::OnPreKeyEvent(
|
|
|
2305
2305
|
(event.modifiers & EVENTFLAG_SHIFT_DOWN));
|
|
2306
2306
|
if (isF12 || isCtrlShiftI) {
|
|
2307
2307
|
CefRefPtr<CefClient> client = browser->GetHost()->GetClient();
|
|
2308
|
-
|
|
2308
|
+
SparkBunCefClient* ebClient = static_cast<SparkBunCefClient*>(client.get());
|
|
2309
2309
|
if (ebClient) {
|
|
2310
2310
|
ebClient->OpenRemoteDevToolsFrontend(browser);
|
|
2311
2311
|
}
|
|
@@ -2337,8 +2337,8 @@ bool ElectrobunKeyboardHandler::OnPreKeyEvent(
|
|
|
2337
2337
|
return false;
|
|
2338
2338
|
}
|
|
2339
2339
|
|
|
2340
|
-
//
|
|
2341
|
-
void
|
|
2340
|
+
// SparkBunRenderHandler::OnPaint implementation
|
|
2341
|
+
void SparkBunRenderHandler::OnPaint(CefRefPtr<CefBrowser> browser,
|
|
2342
2342
|
PaintElementType type,
|
|
2343
2343
|
const RectList& dirtyRects,
|
|
2344
2344
|
const void* buffer,
|
|
@@ -2349,8 +2349,8 @@ void ElectrobunRenderHandler::OnPaint(CefRefPtr<CefBrowser> browser,
|
|
|
2349
2349
|
}
|
|
2350
2350
|
}
|
|
2351
2351
|
|
|
2352
|
-
// Helper function implementation (defined after
|
|
2353
|
-
void SetBrowserOnClient(CefRefPtr<
|
|
2352
|
+
// Helper function implementation (defined after SparkBunCefClient class)
|
|
2353
|
+
void SetBrowserOnClient(CefRefPtr<SparkBunCefClient> client, CefRefPtr<CefBrowser> browser) {
|
|
2354
2354
|
if (client && browser) {
|
|
2355
2355
|
client->SetBrowser(browser);
|
|
2356
2356
|
// Store preload scripts for this browser ID so load handler can access them
|
|
@@ -2361,13 +2361,13 @@ void SetBrowserOnClient(CefRefPtr<ElectrobunCefClient> client, CefRefPtr<CefBrow
|
|
|
2361
2361
|
}
|
|
2362
2362
|
}
|
|
2363
2363
|
|
|
2364
|
-
//
|
|
2365
|
-
void
|
|
2364
|
+
// SparkBunLoadHandler method implementations (defined after SparkBunCefClient class)
|
|
2365
|
+
void SparkBunLoadHandler::OnLoadStart(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, TransitionType transition_type) {
|
|
2366
2366
|
// NOTE: OnLoadStart is now a fallback - primary injection happens via GetResourceResponseFilter
|
|
2367
2367
|
// This ensures preload scripts are in the HTML before parsing, guaranteeing execution order
|
|
2368
2368
|
}
|
|
2369
2369
|
|
|
2370
|
-
void
|
|
2370
|
+
void SparkBunLoadHandler::OnLoadEnd(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, int httpStatusCode) {
|
|
2371
2371
|
// Fire did-navigate event
|
|
2372
2372
|
if (frame->IsMain() && webview_event_handler_) {
|
|
2373
2373
|
std::string url = frame->GetURL().ToString();
|
|
@@ -2380,8 +2380,8 @@ void ElectrobunLoadHandler::OnLoadEnd(CefRefPtr<CefBrowser> browser, CefRefPtr<C
|
|
|
2380
2380
|
}
|
|
2381
2381
|
}
|
|
2382
2382
|
|
|
2383
|
-
//
|
|
2384
|
-
CefRefPtr<CefResponseFilter>
|
|
2383
|
+
// SparkBunResourceRequestHandler method implementations (defined after SparkBunCefClient class)
|
|
2384
|
+
CefRefPtr<CefResponseFilter> SparkBunResourceRequestHandler::GetResourceResponseFilter(
|
|
2385
2385
|
CefRefPtr<CefBrowser> browser,
|
|
2386
2386
|
CefRefPtr<CefFrame> frame,
|
|
2387
2387
|
CefRefPtr<CefRequest> request,
|
|
@@ -2404,7 +2404,7 @@ CefRefPtr<CefResponseFilter> ElectrobunResourceRequestHandler::GetResourceRespon
|
|
|
2404
2404
|
|
|
2405
2405
|
if (!combinedScript.empty()) {
|
|
2406
2406
|
std::cout << "[CEF] Installing response filter to inject preload scripts into HTML" << std::endl;
|
|
2407
|
-
return new
|
|
2407
|
+
return new SparkBunResponseFilter(combinedScript);
|
|
2408
2408
|
}
|
|
2409
2409
|
}
|
|
2410
2410
|
|
|
@@ -2929,7 +2929,7 @@ public:
|
|
|
2929
2929
|
bool isBlockRule = !rule.empty() && rule[0] == '^';
|
|
2930
2930
|
std::string pattern = isBlockRule ? rule.substr(1) : rule;
|
|
2931
2931
|
|
|
2932
|
-
if (
|
|
2932
|
+
if (sparkbun::globMatch(pattern, url)) {
|
|
2933
2933
|
allowed = !isBlockRule; // Last match wins
|
|
2934
2934
|
}
|
|
2935
2935
|
}
|
|
@@ -3077,7 +3077,7 @@ private:
|
|
|
3077
3077
|
public:
|
|
3078
3078
|
std::string pendingUrl;
|
|
3079
3079
|
std::string pendingHtml; // Stored inline HTML for loading after async creation
|
|
3080
|
-
std::string
|
|
3080
|
+
std::string sparkbunScript;
|
|
3081
3081
|
std::string customScript;
|
|
3082
3082
|
bool isCreationComplete = false;
|
|
3083
3083
|
WebviewEventHandler webviewEventHandler = nullptr;
|
|
@@ -3536,7 +3536,7 @@ double WebView2View::lastCtrlClickTime = 0;
|
|
|
3536
3536
|
class CEFView : public AbstractView {
|
|
3537
3537
|
private:
|
|
3538
3538
|
CefRefPtr<CefBrowser> browser;
|
|
3539
|
-
CefRefPtr<
|
|
3539
|
+
CefRefPtr<SparkBunCefClient> client;
|
|
3540
3540
|
OSRWindow* osr_window;
|
|
3541
3541
|
bool is_osr_mode;
|
|
3542
3542
|
|
|
@@ -3749,7 +3749,7 @@ public:
|
|
|
3749
3749
|
}
|
|
3750
3750
|
}
|
|
3751
3751
|
|
|
3752
|
-
void setClient(CefRefPtr<
|
|
3752
|
+
void setClient(CefRefPtr<SparkBunCefClient> cl) {
|
|
3753
3753
|
client = cl;
|
|
3754
3754
|
}
|
|
3755
3755
|
|
|
@@ -3757,7 +3757,7 @@ public:
|
|
|
3757
3757
|
return browser;
|
|
3758
3758
|
}
|
|
3759
3759
|
|
|
3760
|
-
CefRefPtr<
|
|
3760
|
+
CefRefPtr<SparkBunCefClient> getClient() {
|
|
3761
3761
|
return client;
|
|
3762
3762
|
}
|
|
3763
3763
|
|
|
@@ -5302,7 +5302,7 @@ static UINT getMenuVirtualKeyCode(const std::string& key) {
|
|
|
5302
5302
|
// Parse modifiers from accelerator string for menu accelerators using the
|
|
5303
5303
|
// shared cross-platform parser. Returns FCONTROL, FALT, FSHIFT flags.
|
|
5304
5304
|
static BYTE parseMenuModifiers(const std::string& accelerator, std::string& outKey) {
|
|
5305
|
-
auto parts =
|
|
5305
|
+
auto parts = sparkbun::parseAccelerator(accelerator);
|
|
5306
5306
|
outKey = parts.key;
|
|
5307
5307
|
|
|
5308
5308
|
BYTE modifiers = FVIRTKEY;
|
|
@@ -5839,7 +5839,7 @@ void TerminateCEFHelperProcesses() {
|
|
|
5839
5839
|
CloseHandle(hSnapshot);
|
|
5840
5840
|
}
|
|
5841
5841
|
|
|
5842
|
-
|
|
5842
|
+
SPARKBUN_EXPORT bool initCEF() {
|
|
5843
5843
|
if (g_cef_initialized) {
|
|
5844
5844
|
return true; // Already initialized
|
|
5845
5845
|
}
|
|
@@ -5885,31 +5885,31 @@ ELECTROBUN_EXPORT bool initCEF() {
|
|
|
5885
5885
|
std::string userDataDir;
|
|
5886
5886
|
char* localAppData = getenv("LOCALAPPDATA");
|
|
5887
5887
|
if (localAppData) {
|
|
5888
|
-
userDataDir = buildAppDataPath(localAppData,
|
|
5888
|
+
userDataDir = buildAppDataPath(localAppData, g_sparkbunIdentifier, g_sparkbunChannel, "CEF", '\\');
|
|
5889
5889
|
std::cout << "[CEF] Using path: " << userDataDir << std::endl;
|
|
5890
5890
|
} else {
|
|
5891
5891
|
// Fallback to executable directory if LOCALAPPDATA not available
|
|
5892
|
-
userDataDir = buildAppDataPath(exePath,
|
|
5892
|
+
userDataDir = buildAppDataPath(exePath, g_sparkbunIdentifier, g_sparkbunChannel, "cef_cache", '\\');
|
|
5893
5893
|
}
|
|
5894
5894
|
|
|
5895
5895
|
// Create cache directory if it doesn't exist
|
|
5896
5896
|
CreateDirectoryA(userDataDir.c_str(), NULL);
|
|
5897
5897
|
|
|
5898
|
-
// One-shot wipe if
|
|
5898
|
+
// One-shot wipe if SparkBun's cache format version has been bumped
|
|
5899
5899
|
// since the user's last launch. See cache_migration.h.
|
|
5900
|
-
|
|
5900
|
+
sparkbun::migrateCacheFolderIfNeeded(userDataDir);
|
|
5901
5901
|
|
|
5902
5902
|
// Initialize CEF
|
|
5903
5903
|
CefMainArgs main_args(GetModuleHandle(NULL));
|
|
5904
5904
|
|
|
5905
5905
|
// Create the app
|
|
5906
|
-
g_cef_app = new
|
|
5906
|
+
g_cef_app = new SparkBunCefApp();
|
|
5907
5907
|
|
|
5908
5908
|
// Read user-defined chromium flags from build.json
|
|
5909
5909
|
std::string buildJsonPath = std::string(exePath) + "\\..\\Resources\\build.json";
|
|
5910
|
-
std::string buildJsonContent =
|
|
5910
|
+
std::string buildJsonContent = sparkbun::readFileToString(buildJsonPath);
|
|
5911
5911
|
if (!buildJsonContent.empty()) {
|
|
5912
|
-
g_userChromiumFlags =
|
|
5912
|
+
g_userChromiumFlags = sparkbun::parseChromiumFlags(buildJsonContent);
|
|
5913
5913
|
}
|
|
5914
5914
|
|
|
5915
5915
|
// CEF settings
|
|
@@ -5948,7 +5948,7 @@ ELECTROBUN_EXPORT bool initCEF() {
|
|
|
5948
5948
|
if (success) {
|
|
5949
5949
|
g_cef_initialized = true;
|
|
5950
5950
|
// Register the views:// scheme handler factory
|
|
5951
|
-
CefRegisterSchemeHandlerFactory("views", "", new
|
|
5951
|
+
CefRegisterSchemeHandlerFactory("views", "", new SparkBunSchemeHandlerFactory());
|
|
5952
5952
|
|
|
5953
5953
|
// We'll start the message pump timer when we create the first browser
|
|
5954
5954
|
} else {
|
|
@@ -5971,7 +5971,7 @@ static std::shared_ptr<WebView2View> createWebView2View(uint32_t webviewId,
|
|
|
5971
5971
|
HandlePostMessage eventBridgeHandler,
|
|
5972
5972
|
HandlePostMessage bunBridgeHandler,
|
|
5973
5973
|
HandlePostMessage internalBridgeHandler,
|
|
5974
|
-
const char *
|
|
5974
|
+
const char *sparkbunPreloadScript,
|
|
5975
5975
|
const char *customPreloadScript,
|
|
5976
5976
|
bool transparent,
|
|
5977
5977
|
bool sandbox) {
|
|
@@ -5991,7 +5991,7 @@ static std::shared_ptr<WebView2View> createWebView2View(uint32_t webviewId,
|
|
|
5991
5991
|
|
|
5992
5992
|
// Make safe copies of string parameters to avoid memory corruption in lambda captures
|
|
5993
5993
|
std::string urlString = url ? std::string(url) : "";
|
|
5994
|
-
std::string
|
|
5994
|
+
std::string sparkbunScript = sparkbunPreloadScript ? std::string(sparkbunPreloadScript) : "";
|
|
5995
5995
|
std::string customScript = customPreloadScript ? std::string(customPreloadScript) : "";
|
|
5996
5996
|
std::string partitionStr = partitionIdentifier ? std::string(partitionIdentifier) : "";
|
|
5997
5997
|
|
|
@@ -6002,7 +6002,7 @@ static std::shared_ptr<WebView2View> createWebView2View(uint32_t webviewId,
|
|
|
6002
6002
|
|
|
6003
6003
|
// Store URL and scripts in view to survive async callbacks
|
|
6004
6004
|
view->pendingUrl = urlString;
|
|
6005
|
-
view->
|
|
6005
|
+
view->sparkbunScript = sparkbunScript;
|
|
6006
6006
|
view->customScript = customScript;
|
|
6007
6007
|
|
|
6008
6008
|
// Create WebView2 on main thread
|
|
@@ -6233,8 +6233,8 @@ static std::shared_ptr<WebView2View> createWebView2View(uint32_t webviewId,
|
|
|
6233
6233
|
|
|
6234
6234
|
// Add preload scripts
|
|
6235
6235
|
std::string combinedScript;
|
|
6236
|
-
if (!view->
|
|
6237
|
-
combinedScript += view->
|
|
6236
|
+
if (!view->sparkbunScript.empty()) {
|
|
6237
|
+
combinedScript += view->sparkbunScript;
|
|
6238
6238
|
}
|
|
6239
6239
|
if (!view->customScript.empty()) {
|
|
6240
6240
|
if (!combinedScript.empty()) {
|
|
@@ -6695,7 +6695,7 @@ static std::shared_ptr<WebView2View> createWebView2View(uint32_t webviewId,
|
|
|
6695
6695
|
std::wstring userDataFolder;
|
|
6696
6696
|
char* localAppData = getenv("LOCALAPPDATA");
|
|
6697
6697
|
if (localAppData) {
|
|
6698
|
-
std::string userDataPath = buildAppDataPath(localAppData,
|
|
6698
|
+
std::string userDataPath = buildAppDataPath(localAppData, g_sparkbunIdentifier, g_sparkbunChannel, "WebView2", '\\');
|
|
6699
6699
|
|
|
6700
6700
|
// Handle partition-specific storage
|
|
6701
6701
|
if (!partitionStr.empty()) {
|
|
@@ -6753,7 +6753,7 @@ static std::shared_ptr<WebView2View> createWebView2View(uint32_t webviewId,
|
|
|
6753
6753
|
// cache_path for a persistent partition under %LOCALAPPDATA%, creating any
|
|
6754
6754
|
// missing parent directories. Returns "" if %LOCALAPPDATA% is unset, which
|
|
6755
6755
|
// causes the caller to fall back to an ephemeral context.
|
|
6756
|
-
namespace
|
|
6756
|
+
namespace sparkbun {
|
|
6757
6757
|
std::string buildAndEnsurePartitionCachePath(const std::string& partitionName) {
|
|
6758
6758
|
char* localAppData = getenv("LOCALAPPDATA");
|
|
6759
6759
|
if (!localAppData) {
|
|
@@ -6761,18 +6761,18 @@ std::string buildAndEnsurePartitionCachePath(const std::string& partitionName) {
|
|
|
6761
6761
|
return "";
|
|
6762
6762
|
}
|
|
6763
6763
|
std::string cachePath = buildCEFPartitionPath(
|
|
6764
|
-
localAppData,
|
|
6764
|
+
localAppData, g_sparkbunIdentifier, g_sparkbunChannel, "CEF", partitionName, '\\');
|
|
6765
6765
|
std::wstring wideCachePath(cachePath.begin(), cachePath.end());
|
|
6766
6766
|
SHCreateDirectoryExW(NULL, wideCachePath.c_str(), NULL);
|
|
6767
6767
|
return cachePath;
|
|
6768
6768
|
}
|
|
6769
|
-
} // namespace
|
|
6769
|
+
} // namespace sparkbun
|
|
6770
6770
|
|
|
6771
6771
|
CefRefPtr<CefRequestContext> CreateRequestContextForPartition(const char* partitionIdentifier,
|
|
6772
6772
|
uint32_t webviewId) {
|
|
6773
|
-
static CefRefPtr<
|
|
6774
|
-
new
|
|
6775
|
-
return
|
|
6773
|
+
static CefRefPtr<SparkBunSchemeHandlerFactory> schemeFactory =
|
|
6774
|
+
new SparkBunSchemeHandlerFactory();
|
|
6775
|
+
return sparkbun::getOrCreateRequestContextForPartition(
|
|
6776
6776
|
partitionIdentifier, webviewId, schemeFactory);
|
|
6777
6777
|
}
|
|
6778
6778
|
|
|
@@ -6789,7 +6789,7 @@ static std::shared_ptr<CEFView> createCEFView(uint32_t webviewId,
|
|
|
6789
6789
|
HandlePostMessage eventBridgeHandler,
|
|
6790
6790
|
HandlePostMessage bunBridgeHandler,
|
|
6791
6791
|
HandlePostMessage internalBridgeHandler,
|
|
6792
|
-
const char *
|
|
6792
|
+
const char *sparkbunPreloadScript,
|
|
6793
6793
|
const char *customPreloadScript,
|
|
6794
6794
|
bool transparent,
|
|
6795
6795
|
bool sandbox) {
|
|
@@ -6831,7 +6831,7 @@ static std::shared_ptr<CEFView> createCEFView(uint32_t webviewId,
|
|
|
6831
6831
|
}
|
|
6832
6832
|
|
|
6833
6833
|
// Create CEF client with bridge handlers
|
|
6834
|
-
auto client = new
|
|
6834
|
+
auto client = new SparkBunCefClient(webviewId, eventBridgeHandler, bunBridgeHandler, internalBridgeHandler, sandbox);
|
|
6835
6835
|
|
|
6836
6836
|
// Configure OSR mode for transparent windows
|
|
6837
6837
|
if (transparent) {
|
|
@@ -6852,8 +6852,8 @@ static std::shared_ptr<CEFView> createCEFView(uint32_t webviewId,
|
|
|
6852
6852
|
}
|
|
6853
6853
|
|
|
6854
6854
|
// Set up preload scripts
|
|
6855
|
-
if (
|
|
6856
|
-
client->AddPreloadScript(std::string(
|
|
6855
|
+
if (sparkbunPreloadScript && strlen(sparkbunPreloadScript) > 0) {
|
|
6856
|
+
client->AddPreloadScript(std::string(sparkbunPreloadScript));
|
|
6857
6857
|
}
|
|
6858
6858
|
if (customPreloadScript && strlen(customPreloadScript) > 0) {
|
|
6859
6859
|
client->UpdateCustomPreloadScript(std::string(customPreloadScript));
|
|
@@ -6999,18 +6999,18 @@ BOOL WINAPI ConsoleControlHandler(DWORD dwCtrlType) {
|
|
|
6999
6999
|
|
|
7000
7000
|
extern "C" {
|
|
7001
7001
|
|
|
7002
|
-
|
|
7002
|
+
SPARKBUN_EXPORT void startEventLoop(const char* identifier, const char* name, const char* channel) {
|
|
7003
7003
|
g_mainThreadId = GetCurrentThreadId();
|
|
7004
7004
|
|
|
7005
7005
|
// Store identifier, name, and channel globally for use in CEF initialization
|
|
7006
7006
|
if (identifier && identifier[0]) {
|
|
7007
|
-
|
|
7007
|
+
g_sparkbunIdentifier = std::string(identifier);
|
|
7008
7008
|
}
|
|
7009
7009
|
if (name && name[0]) {
|
|
7010
|
-
|
|
7010
|
+
g_sparkbunName = std::string(name);
|
|
7011
7011
|
}
|
|
7012
7012
|
if (channel && channel[0]) {
|
|
7013
|
-
|
|
7013
|
+
g_sparkbunChannel = std::string(channel);
|
|
7014
7014
|
}
|
|
7015
7015
|
|
|
7016
7016
|
// Set up console control handler for graceful shutdown on Ctrl+C
|
|
@@ -7119,7 +7119,7 @@ ELECTROBUN_EXPORT void startEventLoop(const char* identifier, const char* name,
|
|
|
7119
7119
|
}
|
|
7120
7120
|
|
|
7121
7121
|
|
|
7122
|
-
|
|
7122
|
+
SPARKBUN_EXPORT void stopEventLoop() {
|
|
7123
7123
|
if (g_eventLoopStopping.exchange(true)) {
|
|
7124
7124
|
return;
|
|
7125
7125
|
}
|
|
@@ -7138,12 +7138,12 @@ ELECTROBUN_EXPORT void stopEventLoop() {
|
|
|
7138
7138
|
}
|
|
7139
7139
|
}
|
|
7140
7140
|
|
|
7141
|
-
|
|
7141
|
+
SPARKBUN_EXPORT void killApp() {
|
|
7142
7142
|
// Deprecated - delegates to stopEventLoop for backward compatibility
|
|
7143
7143
|
stopEventLoop();
|
|
7144
7144
|
}
|
|
7145
7145
|
|
|
7146
|
-
|
|
7146
|
+
SPARKBUN_EXPORT void waitForShutdownComplete(int timeoutMs) {
|
|
7147
7147
|
int waited = 0;
|
|
7148
7148
|
while (!g_shutdownComplete.load() && waited < timeoutMs) {
|
|
7149
7149
|
Sleep(10);
|
|
@@ -7151,15 +7151,15 @@ ELECTROBUN_EXPORT void waitForShutdownComplete(int timeoutMs) {
|
|
|
7151
7151
|
}
|
|
7152
7152
|
}
|
|
7153
7153
|
|
|
7154
|
-
|
|
7154
|
+
SPARKBUN_EXPORT void forceExit(int code) {
|
|
7155
7155
|
_exit(code);
|
|
7156
7156
|
}
|
|
7157
7157
|
|
|
7158
|
-
|
|
7158
|
+
SPARKBUN_EXPORT void setQuitRequestedHandler(QuitRequestedHandler handler) {
|
|
7159
7159
|
g_quitRequestedHandler = handler;
|
|
7160
7160
|
}
|
|
7161
7161
|
|
|
7162
|
-
|
|
7162
|
+
SPARKBUN_EXPORT void shutdownApplication() {
|
|
7163
7163
|
// Deprecated - use stopEventLoop() instead
|
|
7164
7164
|
stopEventLoop();
|
|
7165
7165
|
}
|
|
@@ -7170,13 +7170,13 @@ static struct {
|
|
|
7170
7170
|
bool startPassthrough;
|
|
7171
7171
|
} g_nextWebviewFlags = {false, false};
|
|
7172
7172
|
|
|
7173
|
-
|
|
7173
|
+
SPARKBUN_EXPORT void setNextWebviewFlags(bool startTransparent, bool startPassthrough) {
|
|
7174
7174
|
g_nextWebviewFlags.startTransparent = startTransparent;
|
|
7175
7175
|
g_nextWebviewFlags.startPassthrough = startPassthrough;
|
|
7176
7176
|
}
|
|
7177
7177
|
|
|
7178
7178
|
// Clean, elegant initWebview function - Windows version matching Mac pattern
|
|
7179
|
-
|
|
7179
|
+
SPARKBUN_EXPORT AbstractView* initWebview(uint32_t webviewId,
|
|
7180
7180
|
NSWindow *window, // Actually HWND on Windows
|
|
7181
7181
|
const char *renderer,
|
|
7182
7182
|
const char *url,
|
|
@@ -7189,7 +7189,7 @@ ELECTROBUN_EXPORT AbstractView* initWebview(uint32_t webviewId,
|
|
|
7189
7189
|
HandlePostMessage eventBridgeHandler,
|
|
7190
7190
|
HandlePostMessage bunBridgeHandler,
|
|
7191
7191
|
HandlePostMessage internalBridgeHandler,
|
|
7192
|
-
const char *
|
|
7192
|
+
const char *sparkbunPreloadScript,
|
|
7193
7193
|
const char *customPreloadScript,
|
|
7194
7194
|
const char *viewsRoot,
|
|
7195
7195
|
bool transparent,
|
|
@@ -7213,13 +7213,13 @@ ELECTROBUN_EXPORT AbstractView* initWebview(uint32_t webviewId,
|
|
|
7213
7213
|
auto cefView = createCEFView(webviewId, hwnd, url, x, y, width, height, autoResize,
|
|
7214
7214
|
partitionIdentifier, navigationCallback, webviewEventHandler,
|
|
7215
7215
|
eventBridgeHandler, bunBridgeHandler, internalBridgeHandler,
|
|
7216
|
-
|
|
7216
|
+
sparkbunPreloadScript, customPreloadScript, transparent, sandbox);
|
|
7217
7217
|
view = cefView.get();
|
|
7218
7218
|
} else {
|
|
7219
7219
|
auto webview2View = createWebView2View(webviewId, hwnd, url, x, y, width, height, autoResize,
|
|
7220
7220
|
partitionIdentifier, navigationCallback, webviewEventHandler,
|
|
7221
7221
|
eventBridgeHandler, bunBridgeHandler, internalBridgeHandler,
|
|
7222
|
-
|
|
7222
|
+
sparkbunPreloadScript, customPreloadScript, transparent, sandbox);
|
|
7223
7223
|
view = webview2View.get();
|
|
7224
7224
|
}
|
|
7225
7225
|
|
|
@@ -7237,7 +7237,7 @@ ELECTROBUN_EXPORT AbstractView* initWebview(uint32_t webviewId,
|
|
|
7237
7237
|
|
|
7238
7238
|
}
|
|
7239
7239
|
|
|
7240
|
-
|
|
7240
|
+
SPARKBUN_EXPORT AbstractView* initWGPUView(uint32_t webviewId,
|
|
7241
7241
|
NSWindow *window, // Actually HWND on Windows
|
|
7242
7242
|
double x, double y,
|
|
7243
7243
|
double width, double height,
|
|
@@ -7319,7 +7319,7 @@ ELECTROBUN_EXPORT AbstractView* initWGPUView(uint32_t webviewId,
|
|
|
7319
7319
|
return view.get();
|
|
7320
7320
|
}
|
|
7321
7321
|
|
|
7322
|
-
|
|
7322
|
+
SPARKBUN_EXPORT MyScriptMessageHandlerWithReply* addScriptMessageHandlerWithReply(WKWebView *webView,
|
|
7323
7323
|
uint32_t webviewId,
|
|
7324
7324
|
const char *name,
|
|
7325
7325
|
HandlePostMessageWithReply callback) {
|
|
@@ -7329,7 +7329,7 @@ ELECTROBUN_EXPORT MyScriptMessageHandlerWithReply* addScriptMessageHandlerWithRe
|
|
|
7329
7329
|
handler->webviewId = webviewId;
|
|
7330
7330
|
return handler;
|
|
7331
7331
|
}
|
|
7332
|
-
|
|
7332
|
+
SPARKBUN_EXPORT void loadURLInWebView(AbstractView *abstractView, const char *urlString) {
|
|
7333
7333
|
if (!abstractView || !urlString) {
|
|
7334
7334
|
::log("ERROR: Invalid parameters passed to loadURLInWebView");
|
|
7335
7335
|
return;
|
|
@@ -7340,7 +7340,7 @@ ELECTROBUN_EXPORT void loadURLInWebView(AbstractView *abstractView, const char *
|
|
|
7340
7340
|
abstractView->loadURL(urlString);
|
|
7341
7341
|
}
|
|
7342
7342
|
|
|
7343
|
-
|
|
7343
|
+
SPARKBUN_EXPORT void wgpuViewSetFrame(AbstractView *abstractView, double x, double y, double width, double height) {
|
|
7344
7344
|
if (!abstractView) return;
|
|
7345
7345
|
RECT bounds = {(LONG)x, (LONG)y, (LONG)(x + width), (LONG)(y + height)};
|
|
7346
7346
|
abstractView->storePendingResize(bounds, "");
|
|
@@ -7348,28 +7348,28 @@ ELECTROBUN_EXPORT void wgpuViewSetFrame(AbstractView *abstractView, double x, do
|
|
|
7348
7348
|
schedulePendingResizeDrain();
|
|
7349
7349
|
}
|
|
7350
7350
|
|
|
7351
|
-
|
|
7351
|
+
SPARKBUN_EXPORT void wgpuViewSetTransparent(AbstractView *abstractView, BOOL transparent) {
|
|
7352
7352
|
if (!abstractView) return;
|
|
7353
7353
|
MainThreadDispatcher::dispatch_sync([abstractView, transparent]() {
|
|
7354
7354
|
abstractView->setTransparent(transparent);
|
|
7355
7355
|
});
|
|
7356
7356
|
}
|
|
7357
7357
|
|
|
7358
|
-
|
|
7358
|
+
SPARKBUN_EXPORT void wgpuViewSetPassthrough(AbstractView *abstractView, BOOL enablePassthrough) {
|
|
7359
7359
|
if (!abstractView) return;
|
|
7360
7360
|
MainThreadDispatcher::dispatch_sync([abstractView, enablePassthrough]() {
|
|
7361
7361
|
abstractView->setPassthrough(enablePassthrough);
|
|
7362
7362
|
});
|
|
7363
7363
|
}
|
|
7364
7364
|
|
|
7365
|
-
|
|
7365
|
+
SPARKBUN_EXPORT void wgpuViewSetHidden(AbstractView *abstractView, BOOL hidden) {
|
|
7366
7366
|
if (!abstractView) return;
|
|
7367
7367
|
MainThreadDispatcher::dispatch_sync([abstractView, hidden]() {
|
|
7368
7368
|
abstractView->setHidden(hidden);
|
|
7369
7369
|
});
|
|
7370
7370
|
}
|
|
7371
7371
|
|
|
7372
|
-
|
|
7372
|
+
SPARKBUN_EXPORT void wgpuViewRemove(AbstractView *abstractView) {
|
|
7373
7373
|
if (!abstractView) return;
|
|
7374
7374
|
uint32_t viewId = abstractView->webviewId;
|
|
7375
7375
|
MainThreadDispatcher::dispatch_sync([abstractView]() {
|
|
@@ -7381,7 +7381,7 @@ ELECTROBUN_EXPORT void wgpuViewRemove(AbstractView *abstractView) {
|
|
|
7381
7381
|
}
|
|
7382
7382
|
}
|
|
7383
7383
|
|
|
7384
|
-
|
|
7384
|
+
SPARKBUN_EXPORT void* wgpuViewGetNativeHandle(AbstractView *abstractView) {
|
|
7385
7385
|
if (!abstractView) return nullptr;
|
|
7386
7386
|
return abstractView->hwnd;
|
|
7387
7387
|
}
|
|
@@ -8128,7 +8128,7 @@ static void gpuTestRequestDeviceCallback(WGPURequestDeviceStatus status, WGPUDev
|
|
|
8128
8128
|
state->device = device;
|
|
8129
8129
|
|
|
8130
8130
|
if (p_wgpuDeviceSetLabel) {
|
|
8131
|
-
WGPUStringView label = { "
|
|
8131
|
+
WGPUStringView label = { "SparkBun WGPU Device", WGPU_STRLEN };
|
|
8132
8132
|
p_wgpuDeviceSetLabel(device, label);
|
|
8133
8133
|
}
|
|
8134
8134
|
state->queue = p_wgpuDeviceGetQueue(device);
|
|
@@ -8159,7 +8159,7 @@ static void runOnMainThreadSyncVoid(std::function<void()> fn) {
|
|
|
8159
8159
|
MainThreadDispatcher::dispatch_sync([&]() { fn(); });
|
|
8160
8160
|
}
|
|
8161
8161
|
|
|
8162
|
-
|
|
8162
|
+
SPARKBUN_EXPORT void* wgpuInstanceCreateSurfaceMainThread(void* instance, void* descriptor) {
|
|
8163
8163
|
if (!ensureWgpuSymbols()) return nullptr;
|
|
8164
8164
|
return runOnMainThreadSyncPtr([&]() -> void* {
|
|
8165
8165
|
return p_wgpuInstanceCreateSurface(instance, descriptor);
|
|
@@ -8170,7 +8170,7 @@ ELECTROBUN_EXPORT void* wgpuInstanceCreateSurfaceMainThread(void* instance, void
|
|
|
8170
8170
|
static std::map<void*, HWND> g_surfaceToHwnd;
|
|
8171
8171
|
static std::mutex g_surfaceToHwndMutex;
|
|
8172
8172
|
|
|
8173
|
-
|
|
8173
|
+
SPARKBUN_EXPORT void* wgpuCreateSurfaceForView(void* wgpuInstance, AbstractView* abstractView) {
|
|
8174
8174
|
if (!wgpuInstance || !abstractView || !abstractView->hwnd) {
|
|
8175
8175
|
printf("[WGPU] createSurfaceForView: null check failed (inst=%p view=%p hwnd=%p)\n",
|
|
8176
8176
|
wgpuInstance, abstractView, abstractView ? abstractView->hwnd : nullptr);
|
|
@@ -8434,7 +8434,7 @@ static bool initDCompBridgeForSurface(void* surface, void* devicePtr, uint32_t w
|
|
|
8434
8434
|
return true;
|
|
8435
8435
|
}
|
|
8436
8436
|
|
|
8437
|
-
|
|
8437
|
+
SPARKBUN_EXPORT void wgpuSurfaceConfigureMainThread(void* surface, void* config) {
|
|
8438
8438
|
if (!ensureWgpuSymbols()) return;
|
|
8439
8439
|
runOnMainThreadSyncVoid([&]() { p_wgpuSurfaceConfigure(surface, config); });
|
|
8440
8440
|
|
|
@@ -8466,7 +8466,7 @@ ELECTROBUN_EXPORT void wgpuSurfaceConfigureMainThread(void* surface, void* confi
|
|
|
8466
8466
|
initDCompBridgeForSurface(surface, devicePtr, width, height);
|
|
8467
8467
|
}
|
|
8468
8468
|
|
|
8469
|
-
|
|
8469
|
+
SPARKBUN_EXPORT void wgpuSurfaceGetCurrentTextureMainThread(void* surface, void* surfaceTexture) {
|
|
8470
8470
|
if (!ensureWgpuSymbols()) return;
|
|
8471
8471
|
|
|
8472
8472
|
// Check for DComp bridge
|
|
@@ -8539,7 +8539,7 @@ ELECTROBUN_EXPORT void wgpuSurfaceGetCurrentTextureMainThread(void* surface, voi
|
|
|
8539
8539
|
runOnMainThreadSyncVoid([&]() { p_wgpuSurfaceGetCurrentTexture(surface, surfaceTexture); });
|
|
8540
8540
|
}
|
|
8541
8541
|
|
|
8542
|
-
|
|
8542
|
+
SPARKBUN_EXPORT int32_t wgpuSurfacePresentMainThread(void* surface) {
|
|
8543
8543
|
if (!ensureWgpuSymbols()) return 0;
|
|
8544
8544
|
|
|
8545
8545
|
// Check for DComp bridge
|
|
@@ -8657,7 +8657,7 @@ ELECTROBUN_EXPORT int32_t wgpuSurfacePresentMainThread(void* surface) {
|
|
|
8657
8657
|
});
|
|
8658
8658
|
}
|
|
8659
8659
|
|
|
8660
|
-
|
|
8660
|
+
SPARKBUN_EXPORT uint64_t wgpuQueueOnSubmittedWorkDoneShim(void* queue, void* callbackInfo) {
|
|
8661
8661
|
if (!ensureWgpuSymbols()) return 0;
|
|
8662
8662
|
if (!callbackInfo) return 0;
|
|
8663
8663
|
WGPUQueueWorkDoneCallbackInfo info = *(WGPUQueueWorkDoneCallbackInfo*)callbackInfo;
|
|
@@ -8665,7 +8665,7 @@ ELECTROBUN_EXPORT uint64_t wgpuQueueOnSubmittedWorkDoneShim(void* queue, void* c
|
|
|
8665
8665
|
return future.id;
|
|
8666
8666
|
}
|
|
8667
8667
|
|
|
8668
|
-
|
|
8668
|
+
SPARKBUN_EXPORT uint64_t wgpuBufferMapAsyncShim(void* buffer, uint64_t mode, uint64_t offset, uint64_t size, void* callbackInfo) {
|
|
8669
8669
|
if (!ensureWgpuSymbols()) return 0;
|
|
8670
8670
|
if (!callbackInfo) return 0;
|
|
8671
8671
|
WGPUBufferMapCallbackInfo info = *(WGPUBufferMapCallbackInfo*)callbackInfo;
|
|
@@ -8673,7 +8673,7 @@ ELECTROBUN_EXPORT uint64_t wgpuBufferMapAsyncShim(void* buffer, uint64_t mode, u
|
|
|
8673
8673
|
return future.id;
|
|
8674
8674
|
}
|
|
8675
8675
|
|
|
8676
|
-
|
|
8676
|
+
SPARKBUN_EXPORT int32_t wgpuInstanceWaitAnyShim(void* instance, uint64_t futureId, uint64_t timeoutNS) {
|
|
8677
8677
|
if (!ensureWgpuSymbols()) return 0;
|
|
8678
8678
|
if (!instance || !futureId) return 0;
|
|
8679
8679
|
WGPUFutureWaitInfo info;
|
|
@@ -8684,7 +8684,7 @@ ELECTROBUN_EXPORT int32_t wgpuInstanceWaitAnyShim(void* instance, uint64_t futur
|
|
|
8684
8684
|
return 0;
|
|
8685
8685
|
}
|
|
8686
8686
|
|
|
8687
|
-
|
|
8687
|
+
SPARKBUN_EXPORT uint8_t* wgpuBufferReadSyncShim(
|
|
8688
8688
|
void* instance,
|
|
8689
8689
|
void* buffer,
|
|
8690
8690
|
uint64_t offset,
|
|
@@ -8741,7 +8741,7 @@ ELECTROBUN_EXPORT uint8_t* wgpuBufferReadSyncShim(
|
|
|
8741
8741
|
return out;
|
|
8742
8742
|
}
|
|
8743
8743
|
|
|
8744
|
-
|
|
8744
|
+
SPARKBUN_EXPORT int32_t wgpuBufferReadSyncIntoShim(
|
|
8745
8745
|
void* instance,
|
|
8746
8746
|
void* buffer,
|
|
8747
8747
|
uint64_t offset,
|
|
@@ -8836,7 +8836,7 @@ static void wgpuReadbackCallback(
|
|
|
8836
8836
|
job->done.store(1);
|
|
8837
8837
|
}
|
|
8838
8838
|
|
|
8839
|
-
|
|
8839
|
+
SPARKBUN_EXPORT void* wgpuBufferReadbackBeginShim(
|
|
8840
8840
|
void* buffer,
|
|
8841
8841
|
uint64_t offset,
|
|
8842
8842
|
uint64_t size,
|
|
@@ -8872,20 +8872,20 @@ ELECTROBUN_EXPORT void* wgpuBufferReadbackBeginShim(
|
|
|
8872
8872
|
return job;
|
|
8873
8873
|
}
|
|
8874
8874
|
|
|
8875
|
-
|
|
8875
|
+
SPARKBUN_EXPORT int32_t wgpuBufferReadbackStatusShim(void* jobPtr) {
|
|
8876
8876
|
if (!jobPtr) return 2;
|
|
8877
8877
|
WGPUReadbackJob* job = (WGPUReadbackJob*)jobPtr;
|
|
8878
8878
|
if (job->done.load() == 0) return 0;
|
|
8879
8879
|
return job->status.load();
|
|
8880
8880
|
}
|
|
8881
8881
|
|
|
8882
|
-
|
|
8882
|
+
SPARKBUN_EXPORT void wgpuBufferReadbackFreeShim(void* jobPtr) {
|
|
8883
8883
|
if (!jobPtr) return;
|
|
8884
8884
|
WGPUReadbackJob* job = (WGPUReadbackJob*)jobPtr;
|
|
8885
8885
|
free(job);
|
|
8886
8886
|
}
|
|
8887
8887
|
|
|
8888
|
-
|
|
8888
|
+
SPARKBUN_EXPORT void wgpuRunGPUTest(void* abstractView) {
|
|
8889
8889
|
wgpu_log("WGPU test: wgpuRunGPUTest called, abstractView=%p", abstractView);
|
|
8890
8890
|
if (!abstractView) {
|
|
8891
8891
|
wgpu_log("WGPU test: abstractView is null, aborting");
|
|
@@ -8952,7 +8952,7 @@ ELECTROBUN_EXPORT void wgpuRunGPUTest(void* abstractView) {
|
|
|
8952
8952
|
});
|
|
8953
8953
|
}
|
|
8954
8954
|
|
|
8955
|
-
|
|
8955
|
+
SPARKBUN_EXPORT void wgpuToggleGPUTestShader(void* abstractView) {
|
|
8956
8956
|
if (!abstractView) return;
|
|
8957
8957
|
if (!ensureWgpuTestSymbols()) return;
|
|
8958
8958
|
|
|
@@ -8965,7 +8965,7 @@ ELECTROBUN_EXPORT void wgpuToggleGPUTestShader(void* abstractView) {
|
|
|
8965
8965
|
});
|
|
8966
8966
|
}
|
|
8967
8967
|
|
|
8968
|
-
|
|
8968
|
+
SPARKBUN_EXPORT void wgpuCreateAdapterDeviceMainThread(void* instancePtr, void* surfacePtr, void* outAdapterDevice) {
|
|
8969
8969
|
printf("[WGPU] createAdapterDeviceMainThread: instance=%p surface=%p\n", instancePtr, surfacePtr);
|
|
8970
8970
|
if (!ensureWgpuTestSymbols()) { printf("[WGPU] createAdapterDeviceMainThread: ensureWgpuTestSymbols FAILED\n"); return; }
|
|
8971
8971
|
MainThreadDispatcher::dispatch_sync([instancePtr, surfacePtr, outAdapterDevice]() {
|
|
@@ -9061,7 +9061,7 @@ ELECTROBUN_EXPORT void wgpuCreateAdapterDeviceMainThread(void* instancePtr, void
|
|
|
9061
9061
|
});
|
|
9062
9062
|
}
|
|
9063
9063
|
|
|
9064
|
-
|
|
9064
|
+
SPARKBUN_EXPORT void loadHTMLInWebView(AbstractView *abstractView, const char *htmlString) {
|
|
9065
9065
|
if (!abstractView || !htmlString) {
|
|
9066
9066
|
::log("ERROR: Invalid parameters passed to loadHTMLInWebView");
|
|
9067
9067
|
return;
|
|
@@ -9070,7 +9070,7 @@ ELECTROBUN_EXPORT void loadHTMLInWebView(AbstractView *abstractView, const char
|
|
|
9070
9070
|
abstractView->loadHTML(htmlString);
|
|
9071
9071
|
}
|
|
9072
9072
|
|
|
9073
|
-
|
|
9073
|
+
SPARKBUN_EXPORT void webviewGoBack(AbstractView *abstractView) {
|
|
9074
9074
|
if (!abstractView) {
|
|
9075
9075
|
::log("ERROR: Invalid AbstractView or webview in webviewGoBack");
|
|
9076
9076
|
return;
|
|
@@ -9079,7 +9079,7 @@ ELECTROBUN_EXPORT void webviewGoBack(AbstractView *abstractView) {
|
|
|
9079
9079
|
abstractView->goBack();
|
|
9080
9080
|
}
|
|
9081
9081
|
|
|
9082
|
-
|
|
9082
|
+
SPARKBUN_EXPORT void webviewGoForward(AbstractView *abstractView) {
|
|
9083
9083
|
if (!abstractView) {
|
|
9084
9084
|
::log("ERROR: Invalid AbstractView or webview in webviewGoForward");
|
|
9085
9085
|
return;
|
|
@@ -9088,7 +9088,7 @@ ELECTROBUN_EXPORT void webviewGoForward(AbstractView *abstractView) {
|
|
|
9088
9088
|
abstractView->goForward();
|
|
9089
9089
|
}
|
|
9090
9090
|
|
|
9091
|
-
|
|
9091
|
+
SPARKBUN_EXPORT void webviewReload(AbstractView *abstractView) {
|
|
9092
9092
|
if (!abstractView) {
|
|
9093
9093
|
::log("ERROR: Invalid AbstractView or webview in webviewReload");
|
|
9094
9094
|
return;
|
|
@@ -9097,7 +9097,7 @@ ELECTROBUN_EXPORT void webviewReload(AbstractView *abstractView) {
|
|
|
9097
9097
|
abstractView->reload();
|
|
9098
9098
|
}
|
|
9099
9099
|
|
|
9100
|
-
|
|
9100
|
+
SPARKBUN_EXPORT void webviewRemove(AbstractView *abstractView) {
|
|
9101
9101
|
if (!abstractView) {
|
|
9102
9102
|
::log("ERROR: Invalid AbstractView in webviewRemove");
|
|
9103
9103
|
return;
|
|
@@ -9106,7 +9106,7 @@ ELECTROBUN_EXPORT void webviewRemove(AbstractView *abstractView) {
|
|
|
9106
9106
|
abstractView->remove();
|
|
9107
9107
|
}
|
|
9108
9108
|
|
|
9109
|
-
|
|
9109
|
+
SPARKBUN_EXPORT BOOL webviewCanGoBack(AbstractView *abstractView) {
|
|
9110
9110
|
if (!abstractView) {
|
|
9111
9111
|
::log("ERROR: Invalid AbstractView or webview in webviewCanGoBack");
|
|
9112
9112
|
return FALSE;
|
|
@@ -9115,7 +9115,7 @@ ELECTROBUN_EXPORT BOOL webviewCanGoBack(AbstractView *abstractView) {
|
|
|
9115
9115
|
return abstractView->canGoBack();
|
|
9116
9116
|
}
|
|
9117
9117
|
|
|
9118
|
-
|
|
9118
|
+
SPARKBUN_EXPORT BOOL webviewCanGoForward(AbstractView *abstractView) {
|
|
9119
9119
|
if (!abstractView) {
|
|
9120
9120
|
::log("ERROR: Invalid AbstractView or webview in webviewCanGoForward");
|
|
9121
9121
|
return FALSE;
|
|
@@ -9124,7 +9124,7 @@ ELECTROBUN_EXPORT BOOL webviewCanGoForward(AbstractView *abstractView) {
|
|
|
9124
9124
|
return abstractView->canGoForward();
|
|
9125
9125
|
}
|
|
9126
9126
|
|
|
9127
|
-
|
|
9127
|
+
SPARKBUN_EXPORT void evaluateJavaScriptWithNoCompletion(AbstractView *abstractView, const char *script) {
|
|
9128
9128
|
if (!abstractView || !script) {
|
|
9129
9129
|
::log("ERROR: Invalid parameters passed to evaluateJavaScriptWithNoCompletion");
|
|
9130
9130
|
return;
|
|
@@ -9134,11 +9134,11 @@ ELECTROBUN_EXPORT void evaluateJavaScriptWithNoCompletion(AbstractView *abstract
|
|
|
9134
9134
|
|
|
9135
9135
|
}
|
|
9136
9136
|
|
|
9137
|
-
|
|
9137
|
+
SPARKBUN_EXPORT void testFFI(void *ptr) {
|
|
9138
9138
|
// Stub implementation
|
|
9139
9139
|
}
|
|
9140
9140
|
|
|
9141
|
-
|
|
9141
|
+
SPARKBUN_EXPORT void callAsyncJavaScript(const char *messageId,
|
|
9142
9142
|
AbstractView *abstractView,
|
|
9143
9143
|
const char *jsString,
|
|
9144
9144
|
uint32_t webviewId,
|
|
@@ -9150,7 +9150,7 @@ ELECTROBUN_EXPORT void callAsyncJavaScript(const char *messageId,
|
|
|
9150
9150
|
}
|
|
9151
9151
|
}
|
|
9152
9152
|
|
|
9153
|
-
|
|
9153
|
+
SPARKBUN_EXPORT void addPreloadScriptToWebView(AbstractView *abstractView, const char *scriptContent, BOOL forMainFrameOnly) {
|
|
9154
9154
|
if (abstractView && scriptContent) {
|
|
9155
9155
|
MainThreadDispatcher::dispatch_sync([abstractView, scriptContent]() {
|
|
9156
9156
|
abstractView->addPreloadScriptToWebView(scriptContent);
|
|
@@ -9158,7 +9158,7 @@ ELECTROBUN_EXPORT void addPreloadScriptToWebView(AbstractView *abstractView, con
|
|
|
9158
9158
|
}
|
|
9159
9159
|
}
|
|
9160
9160
|
|
|
9161
|
-
|
|
9161
|
+
SPARKBUN_EXPORT void updatePreloadScriptToWebView(AbstractView *abstractView,
|
|
9162
9162
|
const char *scriptIdentifier,
|
|
9163
9163
|
const char *scriptContent,
|
|
9164
9164
|
BOOL forMainFrameOnly) {
|
|
@@ -9169,26 +9169,26 @@ ELECTROBUN_EXPORT void updatePreloadScriptToWebView(AbstractView *abstractView,
|
|
|
9169
9169
|
}
|
|
9170
9170
|
}
|
|
9171
9171
|
|
|
9172
|
-
|
|
9172
|
+
SPARKBUN_EXPORT void invokeDecisionHandler(void (*decisionHandler)(int), int policy) {
|
|
9173
9173
|
// Stub implementation
|
|
9174
9174
|
if (decisionHandler) {
|
|
9175
9175
|
decisionHandler(policy);
|
|
9176
9176
|
}
|
|
9177
9177
|
}
|
|
9178
9178
|
|
|
9179
|
-
|
|
9179
|
+
SPARKBUN_EXPORT const char* getUrlFromNavigationAction(void *navigationAction) {
|
|
9180
9180
|
// Stub implementation
|
|
9181
9181
|
static const char* defaultUrl = "about:blank";
|
|
9182
9182
|
return defaultUrl;
|
|
9183
9183
|
}
|
|
9184
9184
|
|
|
9185
|
-
|
|
9185
|
+
SPARKBUN_EXPORT const char* getBodyFromScriptMessage(void *message) {
|
|
9186
9186
|
// Stub implementation
|
|
9187
9187
|
static const char* emptyString = "";
|
|
9188
9188
|
return emptyString;
|
|
9189
9189
|
}
|
|
9190
9190
|
|
|
9191
|
-
|
|
9191
|
+
SPARKBUN_EXPORT void webviewSetTransparent(AbstractView *abstractView, BOOL transparent) {
|
|
9192
9192
|
if (abstractView) {
|
|
9193
9193
|
// UI operations must be performed on the main thread
|
|
9194
9194
|
MainThreadDispatcher::dispatch_sync([abstractView, transparent]() {
|
|
@@ -9197,7 +9197,7 @@ ELECTROBUN_EXPORT void webviewSetTransparent(AbstractView *abstractView, BOOL tr
|
|
|
9197
9197
|
}
|
|
9198
9198
|
}
|
|
9199
9199
|
|
|
9200
|
-
|
|
9200
|
+
SPARKBUN_EXPORT void webviewSetPassthrough(AbstractView *abstractView, BOOL enablePassthrough) {
|
|
9201
9201
|
if (abstractView) {
|
|
9202
9202
|
// UI operations must be performed on the main thread
|
|
9203
9203
|
MainThreadDispatcher::dispatch_sync([abstractView, enablePassthrough]() {
|
|
@@ -9206,7 +9206,7 @@ ELECTROBUN_EXPORT void webviewSetPassthrough(AbstractView *abstractView, BOOL en
|
|
|
9206
9206
|
}
|
|
9207
9207
|
}
|
|
9208
9208
|
|
|
9209
|
-
|
|
9209
|
+
SPARKBUN_EXPORT void webviewSetHidden(AbstractView *abstractView, BOOL hidden) {
|
|
9210
9210
|
if (abstractView) {
|
|
9211
9211
|
// UI operations must be performed on the main thread
|
|
9212
9212
|
MainThreadDispatcher::dispatch_sync([abstractView, hidden]() {
|
|
@@ -9215,7 +9215,7 @@ ELECTROBUN_EXPORT void webviewSetHidden(AbstractView *abstractView, BOOL hidden)
|
|
|
9215
9215
|
}
|
|
9216
9216
|
}
|
|
9217
9217
|
|
|
9218
|
-
|
|
9218
|
+
SPARKBUN_EXPORT void setWebviewNavigationRules(AbstractView *abstractView, const char *rulesJson) {
|
|
9219
9219
|
if (abstractView) {
|
|
9220
9220
|
// UI operations must be performed on the main thread
|
|
9221
9221
|
MainThreadDispatcher::dispatch_sync([abstractView, rulesJson]() {
|
|
@@ -9224,7 +9224,7 @@ ELECTROBUN_EXPORT void setWebviewNavigationRules(AbstractView *abstractView, con
|
|
|
9224
9224
|
}
|
|
9225
9225
|
}
|
|
9226
9226
|
|
|
9227
|
-
|
|
9227
|
+
SPARKBUN_EXPORT void webviewFindInPage(AbstractView *abstractView, const char *searchText, bool forward, bool matchCase) {
|
|
9228
9228
|
if (abstractView) {
|
|
9229
9229
|
MainThreadDispatcher::dispatch_sync([abstractView, searchText, forward, matchCase]() {
|
|
9230
9230
|
abstractView->findInPage(searchText, forward, matchCase);
|
|
@@ -9250,7 +9250,7 @@ void toggleRemoteDevTools(uint32_t webviewId) {
|
|
|
9250
9250
|
openRemoteDevTools(webviewId);
|
|
9251
9251
|
}
|
|
9252
9252
|
|
|
9253
|
-
|
|
9253
|
+
SPARKBUN_EXPORT void webviewStopFind(AbstractView *abstractView) {
|
|
9254
9254
|
if (abstractView) {
|
|
9255
9255
|
MainThreadDispatcher::dispatch_sync([abstractView]() {
|
|
9256
9256
|
abstractView->stopFindInPage();
|
|
@@ -9258,7 +9258,7 @@ ELECTROBUN_EXPORT void webviewStopFind(AbstractView *abstractView) {
|
|
|
9258
9258
|
}
|
|
9259
9259
|
}
|
|
9260
9260
|
|
|
9261
|
-
|
|
9261
|
+
SPARKBUN_EXPORT void webviewOpenDevTools(AbstractView *abstractView) {
|
|
9262
9262
|
if (abstractView) {
|
|
9263
9263
|
MainThreadDispatcher::dispatch_sync([abstractView]() {
|
|
9264
9264
|
abstractView->openDevTools();
|
|
@@ -9266,7 +9266,7 @@ ELECTROBUN_EXPORT void webviewOpenDevTools(AbstractView *abstractView) {
|
|
|
9266
9266
|
}
|
|
9267
9267
|
}
|
|
9268
9268
|
|
|
9269
|
-
|
|
9269
|
+
SPARKBUN_EXPORT void webviewCloseDevTools(AbstractView *abstractView) {
|
|
9270
9270
|
if (abstractView) {
|
|
9271
9271
|
MainThreadDispatcher::dispatch_sync([abstractView]() {
|
|
9272
9272
|
abstractView->closeDevTools();
|
|
@@ -9274,7 +9274,7 @@ ELECTROBUN_EXPORT void webviewCloseDevTools(AbstractView *abstractView) {
|
|
|
9274
9274
|
}
|
|
9275
9275
|
}
|
|
9276
9276
|
|
|
9277
|
-
|
|
9277
|
+
SPARKBUN_EXPORT void webviewToggleDevTools(AbstractView *abstractView) {
|
|
9278
9278
|
if (abstractView) {
|
|
9279
9279
|
MainThreadDispatcher::dispatch_sync([abstractView]() {
|
|
9280
9280
|
abstractView->toggleDevTools();
|
|
@@ -9282,23 +9282,23 @@ ELECTROBUN_EXPORT void webviewToggleDevTools(AbstractView *abstractView) {
|
|
|
9282
9282
|
}
|
|
9283
9283
|
}
|
|
9284
9284
|
|
|
9285
|
-
|
|
9285
|
+
SPARKBUN_EXPORT void webviewSetPageZoom(AbstractView *abstractView, double zoomLevel) {
|
|
9286
9286
|
// pageZoom is WebKit-specific, not available on Windows
|
|
9287
9287
|
// TODO: implement WebView2 zoom if needed
|
|
9288
9288
|
}
|
|
9289
9289
|
|
|
9290
|
-
|
|
9290
|
+
SPARKBUN_EXPORT double webviewGetPageZoom(AbstractView *abstractView) {
|
|
9291
9291
|
// pageZoom is WebKit-specific, not available on Windows
|
|
9292
9292
|
return 1.0;
|
|
9293
9293
|
}
|
|
9294
9294
|
|
|
9295
|
-
|
|
9295
|
+
SPARKBUN_EXPORT NSRect createNSRectWrapper(double x, double y, double width, double height) {
|
|
9296
9296
|
// Stub implementation
|
|
9297
9297
|
NSRect rect = {x, y, width, height};
|
|
9298
9298
|
return rect;
|
|
9299
9299
|
}
|
|
9300
9300
|
|
|
9301
|
-
|
|
9301
|
+
SPARKBUN_EXPORT NSWindow* createNSWindowWithFrameAndStyle(uint32_t windowId,
|
|
9302
9302
|
createNSWindowWithFrameAndStyleParams config,
|
|
9303
9303
|
WindowCloseHandler zigCloseHandler,
|
|
9304
9304
|
WindowMoveHandler zigMoveHandler,
|
|
@@ -9310,14 +9310,14 @@ ELECTROBUN_EXPORT NSWindow* createNSWindowWithFrameAndStyle(uint32_t windowId,
|
|
|
9310
9310
|
return new NSWindow();
|
|
9311
9311
|
}
|
|
9312
9312
|
|
|
9313
|
-
|
|
9313
|
+
SPARKBUN_EXPORT void testFFI2(void (*completionHandler)()) {
|
|
9314
9314
|
// Stub implementation
|
|
9315
9315
|
if (completionHandler) {
|
|
9316
9316
|
completionHandler();
|
|
9317
9317
|
}
|
|
9318
9318
|
}
|
|
9319
9319
|
|
|
9320
|
-
|
|
9320
|
+
SPARKBUN_EXPORT HWND createWindowWithFrameAndStyleFromWorker(
|
|
9321
9321
|
uint32_t windowId,
|
|
9322
9322
|
double x, double y,
|
|
9323
9323
|
double width, double height,
|
|
@@ -9484,7 +9484,7 @@ static void activateVisibleWindow(HWND hwnd) {
|
|
|
9484
9484
|
SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW);
|
|
9485
9485
|
}
|
|
9486
9486
|
|
|
9487
|
-
|
|
9487
|
+
SPARKBUN_EXPORT void showWindow(void *window, bool activate) {
|
|
9488
9488
|
// On Windows, window ptr is actually HWND
|
|
9489
9489
|
HWND hwnd = reinterpret_cast<HWND>(window);
|
|
9490
9490
|
|
|
@@ -9510,7 +9510,7 @@ ELECTROBUN_EXPORT void showWindow(void *window, bool activate) {
|
|
|
9510
9510
|
});
|
|
9511
9511
|
}
|
|
9512
9512
|
|
|
9513
|
-
|
|
9513
|
+
SPARKBUN_EXPORT void activateWindow(void *window) {
|
|
9514
9514
|
HWND hwnd = reinterpret_cast<HWND>(window);
|
|
9515
9515
|
|
|
9516
9516
|
if (!IsWindow(hwnd)) {
|
|
@@ -9523,7 +9523,7 @@ ELECTROBUN_EXPORT void activateWindow(void *window) {
|
|
|
9523
9523
|
});
|
|
9524
9524
|
}
|
|
9525
9525
|
|
|
9526
|
-
|
|
9526
|
+
SPARKBUN_EXPORT void hideWindow(void *window) {
|
|
9527
9527
|
HWND hwnd = reinterpret_cast<HWND>(window);
|
|
9528
9528
|
|
|
9529
9529
|
if (!IsWindow(hwnd)) {
|
|
@@ -9536,7 +9536,7 @@ ELECTROBUN_EXPORT void hideWindow(void *window) {
|
|
|
9536
9536
|
});
|
|
9537
9537
|
}
|
|
9538
9538
|
|
|
9539
|
-
|
|
9539
|
+
SPARKBUN_EXPORT void setWindowTitle(NSWindow *window, const char *title) {
|
|
9540
9540
|
// On Windows, NSWindow* is actually HWND
|
|
9541
9541
|
HWND hwnd = reinterpret_cast<HWND>(window);
|
|
9542
9542
|
|
|
@@ -9579,7 +9579,7 @@ ELECTROBUN_EXPORT void setWindowTitle(NSWindow *window, const char *title) {
|
|
|
9579
9579
|
});
|
|
9580
9580
|
}
|
|
9581
9581
|
|
|
9582
|
-
|
|
9582
|
+
SPARKBUN_EXPORT void closeWindow(NSWindow *window) {
|
|
9583
9583
|
// On Windows, NSWindow* is actually HWND
|
|
9584
9584
|
HWND hwnd = reinterpret_cast<HWND>(window);
|
|
9585
9585
|
|
|
@@ -9620,7 +9620,7 @@ ELECTROBUN_EXPORT void closeWindow(NSWindow *window) {
|
|
|
9620
9620
|
});
|
|
9621
9621
|
}
|
|
9622
9622
|
|
|
9623
|
-
|
|
9623
|
+
SPARKBUN_EXPORT void minimizeWindow(NSWindow *window) {
|
|
9624
9624
|
HWND hwnd = reinterpret_cast<HWND>(window);
|
|
9625
9625
|
|
|
9626
9626
|
if (!IsWindow(hwnd)) {
|
|
@@ -9633,7 +9633,7 @@ ELECTROBUN_EXPORT void minimizeWindow(NSWindow *window) {
|
|
|
9633
9633
|
});
|
|
9634
9634
|
}
|
|
9635
9635
|
|
|
9636
|
-
|
|
9636
|
+
SPARKBUN_EXPORT void restoreWindow(NSWindow *window) {
|
|
9637
9637
|
HWND hwnd = reinterpret_cast<HWND>(window);
|
|
9638
9638
|
|
|
9639
9639
|
if (!IsWindow(hwnd)) {
|
|
@@ -9646,7 +9646,7 @@ ELECTROBUN_EXPORT void restoreWindow(NSWindow *window) {
|
|
|
9646
9646
|
});
|
|
9647
9647
|
}
|
|
9648
9648
|
|
|
9649
|
-
|
|
9649
|
+
SPARKBUN_EXPORT bool isWindowMinimized(NSWindow *window) {
|
|
9650
9650
|
HWND hwnd = reinterpret_cast<HWND>(window);
|
|
9651
9651
|
|
|
9652
9652
|
if (!IsWindow(hwnd)) {
|
|
@@ -9656,7 +9656,7 @@ ELECTROBUN_EXPORT bool isWindowMinimized(NSWindow *window) {
|
|
|
9656
9656
|
return IsIconic(hwnd) != 0;
|
|
9657
9657
|
}
|
|
9658
9658
|
|
|
9659
|
-
|
|
9659
|
+
SPARKBUN_EXPORT void maximizeWindow(NSWindow *window) {
|
|
9660
9660
|
HWND hwnd = reinterpret_cast<HWND>(window);
|
|
9661
9661
|
|
|
9662
9662
|
if (!IsWindow(hwnd)) {
|
|
@@ -9669,7 +9669,7 @@ ELECTROBUN_EXPORT void maximizeWindow(NSWindow *window) {
|
|
|
9669
9669
|
});
|
|
9670
9670
|
}
|
|
9671
9671
|
|
|
9672
|
-
|
|
9672
|
+
SPARKBUN_EXPORT void unmaximizeWindow(NSWindow *window) {
|
|
9673
9673
|
HWND hwnd = reinterpret_cast<HWND>(window);
|
|
9674
9674
|
|
|
9675
9675
|
if (!IsWindow(hwnd)) {
|
|
@@ -9682,7 +9682,7 @@ ELECTROBUN_EXPORT void unmaximizeWindow(NSWindow *window) {
|
|
|
9682
9682
|
});
|
|
9683
9683
|
}
|
|
9684
9684
|
|
|
9685
|
-
|
|
9685
|
+
SPARKBUN_EXPORT bool isWindowMaximized(NSWindow *window) {
|
|
9686
9686
|
HWND hwnd = reinterpret_cast<HWND>(window);
|
|
9687
9687
|
|
|
9688
9688
|
if (!IsWindow(hwnd)) {
|
|
@@ -9692,7 +9692,7 @@ ELECTROBUN_EXPORT bool isWindowMaximized(NSWindow *window) {
|
|
|
9692
9692
|
return IsZoomed(hwnd) != 0;
|
|
9693
9693
|
}
|
|
9694
9694
|
|
|
9695
|
-
|
|
9695
|
+
SPARKBUN_EXPORT void setWindowFullScreen(NSWindow *window, bool fullScreen) {
|
|
9696
9696
|
HWND hwnd = reinterpret_cast<HWND>(window);
|
|
9697
9697
|
|
|
9698
9698
|
if (!IsWindow(hwnd)) {
|
|
@@ -9746,7 +9746,7 @@ ELECTROBUN_EXPORT void setWindowFullScreen(NSWindow *window, bool fullScreen) {
|
|
|
9746
9746
|
});
|
|
9747
9747
|
}
|
|
9748
9748
|
|
|
9749
|
-
|
|
9749
|
+
SPARKBUN_EXPORT bool isWindowFullScreen(NSWindow *window) {
|
|
9750
9750
|
HWND hwnd = reinterpret_cast<HWND>(window);
|
|
9751
9751
|
|
|
9752
9752
|
if (!IsWindow(hwnd)) {
|
|
@@ -9757,7 +9757,7 @@ ELECTROBUN_EXPORT bool isWindowFullScreen(NSWindow *window) {
|
|
|
9757
9757
|
return (style & WS_POPUP) && !(style & WS_OVERLAPPEDWINDOW);
|
|
9758
9758
|
}
|
|
9759
9759
|
|
|
9760
|
-
|
|
9760
|
+
SPARKBUN_EXPORT void setWindowAlwaysOnTop(NSWindow *window, bool alwaysOnTop) {
|
|
9761
9761
|
HWND hwnd = reinterpret_cast<HWND>(window);
|
|
9762
9762
|
|
|
9763
9763
|
if (!IsWindow(hwnd)) {
|
|
@@ -9773,7 +9773,7 @@ ELECTROBUN_EXPORT void setWindowAlwaysOnTop(NSWindow *window, bool alwaysOnTop)
|
|
|
9773
9773
|
});
|
|
9774
9774
|
}
|
|
9775
9775
|
|
|
9776
|
-
|
|
9776
|
+
SPARKBUN_EXPORT bool isWindowAlwaysOnTop(NSWindow *window) {
|
|
9777
9777
|
HWND hwnd = reinterpret_cast<HWND>(window);
|
|
9778
9778
|
|
|
9779
9779
|
if (!IsWindow(hwnd)) {
|
|
@@ -9784,44 +9784,44 @@ ELECTROBUN_EXPORT bool isWindowAlwaysOnTop(NSWindow *window) {
|
|
|
9784
9784
|
return (exStyle & WS_EX_TOPMOST) != 0;
|
|
9785
9785
|
}
|
|
9786
9786
|
|
|
9787
|
-
|
|
9787
|
+
SPARKBUN_EXPORT void setWindowVisibleOnAllWorkspaces(NSWindow *window, bool visible) {
|
|
9788
9788
|
// Not applicable on Windows - no-op
|
|
9789
9789
|
}
|
|
9790
9790
|
|
|
9791
|
-
|
|
9791
|
+
SPARKBUN_EXPORT bool isWindowVisibleOnAllWorkspaces(NSWindow *window) {
|
|
9792
9792
|
// Not applicable on Windows
|
|
9793
9793
|
return false;
|
|
9794
9794
|
}
|
|
9795
9795
|
|
|
9796
|
-
|
|
9796
|
+
SPARKBUN_EXPORT void setWindowPosition(NSWindow *window, double x, double y) {
|
|
9797
9797
|
HWND hwnd = reinterpret_cast<HWND>(window);
|
|
9798
9798
|
if (!IsWindow(hwnd)) return;
|
|
9799
9799
|
|
|
9800
9800
|
SetWindowPos(hwnd, NULL, (int)x, (int)y, 0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
|
|
9801
9801
|
}
|
|
9802
9802
|
|
|
9803
|
-
|
|
9803
|
+
SPARKBUN_EXPORT void setWindowButtonPosition(NSWindow *window, double x, double y) {
|
|
9804
9804
|
(void)window;
|
|
9805
9805
|
(void)x;
|
|
9806
9806
|
(void)y;
|
|
9807
9807
|
// Not applicable on Windows - no-op
|
|
9808
9808
|
}
|
|
9809
9809
|
|
|
9810
|
-
|
|
9810
|
+
SPARKBUN_EXPORT void setWindowSize(NSWindow *window, double width, double height) {
|
|
9811
9811
|
HWND hwnd = reinterpret_cast<HWND>(window);
|
|
9812
9812
|
if (!IsWindow(hwnd)) return;
|
|
9813
9813
|
|
|
9814
9814
|
SetWindowPos(hwnd, NULL, 0, 0, (int)width, (int)height, SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
|
|
9815
9815
|
}
|
|
9816
9816
|
|
|
9817
|
-
|
|
9817
|
+
SPARKBUN_EXPORT void setWindowFrame(NSWindow *window, double x, double y, double width, double height) {
|
|
9818
9818
|
HWND hwnd = reinterpret_cast<HWND>(window);
|
|
9819
9819
|
if (!IsWindow(hwnd)) return;
|
|
9820
9820
|
|
|
9821
9821
|
SetWindowPos(hwnd, NULL, (int)x, (int)y, (int)width, (int)height, SWP_NOZORDER | SWP_NOACTIVATE);
|
|
9822
9822
|
}
|
|
9823
9823
|
|
|
9824
|
-
|
|
9824
|
+
SPARKBUN_EXPORT void getWindowFrame(NSWindow *window, double *outX, double *outY, double *outWidth, double *outHeight) {
|
|
9825
9825
|
HWND hwnd = reinterpret_cast<HWND>(window);
|
|
9826
9826
|
if (!IsWindow(hwnd)) {
|
|
9827
9827
|
*outX = 0;
|
|
@@ -9839,7 +9839,7 @@ ELECTROBUN_EXPORT void getWindowFrame(NSWindow *window, double *outX, double *ou
|
|
|
9839
9839
|
*outHeight = (double)(rect.bottom - rect.top);
|
|
9840
9840
|
}
|
|
9841
9841
|
|
|
9842
|
-
|
|
9842
|
+
SPARKBUN_EXPORT void resizeWebview(AbstractView *abstractView, double x, double y, double width, double height, const char *masksJson) {
|
|
9843
9843
|
if (!abstractView) {
|
|
9844
9844
|
::log("ERROR: Invalid AbstractView in resizeWebview");
|
|
9845
9845
|
return;
|
|
@@ -9856,7 +9856,7 @@ ELECTROBUN_EXPORT void resizeWebview(AbstractView *abstractView, double x, doubl
|
|
|
9856
9856
|
|
|
9857
9857
|
|
|
9858
9858
|
|
|
9859
|
-
|
|
9859
|
+
SPARKBUN_EXPORT void stopWindowMove() {
|
|
9860
9860
|
if (g_isMovingWindow) {
|
|
9861
9861
|
// Unregister raw input device
|
|
9862
9862
|
RAWINPUTDEVICE rid;
|
|
@@ -9871,7 +9871,7 @@ ELECTROBUN_EXPORT void stopWindowMove() {
|
|
|
9871
9871
|
}
|
|
9872
9872
|
}
|
|
9873
9873
|
|
|
9874
|
-
|
|
9874
|
+
SPARKBUN_EXPORT void startWindowMove(NSWindow *window) {
|
|
9875
9875
|
// On Windows, NSWindow* is actually HWND
|
|
9876
9876
|
HWND hwnd = reinterpret_cast<HWND>(window);
|
|
9877
9877
|
|
|
@@ -9905,7 +9905,7 @@ ELECTROBUN_EXPORT void startWindowMove(NSWindow *window) {
|
|
|
9905
9905
|
}
|
|
9906
9906
|
}
|
|
9907
9907
|
|
|
9908
|
-
|
|
9908
|
+
SPARKBUN_EXPORT BOOL moveToTrash(char *pathString) {
|
|
9909
9909
|
if (!pathString) {
|
|
9910
9910
|
::log("ERROR: NULL path string passed to moveToTrash");
|
|
9911
9911
|
return FALSE;
|
|
@@ -9944,7 +9944,7 @@ ELECTROBUN_EXPORT BOOL moveToTrash(char *pathString) {
|
|
|
9944
9944
|
}
|
|
9945
9945
|
}
|
|
9946
9946
|
|
|
9947
|
-
|
|
9947
|
+
SPARKBUN_EXPORT void showItemInFolder(char *path) {
|
|
9948
9948
|
if (!path) {
|
|
9949
9949
|
::log("ERROR: NULL path passed to showItemInFolder");
|
|
9950
9950
|
return;
|
|
@@ -9987,7 +9987,7 @@ ELECTROBUN_EXPORT void showItemInFolder(char *path) {
|
|
|
9987
9987
|
}
|
|
9988
9988
|
|
|
9989
9989
|
// Open a URL in the default browser or appropriate application
|
|
9990
|
-
|
|
9990
|
+
SPARKBUN_EXPORT BOOL openExternal(const char *urlString) {
|
|
9991
9991
|
if (!urlString) {
|
|
9992
9992
|
::log("ERROR: NULL URL passed to openExternal");
|
|
9993
9993
|
return FALSE;
|
|
@@ -10029,7 +10029,7 @@ ELECTROBUN_EXPORT BOOL openExternal(const char *urlString) {
|
|
|
10029
10029
|
}
|
|
10030
10030
|
|
|
10031
10031
|
// Open a file or folder with the default application
|
|
10032
|
-
|
|
10032
|
+
SPARKBUN_EXPORT BOOL openPath(const char *pathString) {
|
|
10033
10033
|
if (!pathString) {
|
|
10034
10034
|
::log("ERROR: NULL path passed to openPath");
|
|
10035
10035
|
return FALSE;
|
|
@@ -10071,7 +10071,7 @@ ELECTROBUN_EXPORT BOOL openPath(const char *pathString) {
|
|
|
10071
10071
|
}
|
|
10072
10072
|
|
|
10073
10073
|
// Show a native desktop notification using Shell_NotifyIcon balloon
|
|
10074
|
-
|
|
10074
|
+
SPARKBUN_EXPORT void showNotification(const char *title, const char *body, const char *subtitle, BOOL silent) {
|
|
10075
10075
|
if (!title) {
|
|
10076
10076
|
::log("ERROR: NULL title passed to showNotification");
|
|
10077
10077
|
return;
|
|
@@ -10138,7 +10138,7 @@ ELECTROBUN_EXPORT void showNotification(const char *title, const char *body, con
|
|
|
10138
10138
|
::log("Notification shown: " + std::string(title));
|
|
10139
10139
|
}
|
|
10140
10140
|
|
|
10141
|
-
|
|
10141
|
+
SPARKBUN_EXPORT const char* openFileDialog(const char *startingFolder,
|
|
10142
10142
|
const char *allowedFileTypes,
|
|
10143
10143
|
BOOL canChooseFiles,
|
|
10144
10144
|
BOOL canChooseDirectories,
|
|
@@ -10307,7 +10307,7 @@ ELECTROBUN_EXPORT const char* openFileDialog(const char *startingFolder,
|
|
|
10307
10307
|
return strdup(result.c_str());
|
|
10308
10308
|
}
|
|
10309
10309
|
|
|
10310
|
-
|
|
10310
|
+
SPARKBUN_EXPORT int showMessageBox(const char *type,
|
|
10311
10311
|
const char *title,
|
|
10312
10312
|
const char *message,
|
|
10313
10313
|
const char *detail,
|
|
@@ -10411,7 +10411,7 @@ ELECTROBUN_EXPORT int showMessageBox(const char *type,
|
|
|
10411
10411
|
|
|
10412
10412
|
// clipboardReadText - Read text from the system clipboard
|
|
10413
10413
|
// Returns: UTF-8 string (caller must free) or NULL if no text available
|
|
10414
|
-
|
|
10414
|
+
SPARKBUN_EXPORT const char* clipboardReadText() {
|
|
10415
10415
|
return MainThreadDispatcher::dispatch_sync([=]() -> const char* {
|
|
10416
10416
|
if (!OpenClipboard(nullptr)) {
|
|
10417
10417
|
return nullptr;
|
|
@@ -10439,7 +10439,7 @@ ELECTROBUN_EXPORT const char* clipboardReadText() {
|
|
|
10439
10439
|
}
|
|
10440
10440
|
|
|
10441
10441
|
// clipboardWriteText - Write text to the system clipboard
|
|
10442
|
-
|
|
10442
|
+
SPARKBUN_EXPORT void clipboardWriteText(const char* text) {
|
|
10443
10443
|
if (!text) return;
|
|
10444
10444
|
|
|
10445
10445
|
MainThreadDispatcher::dispatch_sync([=]() {
|
|
@@ -10467,7 +10467,7 @@ ELECTROBUN_EXPORT void clipboardWriteText(const char* text) {
|
|
|
10467
10467
|
|
|
10468
10468
|
// clipboardReadImage - Read image from clipboard as PNG data
|
|
10469
10469
|
// Returns: PNG data (caller must free) and sets outSize, or NULL if no image
|
|
10470
|
-
|
|
10470
|
+
SPARKBUN_EXPORT const uint8_t* clipboardReadImage(size_t* outSize) {
|
|
10471
10471
|
return MainThreadDispatcher::dispatch_sync([=]() -> const uint8_t* {
|
|
10472
10472
|
if (outSize) *outSize = 0;
|
|
10473
10473
|
|
|
@@ -10500,7 +10500,7 @@ ELECTROBUN_EXPORT const uint8_t* clipboardReadImage(size_t* outSize) {
|
|
|
10500
10500
|
}
|
|
10501
10501
|
|
|
10502
10502
|
// clipboardWriteImage - Write PNG image data to clipboard
|
|
10503
|
-
|
|
10503
|
+
SPARKBUN_EXPORT void clipboardWriteImage(const uint8_t* pngData, size_t size) {
|
|
10504
10504
|
if (!pngData || size == 0) return;
|
|
10505
10505
|
|
|
10506
10506
|
MainThreadDispatcher::dispatch_sync([=]() {
|
|
@@ -10528,7 +10528,7 @@ ELECTROBUN_EXPORT void clipboardWriteImage(const uint8_t* pngData, size_t size)
|
|
|
10528
10528
|
}
|
|
10529
10529
|
|
|
10530
10530
|
// clipboardClear - Clear the clipboard
|
|
10531
|
-
|
|
10531
|
+
SPARKBUN_EXPORT void clipboardClear() {
|
|
10532
10532
|
MainThreadDispatcher::dispatch_sync([=]() {
|
|
10533
10533
|
if (OpenClipboard(nullptr)) {
|
|
10534
10534
|
EmptyClipboard();
|
|
@@ -10539,7 +10539,7 @@ ELECTROBUN_EXPORT void clipboardClear() {
|
|
|
10539
10539
|
|
|
10540
10540
|
// clipboardAvailableFormats - Get available formats in clipboard
|
|
10541
10541
|
// Returns: comma-separated list of formats (caller must free)
|
|
10542
|
-
|
|
10542
|
+
SPARKBUN_EXPORT const char* clipboardAvailableFormats() {
|
|
10543
10543
|
return MainThreadDispatcher::dispatch_sync([=]() -> const char* {
|
|
10544
10544
|
if (!OpenClipboard(nullptr)) {
|
|
10545
10545
|
return strdup("");
|
|
@@ -10672,7 +10672,7 @@ LRESULT CALLBACK TrayWindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lPara
|
|
|
10672
10672
|
return DefWindowProc(hwnd, msg, wParam, lParam);
|
|
10673
10673
|
}
|
|
10674
10674
|
|
|
10675
|
-
|
|
10675
|
+
SPARKBUN_EXPORT NSStatusItem* createTray(uint32_t trayId, const char *title, const char *pathToImage, bool isTemplate,
|
|
10676
10676
|
uint32_t width, uint32_t height, ZigStatusItemHandler zigTrayItemHandler) {
|
|
10677
10677
|
|
|
10678
10678
|
return MainThreadDispatcher::dispatch_sync([=]() -> NSStatusItem* {
|
|
@@ -10798,7 +10798,7 @@ ELECTROBUN_EXPORT NSStatusItem* createTray(uint32_t trayId, const char *title, c
|
|
|
10798
10798
|
});
|
|
10799
10799
|
}
|
|
10800
10800
|
|
|
10801
|
-
|
|
10801
|
+
SPARKBUN_EXPORT void setTrayTitle(NSStatusItem *statusItem, const char *title) {
|
|
10802
10802
|
if (!statusItem) return;
|
|
10803
10803
|
|
|
10804
10804
|
MainThreadDispatcher::dispatch_sync([=]() {
|
|
@@ -10816,7 +10816,7 @@ ELECTROBUN_EXPORT void setTrayTitle(NSStatusItem *statusItem, const char *title)
|
|
|
10816
10816
|
});
|
|
10817
10817
|
}
|
|
10818
10818
|
|
|
10819
|
-
|
|
10819
|
+
SPARKBUN_EXPORT void setTrayImage(NSStatusItem *statusItem, const char *image) {
|
|
10820
10820
|
if (!statusItem) return;
|
|
10821
10821
|
|
|
10822
10822
|
MainThreadDispatcher::dispatch_sync([=]() {
|
|
@@ -10857,7 +10857,7 @@ ELECTROBUN_EXPORT void setTrayImage(NSStatusItem *statusItem, const char *image)
|
|
|
10857
10857
|
}
|
|
10858
10858
|
|
|
10859
10859
|
// Updated setTrayMenuFromJSON function
|
|
10860
|
-
|
|
10860
|
+
SPARKBUN_EXPORT void setTrayMenuFromJSON(NSStatusItem *statusItem, const char *jsonString) {
|
|
10861
10861
|
if (!statusItem || !jsonString) return;
|
|
10862
10862
|
|
|
10863
10863
|
MainThreadDispatcher::dispatch_sync([=]() {
|
|
@@ -10946,12 +10946,12 @@ void handleTrayIconMessage(HWND hwnd, WPARAM wParam, LPARAM lParam) {
|
|
|
10946
10946
|
}
|
|
10947
10947
|
}
|
|
10948
10948
|
|
|
10949
|
-
|
|
10949
|
+
SPARKBUN_EXPORT void setTrayMenu(NSStatusItem *statusItem, const char *menuConfig) {
|
|
10950
10950
|
// Delegate to JSON version for now
|
|
10951
10951
|
setTrayMenuFromJSON(statusItem, menuConfig);
|
|
10952
10952
|
}
|
|
10953
10953
|
|
|
10954
|
-
|
|
10954
|
+
SPARKBUN_EXPORT void removeTray(NSStatusItem *statusItem) {
|
|
10955
10955
|
if (!statusItem) return;
|
|
10956
10956
|
|
|
10957
10957
|
MainThreadDispatcher::dispatch_sync([=]() {
|
|
@@ -10963,12 +10963,12 @@ ELECTROBUN_EXPORT void removeTray(NSStatusItem *statusItem) {
|
|
|
10963
10963
|
});
|
|
10964
10964
|
}
|
|
10965
10965
|
|
|
10966
|
-
|
|
10966
|
+
SPARKBUN_EXPORT const char* getTrayBounds(NSStatusItem *statusItem) {
|
|
10967
10967
|
(void)statusItem;
|
|
10968
10968
|
return _strdup("{\"x\":0,\"y\":0,\"width\":0,\"height\":0}");
|
|
10969
10969
|
}
|
|
10970
10970
|
|
|
10971
|
-
|
|
10971
|
+
SPARKBUN_EXPORT void setApplicationMenu(const char *jsonString, ZigStatusItemHandler zigTrayItemHandler) {
|
|
10972
10972
|
if (!jsonString) {
|
|
10973
10973
|
::log("ERROR: NULL JSON string passed to setApplicationMenu");
|
|
10974
10974
|
return;
|
|
@@ -11040,7 +11040,7 @@ ELECTROBUN_EXPORT void setApplicationMenu(const char *jsonString, ZigStatusItemH
|
|
|
11040
11040
|
}
|
|
11041
11041
|
|
|
11042
11042
|
|
|
11043
|
-
|
|
11043
|
+
SPARKBUN_EXPORT void showContextMenu(const char *jsonString, ZigStatusItemHandler contextMenuHandler) {
|
|
11044
11044
|
if (!jsonString) {
|
|
11045
11045
|
::log("ERROR: NULL JSON string passed to showContextMenu");
|
|
11046
11046
|
return;
|
|
@@ -11103,7 +11103,7 @@ ELECTROBUN_EXPORT void showContextMenu(const char *jsonString, ZigStatusItemHand
|
|
|
11103
11103
|
});
|
|
11104
11104
|
}
|
|
11105
11105
|
|
|
11106
|
-
|
|
11106
|
+
SPARKBUN_EXPORT void getWebviewSnapshot(uint32_t hostId, uint32_t webviewId,
|
|
11107
11107
|
WKWebView *webView,
|
|
11108
11108
|
zigSnapshotCallback callback) {
|
|
11109
11109
|
// Stub implementation
|
|
@@ -11113,13 +11113,13 @@ ELECTROBUN_EXPORT void getWebviewSnapshot(uint32_t hostId, uint32_t webviewId,
|
|
|
11113
11113
|
}
|
|
11114
11114
|
}
|
|
11115
11115
|
|
|
11116
|
-
|
|
11116
|
+
SPARKBUN_EXPORT void setJSUtils(GetMimeType getMimeType, GetHTMLForWebviewSync getHTMLForWebviewSync) {
|
|
11117
11117
|
::log("setJSUtils called but using map-based approach instead of callbacks");
|
|
11118
11118
|
}
|
|
11119
11119
|
|
|
11120
11120
|
// MARK: - Webview HTML Content Management (replaces JSCallback approach)
|
|
11121
11121
|
|
|
11122
|
-
extern "C"
|
|
11122
|
+
extern "C" SPARKBUN_EXPORT void setWebviewHTMLContent(uint32_t webviewId, const char* htmlContent) {
|
|
11123
11123
|
std::lock_guard<std::mutex> lock(webviewHTMLMutex);
|
|
11124
11124
|
if (htmlContent) {
|
|
11125
11125
|
webviewHTMLContent[webviewId] = std::string(htmlContent);
|
|
@@ -11134,7 +11134,7 @@ extern "C" ELECTROBUN_EXPORT void setWebviewHTMLContent(uint32_t webviewId, cons
|
|
|
11134
11134
|
}
|
|
11135
11135
|
}
|
|
11136
11136
|
|
|
11137
|
-
extern "C"
|
|
11137
|
+
extern "C" SPARKBUN_EXPORT const char* getWebviewHTMLContent(uint32_t webviewId) {
|
|
11138
11138
|
std::lock_guard<std::mutex> lock(webviewHTMLMutex);
|
|
11139
11139
|
auto it = webviewHTMLContent.find(webviewId);
|
|
11140
11140
|
if (it != webviewHTMLContent.end()) {
|
|
@@ -11152,7 +11152,7 @@ extern "C" ELECTROBUN_EXPORT const char* getWebviewHTMLContent(uint32_t webviewI
|
|
|
11152
11152
|
}
|
|
11153
11153
|
|
|
11154
11154
|
// Adding a few Windows-specific functions for interop if needed
|
|
11155
|
-
|
|
11155
|
+
SPARKBUN_EXPORT uint32_t getWindowStyle(
|
|
11156
11156
|
bool Borderless,
|
|
11157
11157
|
bool Titled,
|
|
11158
11158
|
bool Closable,
|
|
@@ -11585,7 +11585,7 @@ static UINT getVirtualKeyCode(const std::string& key) {
|
|
|
11585
11585
|
// Parse modifiers from accelerator string for global shortcuts using the
|
|
11586
11586
|
// shared cross-platform parser. Returns MOD_CONTROL, MOD_ALT, MOD_SHIFT flags.
|
|
11587
11587
|
static UINT parseModifiers(const std::string& accelerator, std::string& outKey) {
|
|
11588
|
-
auto parts =
|
|
11588
|
+
auto parts = sparkbun::parseAccelerator(accelerator);
|
|
11589
11589
|
outKey = parts.key;
|
|
11590
11590
|
|
|
11591
11591
|
UINT modifiers = 0;
|
|
@@ -11648,11 +11648,11 @@ static void hotkeyMessageLoop() {
|
|
|
11648
11648
|
wc.cbSize = sizeof(WNDCLASSEXW);
|
|
11649
11649
|
wc.lpfnWndProc = HotkeyWndProc;
|
|
11650
11650
|
wc.hInstance = GetModuleHandle(NULL);
|
|
11651
|
-
wc.lpszClassName = L"
|
|
11651
|
+
wc.lpszClassName = L"SparkBunHotkeyWindow";
|
|
11652
11652
|
|
|
11653
11653
|
RegisterClassExW(&wc);
|
|
11654
11654
|
|
|
11655
|
-
g_hotkeyWindow = CreateWindowExW(0, L"
|
|
11655
|
+
g_hotkeyWindow = CreateWindowExW(0, L"SparkBunHotkeyWindow", L"",
|
|
11656
11656
|
0, 0, 0, 0, 0, HWND_MESSAGE, NULL, GetModuleHandle(NULL), NULL);
|
|
11657
11657
|
|
|
11658
11658
|
if (!g_hotkeyWindow) {
|
|
@@ -11671,7 +11671,7 @@ static void hotkeyMessageLoop() {
|
|
|
11671
11671
|
}
|
|
11672
11672
|
|
|
11673
11673
|
// Set the callback for global shortcut events
|
|
11674
|
-
extern "C"
|
|
11674
|
+
extern "C" SPARKBUN_EXPORT void setGlobalShortcutCallback(GlobalShortcutCallback callback) {
|
|
11675
11675
|
g_globalShortcutCallback = callback;
|
|
11676
11676
|
|
|
11677
11677
|
// Start the hotkey message loop thread if not running
|
|
@@ -11686,7 +11686,7 @@ extern "C" ELECTROBUN_EXPORT void setGlobalShortcutCallback(GlobalShortcutCallba
|
|
|
11686
11686
|
}
|
|
11687
11687
|
|
|
11688
11688
|
// Register a global keyboard shortcut
|
|
11689
|
-
extern "C"
|
|
11689
|
+
extern "C" SPARKBUN_EXPORT BOOL registerGlobalShortcut(const char* accelerator) {
|
|
11690
11690
|
if (!accelerator) {
|
|
11691
11691
|
::log("ERROR: Cannot register shortcut - invalid accelerator");
|
|
11692
11692
|
return FALSE;
|
|
@@ -11758,7 +11758,7 @@ extern "C" ELECTROBUN_EXPORT BOOL registerGlobalShortcut(const char* accelerator
|
|
|
11758
11758
|
}
|
|
11759
11759
|
|
|
11760
11760
|
// Unregister a global keyboard shortcut
|
|
11761
|
-
extern "C"
|
|
11761
|
+
extern "C" SPARKBUN_EXPORT BOOL unregisterGlobalShortcut(const char* accelerator) {
|
|
11762
11762
|
if (!accelerator) return FALSE;
|
|
11763
11763
|
|
|
11764
11764
|
std::string accelStr(accelerator);
|
|
@@ -11784,14 +11784,14 @@ extern "C" ELECTROBUN_EXPORT BOOL unregisterGlobalShortcut(const char* accelerat
|
|
|
11784
11784
|
}
|
|
11785
11785
|
|
|
11786
11786
|
// Unregister all global keyboard shortcuts
|
|
11787
|
-
extern "C"
|
|
11787
|
+
extern "C" SPARKBUN_EXPORT void unregisterAllGlobalShortcuts() {
|
|
11788
11788
|
if (g_hotkeyWindow) {
|
|
11789
11789
|
PostMessage(g_hotkeyWindow, WM_UNREGISTER_ALL_HOTKEYS, 0, 0);
|
|
11790
11790
|
}
|
|
11791
11791
|
}
|
|
11792
11792
|
|
|
11793
11793
|
// Check if a shortcut is registered
|
|
11794
|
-
extern "C"
|
|
11794
|
+
extern "C" SPARKBUN_EXPORT BOOL isGlobalShortcutRegistered(const char* accelerator) {
|
|
11795
11795
|
if (!accelerator) return FALSE;
|
|
11796
11796
|
|
|
11797
11797
|
std::string accelStr(accelerator);
|
|
@@ -11868,7 +11868,7 @@ static BOOL CALLBACK MonitorEnumProc(HMONITOR hMonitor, HDC hdcMonitor, LPRECT l
|
|
|
11868
11868
|
}
|
|
11869
11869
|
|
|
11870
11870
|
// Get all displays as JSON array
|
|
11871
|
-
extern "C"
|
|
11871
|
+
extern "C" SPARKBUN_EXPORT const char* getAllDisplays() {
|
|
11872
11872
|
MonitorEnumData data;
|
|
11873
11873
|
|
|
11874
11874
|
EnumDisplayMonitors(NULL, NULL, MonitorEnumProc, reinterpret_cast<LPARAM>(&data));
|
|
@@ -11943,7 +11943,7 @@ static BOOL CALLBACK PrimaryMonitorEnumProc(HMONITOR hMonitor, HDC hdcMonitor, L
|
|
|
11943
11943
|
}
|
|
11944
11944
|
|
|
11945
11945
|
// Get primary display as JSON
|
|
11946
|
-
extern "C"
|
|
11946
|
+
extern "C" SPARKBUN_EXPORT const char* getPrimaryDisplay() {
|
|
11947
11947
|
PrimaryMonitorData data;
|
|
11948
11948
|
data.found = false;
|
|
11949
11949
|
|
|
@@ -11957,7 +11957,7 @@ extern "C" ELECTROBUN_EXPORT const char* getPrimaryDisplay() {
|
|
|
11957
11957
|
}
|
|
11958
11958
|
|
|
11959
11959
|
// Get current cursor position as JSON: {"x": 123, "y": 456}
|
|
11960
|
-
extern "C"
|
|
11960
|
+
extern "C" SPARKBUN_EXPORT const char* getCursorScreenPoint() {
|
|
11961
11961
|
POINT cursorPos;
|
|
11962
11962
|
if (GetCursorPos(&cursorPos)) {
|
|
11963
11963
|
std::ostringstream json;
|
|
@@ -11968,7 +11968,7 @@ extern "C" ELECTROBUN_EXPORT const char* getCursorScreenPoint() {
|
|
|
11968
11968
|
return _strdup("{\"x\":0,\"y\":0}");
|
|
11969
11969
|
}
|
|
11970
11970
|
|
|
11971
|
-
extern "C"
|
|
11971
|
+
extern "C" SPARKBUN_EXPORT uint64_t getMouseButtons() {
|
|
11972
11972
|
uint64_t buttons = 0;
|
|
11973
11973
|
if (GetAsyncKeyState(VK_LBUTTON) & 0x8000) buttons |= 1ull << 0;
|
|
11974
11974
|
if (GetAsyncKeyState(VK_RBUTTON) & 0x8000) buttons |= 1ull << 1;
|
|
@@ -11996,7 +11996,7 @@ static WebView2View* findWebView2ById(uint32_t webviewId) {
|
|
|
11996
11996
|
// Get cookies for a webview (WebView2)
|
|
11997
11997
|
// Note: WebView2 requires a live webview to access cookies. Pass webviewId of an existing webview.
|
|
11998
11998
|
// filterJson: {"url": "https://example.com"} or {} for all
|
|
11999
|
-
extern "C"
|
|
11999
|
+
extern "C" SPARKBUN_EXPORT const char* sessionGetCookies(const char* partitionIdentifier, const char* filterJson) {
|
|
12000
12000
|
// For WebView2, we need a webview to access cookies
|
|
12001
12001
|
// We'll try to find any webview with the matching partition
|
|
12002
12002
|
// For now, return empty array - full implementation requires webview access
|
|
@@ -12121,7 +12121,7 @@ extern "C" ELECTROBUN_EXPORT const char* sessionGetCookies(const char* partition
|
|
|
12121
12121
|
}
|
|
12122
12122
|
|
|
12123
12123
|
// Set a cookie (WebView2)
|
|
12124
|
-
extern "C"
|
|
12124
|
+
extern "C" SPARKBUN_EXPORT bool sessionSetCookie(const char* partitionIdentifier, const char* cookieJson) {
|
|
12125
12125
|
if (!cookieJson) return false;
|
|
12126
12126
|
|
|
12127
12127
|
// Find a WebView2 instance
|
|
@@ -12239,7 +12239,7 @@ extern "C" ELECTROBUN_EXPORT bool sessionSetCookie(const char* partitionIdentifi
|
|
|
12239
12239
|
}
|
|
12240
12240
|
|
|
12241
12241
|
// Remove a specific cookie (WebView2)
|
|
12242
|
-
extern "C"
|
|
12242
|
+
extern "C" SPARKBUN_EXPORT bool sessionRemoveCookie(const char* partitionIdentifier, const char* urlStr, const char* cookieName) {
|
|
12243
12243
|
if (!urlStr || !cookieName) return false;
|
|
12244
12244
|
|
|
12245
12245
|
// Find a WebView2 instance
|
|
@@ -12313,7 +12313,7 @@ extern "C" ELECTROBUN_EXPORT bool sessionRemoveCookie(const char* partitionIdent
|
|
|
12313
12313
|
}
|
|
12314
12314
|
|
|
12315
12315
|
// Clear all cookies (WebView2)
|
|
12316
|
-
extern "C"
|
|
12316
|
+
extern "C" SPARKBUN_EXPORT void sessionClearCookies(const char* partitionIdentifier) {
|
|
12317
12317
|
// Find a WebView2 instance
|
|
12318
12318
|
WebView2View* view = nullptr;
|
|
12319
12319
|
for (auto& pair : g_webview2Views) {
|
|
@@ -12343,7 +12343,7 @@ extern "C" ELECTROBUN_EXPORT void sessionClearCookies(const char* partitionIdent
|
|
|
12343
12343
|
}
|
|
12344
12344
|
|
|
12345
12345
|
// Clear storage data (WebView2) - uses Profile API
|
|
12346
|
-
extern "C"
|
|
12346
|
+
extern "C" SPARKBUN_EXPORT void sessionClearStorageData(const char* partitionIdentifier, const char* storageTypesJson) {
|
|
12347
12347
|
// Find a WebView2 instance
|
|
12348
12348
|
WebView2View* view = nullptr;
|
|
12349
12349
|
for (auto& pair : g_webview2Views) {
|
|
@@ -12399,31 +12399,31 @@ extern "C" ELECTROBUN_EXPORT void sessionClearStorageData(const char* partitionI
|
|
|
12399
12399
|
}
|
|
12400
12400
|
|
|
12401
12401
|
// URL scheme handler - macOS only, stub for Windows
|
|
12402
|
-
extern "C"
|
|
12402
|
+
extern "C" SPARKBUN_EXPORT void setURLOpenHandler(void (*callback)(const char*)) {
|
|
12403
12403
|
(void)callback;
|
|
12404
12404
|
// Not supported on Windows - stub to prevent dlopen failure
|
|
12405
12405
|
// Windows URL protocol handling is done via registry
|
|
12406
12406
|
}
|
|
12407
12407
|
|
|
12408
12408
|
// App reopen handler - macOS only, stub for Windows
|
|
12409
|
-
extern "C"
|
|
12409
|
+
extern "C" SPARKBUN_EXPORT void setAppReopenHandler(void (*callback)()) {
|
|
12410
12410
|
(void)callback;
|
|
12411
12411
|
// Not supported on Windows - stub to prevent dlopen failure
|
|
12412
12412
|
}
|
|
12413
12413
|
|
|
12414
12414
|
// Dock icon visibility - macOS only, stubs for Windows
|
|
12415
|
-
extern "C"
|
|
12415
|
+
extern "C" SPARKBUN_EXPORT void setDockIconVisible(bool visible) {
|
|
12416
12416
|
(void)visible;
|
|
12417
12417
|
// Not supported on Windows - stub to prevent dlopen failure
|
|
12418
12418
|
}
|
|
12419
12419
|
|
|
12420
|
-
extern "C"
|
|
12420
|
+
extern "C" SPARKBUN_EXPORT bool isDockIconVisible() {
|
|
12421
12421
|
// Not supported on Windows
|
|
12422
12422
|
return true;
|
|
12423
12423
|
}
|
|
12424
12424
|
|
|
12425
12425
|
// Window icon - Linux only, no-op for Windows
|
|
12426
|
-
extern "C"
|
|
12426
|
+
extern "C" SPARKBUN_EXPORT void setWindowIcon(void* window, const char* iconPath) {
|
|
12427
12427
|
// Not yet implemented on Windows
|
|
12428
12428
|
// TODO: Implement using SetWindowIcon/LoadImage APIs
|
|
12429
12429
|
}
|