electrobun 1.18.1 → 1.18.4-beta.3
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/README.md +1 -0
- package/dist/api/bun/ElectrobunConfig.ts +20 -0
- package/dist/api/bun/core/BrowserView.ts +29 -47
- package/dist/api/bun/core/BrowserWindow.ts +14 -7
- package/dist/api/bun/core/BuildConfig.ts +31 -4
- package/dist/api/bun/core/GpuWindow.ts +13 -6
- package/dist/api/bun/core/Tray.ts +33 -32
- package/dist/api/bun/proc/native.ts +682 -655
- package/dist/main.js +26 -22
- package/dist/preload-full.js +885 -0
- package/dist/preload-sandboxed.js +111 -0
- package/dist/zig-sdk/electrobun.zig +1979 -0
- package/package.json +2 -3
- package/src/cli/index.ts +313 -135
- package/dist/api/bun/core/windowIds.ts +0 -5
|
@@ -0,0 +1,1979 @@
|
|
|
1
|
+
const std = @import("std");
|
|
2
|
+
const builtin = @import("builtin");
|
|
3
|
+
|
|
4
|
+
pub const WindowCloseHandler = *const fn (u32) callconv(.C) void;
|
|
5
|
+
pub const WindowMoveHandler = *const fn (u32, f64, f64) callconv(.C) void;
|
|
6
|
+
pub const WindowResizeHandler = *const fn (u32, f64, f64, f64, f64) callconv(.C) void;
|
|
7
|
+
pub const WindowFocusHandler = *const fn (u32) callconv(.C) void;
|
|
8
|
+
pub const WindowBlurHandler = *const fn (u32) callconv(.C) void;
|
|
9
|
+
pub const WindowKeyHandler = *const fn (u32, u32, u32, u32, u32) callconv(.C) void;
|
|
10
|
+
pub const DecideNavigationHandler = *const fn (u32, [*:0]const u8) callconv(.C) u32;
|
|
11
|
+
pub const WebviewEventHandler = *const fn (u32, [*:0]const u8, [*:0]const u8) callconv(.C) void;
|
|
12
|
+
pub const WebviewPostMessageHandler = *const fn (u32, [*:0]const u8) callconv(.C) u32;
|
|
13
|
+
pub const StatusItemHandler = *const fn (u32, [*:0]const u8) callconv(.C) void;
|
|
14
|
+
pub const GlobalShortcutHandler = *const fn ([*:0]const u8) callconv(.C) void;
|
|
15
|
+
pub const QuitRequestedHandler = *const fn () callconv(.C) void;
|
|
16
|
+
pub const URLOpenHandler = *const fn ([*:0]const u8) callconv(.C) void;
|
|
17
|
+
pub const AppReopenHandler = *const fn () callconv(.C) void;
|
|
18
|
+
|
|
19
|
+
pub const Renderer = enum {
|
|
20
|
+
native,
|
|
21
|
+
cef,
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
pub const AppInfo = struct {
|
|
25
|
+
identifier: []const u8,
|
|
26
|
+
name: []const u8,
|
|
27
|
+
channel: []const u8,
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
pub const OwnedAppInfo = struct {
|
|
31
|
+
identifier: []u8,
|
|
32
|
+
name: []u8,
|
|
33
|
+
channel: []u8,
|
|
34
|
+
|
|
35
|
+
pub fn deinit(self: *const OwnedAppInfo, allocator: std.mem.Allocator) void {
|
|
36
|
+
allocator.free(self.identifier);
|
|
37
|
+
allocator.free(self.name);
|
|
38
|
+
allocator.free(self.channel);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
pub fn borrowed(self: *const OwnedAppInfo) AppInfo {
|
|
42
|
+
return .{
|
|
43
|
+
.identifier = self.identifier,
|
|
44
|
+
.name = self.name,
|
|
45
|
+
.channel = self.channel,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
pub const Rect = struct {
|
|
51
|
+
x: f64 = 0,
|
|
52
|
+
y: f64 = 0,
|
|
53
|
+
width: f64 = 800,
|
|
54
|
+
height: f64 = 600,
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
pub const TrafficLightOffset = struct {
|
|
58
|
+
x: f64 = 0,
|
|
59
|
+
y: f64 = 0,
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
pub const WindowStyle = struct {
|
|
63
|
+
borderless: bool = false,
|
|
64
|
+
titled: bool = true,
|
|
65
|
+
closable: bool = true,
|
|
66
|
+
miniaturizable: bool = true,
|
|
67
|
+
resizable: bool = true,
|
|
68
|
+
unified_title_and_toolbar: bool = false,
|
|
69
|
+
full_screen: bool = false,
|
|
70
|
+
full_size_content_view: bool = false,
|
|
71
|
+
utility_window: bool = false,
|
|
72
|
+
doc_modal_window: bool = false,
|
|
73
|
+
nonactivating_panel: bool = false,
|
|
74
|
+
hud_window: bool = false,
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
pub const WindowCallbacks = struct {
|
|
78
|
+
close: ?WindowCloseHandler = null,
|
|
79
|
+
move: ?WindowMoveHandler = null,
|
|
80
|
+
resize: ?WindowResizeHandler = null,
|
|
81
|
+
focus: ?WindowFocusHandler = null,
|
|
82
|
+
blur: ?WindowBlurHandler = null,
|
|
83
|
+
key: ?WindowKeyHandler = null,
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
pub const WindowOptions = struct {
|
|
87
|
+
title: []const u8,
|
|
88
|
+
frame: Rect,
|
|
89
|
+
style: WindowStyle = .{},
|
|
90
|
+
title_bar_style: []const u8 = "default",
|
|
91
|
+
transparent: bool = false,
|
|
92
|
+
hidden: bool = false,
|
|
93
|
+
activate: bool = true,
|
|
94
|
+
traffic_light_offset: TrafficLightOffset = .{},
|
|
95
|
+
callbacks: WindowCallbacks = .{},
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
pub const WebviewCallbacks = struct {
|
|
99
|
+
decide_navigation: ?DecideNavigationHandler = null,
|
|
100
|
+
event: ?WebviewEventHandler = null,
|
|
101
|
+
event_bridge: ?WebviewPostMessageHandler = null,
|
|
102
|
+
bun_bridge: ?WebviewPostMessageHandler = null,
|
|
103
|
+
internal_bridge: ?WebviewPostMessageHandler = null,
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
pub const WebviewOptions = struct {
|
|
107
|
+
window_id: u32,
|
|
108
|
+
host_webview_id: u32 = 0,
|
|
109
|
+
renderer: Renderer = .native,
|
|
110
|
+
url: []const u8 = "",
|
|
111
|
+
frame: Rect = .{},
|
|
112
|
+
auto_resize: bool = true,
|
|
113
|
+
partition: []const u8 = "persist:default",
|
|
114
|
+
callbacks: WebviewCallbacks = .{},
|
|
115
|
+
secret_key: []const u8 = "",
|
|
116
|
+
preload: []const u8 = "",
|
|
117
|
+
views_root: []const u8 = "",
|
|
118
|
+
sandbox: bool = true,
|
|
119
|
+
start_transparent: bool = false,
|
|
120
|
+
start_passthrough: bool = false,
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
pub const WGPUViewOptions = struct {
|
|
124
|
+
window_id: u32,
|
|
125
|
+
frame: Rect = .{},
|
|
126
|
+
auto_resize: bool = true,
|
|
127
|
+
start_transparent: bool = false,
|
|
128
|
+
start_passthrough: bool = false,
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
pub const TrayOptions = struct {
|
|
132
|
+
title: []const u8 = "",
|
|
133
|
+
image: []const u8,
|
|
134
|
+
is_template: bool = false,
|
|
135
|
+
width: u32 = 18,
|
|
136
|
+
height: u32 = 18,
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
pub const Display = struct {
|
|
140
|
+
id: i64,
|
|
141
|
+
bounds: Rect,
|
|
142
|
+
workArea: Rect,
|
|
143
|
+
scaleFactor: f64,
|
|
144
|
+
isPrimary: bool,
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
pub const Point = struct {
|
|
148
|
+
x: f64,
|
|
149
|
+
y: f64,
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
pub const NotificationOptions = struct {
|
|
153
|
+
title: []const u8,
|
|
154
|
+
body: []const u8 = "",
|
|
155
|
+
subtitle: []const u8 = "",
|
|
156
|
+
silent: bool = false,
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
pub const Cookie = struct {
|
|
160
|
+
name: []const u8,
|
|
161
|
+
value: []const u8,
|
|
162
|
+
domain: ?[]const u8 = null,
|
|
163
|
+
path: ?[]const u8 = null,
|
|
164
|
+
secure: ?bool = null,
|
|
165
|
+
httpOnly: ?bool = null,
|
|
166
|
+
sameSite: ?[]const u8 = null,
|
|
167
|
+
expirationDate: ?f64 = null,
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
pub const CookieFilter = struct {
|
|
171
|
+
url: ?[]const u8 = null,
|
|
172
|
+
name: ?[]const u8 = null,
|
|
173
|
+
domain: ?[]const u8 = null,
|
|
174
|
+
path: ?[]const u8 = null,
|
|
175
|
+
secure: ?bool = null,
|
|
176
|
+
session: ?bool = null,
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
pub const StorageType = enum {
|
|
180
|
+
cookies,
|
|
181
|
+
localStorage,
|
|
182
|
+
sessionStorage,
|
|
183
|
+
indexedDB,
|
|
184
|
+
webSQL,
|
|
185
|
+
cache,
|
|
186
|
+
all,
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
pub const OpenFileDialogOptions = struct {
|
|
190
|
+
starting_folder: []const u8 = "~/",
|
|
191
|
+
allowed_file_types: []const u8 = "*",
|
|
192
|
+
can_choose_files: bool = true,
|
|
193
|
+
can_choose_directory: bool = true,
|
|
194
|
+
allows_multiple_selection: bool = true,
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
pub const MessageBoxOptions = struct {
|
|
198
|
+
box_type: []const u8 = "info",
|
|
199
|
+
title: []const u8 = "",
|
|
200
|
+
message: []const u8 = "",
|
|
201
|
+
detail: []const u8 = "",
|
|
202
|
+
buttons: []const []const u8 = &.{ "OK" },
|
|
203
|
+
default_id: c_int = 0,
|
|
204
|
+
cancel_id: c_int = -1,
|
|
205
|
+
};
|
|
206
|
+
|
|
207
|
+
pub const Paths = struct {
|
|
208
|
+
home: []u8,
|
|
209
|
+
appData: []u8,
|
|
210
|
+
config: []u8,
|
|
211
|
+
cache: []u8,
|
|
212
|
+
temp: []u8,
|
|
213
|
+
logs: []u8,
|
|
214
|
+
documents: []u8,
|
|
215
|
+
downloads: []u8,
|
|
216
|
+
desktop: []u8,
|
|
217
|
+
pictures: []u8,
|
|
218
|
+
music: []u8,
|
|
219
|
+
videos: []u8,
|
|
220
|
+
userData: []u8,
|
|
221
|
+
userCache: []u8,
|
|
222
|
+
userLogs: []u8,
|
|
223
|
+
|
|
224
|
+
pub fn deinit(self: *const Paths, allocator: std.mem.Allocator) void {
|
|
225
|
+
allocator.free(self.home);
|
|
226
|
+
allocator.free(self.appData);
|
|
227
|
+
allocator.free(self.config);
|
|
228
|
+
allocator.free(self.cache);
|
|
229
|
+
allocator.free(self.temp);
|
|
230
|
+
allocator.free(self.logs);
|
|
231
|
+
allocator.free(self.documents);
|
|
232
|
+
allocator.free(self.downloads);
|
|
233
|
+
allocator.free(self.desktop);
|
|
234
|
+
allocator.free(self.pictures);
|
|
235
|
+
allocator.free(self.music);
|
|
236
|
+
allocator.free(self.videos);
|
|
237
|
+
allocator.free(self.userData);
|
|
238
|
+
allocator.free(self.userCache);
|
|
239
|
+
allocator.free(self.userLogs);
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
pub fn resolve(allocator: std.mem.Allocator, app_info: AppInfo) !Paths {
|
|
243
|
+
const home = try getHomeDirOwned(allocator);
|
|
244
|
+
errdefer allocator.free(home);
|
|
245
|
+
|
|
246
|
+
const app_data = try getAppDataDirOwned(allocator, home);
|
|
247
|
+
errdefer allocator.free(app_data);
|
|
248
|
+
const config = try getConfigDirOwned(allocator, home);
|
|
249
|
+
errdefer allocator.free(config);
|
|
250
|
+
const cache = try getCacheDirOwned(allocator, home);
|
|
251
|
+
errdefer allocator.free(cache);
|
|
252
|
+
const temp = try getTempDirOwned(allocator, home);
|
|
253
|
+
errdefer allocator.free(temp);
|
|
254
|
+
const logs = try getLogsDirOwned(allocator, home);
|
|
255
|
+
errdefer allocator.free(logs);
|
|
256
|
+
|
|
257
|
+
const documents = try getUserDirOwned(allocator, home, "Documents", "Documents", "XDG_DOCUMENTS_DIR", "Documents");
|
|
258
|
+
errdefer allocator.free(documents);
|
|
259
|
+
const downloads = try getUserDirOwned(allocator, home, "Downloads", "Downloads", "XDG_DOWNLOAD_DIR", "Downloads");
|
|
260
|
+
errdefer allocator.free(downloads);
|
|
261
|
+
const desktop = try getUserDirOwned(allocator, home, "Desktop", "Desktop", "XDG_DESKTOP_DIR", "Desktop");
|
|
262
|
+
errdefer allocator.free(desktop);
|
|
263
|
+
const pictures = try getUserDirOwned(allocator, home, "Pictures", "Pictures", "XDG_PICTURES_DIR", "Pictures");
|
|
264
|
+
errdefer allocator.free(pictures);
|
|
265
|
+
const music = try getUserDirOwned(allocator, home, "Music", "Music", "XDG_MUSIC_DIR", "Music");
|
|
266
|
+
errdefer allocator.free(music);
|
|
267
|
+
const videos = try getUserDirOwned(allocator, home, "Movies", "Videos", "XDG_VIDEOS_DIR", "Videos");
|
|
268
|
+
errdefer allocator.free(videos);
|
|
269
|
+
|
|
270
|
+
const user_data = try buildAppScopedDir(allocator, app_data, app_info);
|
|
271
|
+
errdefer allocator.free(user_data);
|
|
272
|
+
const user_cache = try buildAppScopedDir(allocator, cache, app_info);
|
|
273
|
+
errdefer allocator.free(user_cache);
|
|
274
|
+
const user_logs = try buildAppScopedDir(allocator, logs, app_info);
|
|
275
|
+
errdefer allocator.free(user_logs);
|
|
276
|
+
|
|
277
|
+
return .{
|
|
278
|
+
.home = home,
|
|
279
|
+
.appData = app_data,
|
|
280
|
+
.config = config,
|
|
281
|
+
.cache = cache,
|
|
282
|
+
.temp = temp,
|
|
283
|
+
.logs = logs,
|
|
284
|
+
.documents = documents,
|
|
285
|
+
.downloads = downloads,
|
|
286
|
+
.desktop = desktop,
|
|
287
|
+
.pictures = pictures,
|
|
288
|
+
.music = music,
|
|
289
|
+
.videos = videos,
|
|
290
|
+
.userData = user_data,
|
|
291
|
+
.userCache = user_cache,
|
|
292
|
+
.userLogs = user_logs,
|
|
293
|
+
};
|
|
294
|
+
}
|
|
295
|
+
};
|
|
296
|
+
|
|
297
|
+
pub const BrowserWindowRef = struct {
|
|
298
|
+
registry: *WindowRegistry,
|
|
299
|
+
id: u32,
|
|
300
|
+
|
|
301
|
+
pub fn close(self: BrowserWindowRef) !void {
|
|
302
|
+
try self.registry.core.closeWindow(self.id);
|
|
303
|
+
_ = self.registry.ids.remove(self.id);
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
pub fn getFrame(self: BrowserWindowRef) !Rect {
|
|
307
|
+
return try self.registry.core.getWindowFrame(self.id);
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
pub fn setWindowButtonPosition(self: BrowserWindowRef, x: f64, y: f64) !void {
|
|
311
|
+
try self.registry.core.setWindowButtonPosition(self.id, x, y);
|
|
312
|
+
}
|
|
313
|
+
};
|
|
314
|
+
|
|
315
|
+
pub const SessionPartition = struct {
|
|
316
|
+
core: *Core,
|
|
317
|
+
partition: []const u8,
|
|
318
|
+
|
|
319
|
+
pub fn getCookies(self: SessionPartition, filter: ?CookieFilter) ![]Cookie {
|
|
320
|
+
const filter_json = try std.json.stringifyAlloc(self.core.allocator, filter orelse CookieFilter{}, .{});
|
|
321
|
+
defer self.core.allocator.free(filter_json);
|
|
322
|
+
return self.core.sessionGetCookies(self.partition, filter_json);
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
pub fn setCookie(self: SessionPartition, cookie: Cookie) !bool {
|
|
326
|
+
const cookie_json = try std.json.stringifyAlloc(self.core.allocator, cookie, .{});
|
|
327
|
+
defer self.core.allocator.free(cookie_json);
|
|
328
|
+
return self.core.sessionSetCookie(self.partition, cookie_json);
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
pub fn removeCookie(self: SessionPartition, url: []const u8, name: []const u8) !bool {
|
|
332
|
+
return self.core.sessionRemoveCookie(self.partition, url, name);
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
pub fn clearCookies(self: SessionPartition) !void {
|
|
336
|
+
try self.core.sessionClearCookies(self.partition);
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
pub fn clearStorageData(self: SessionPartition, storage_types: []const StorageType) !void {
|
|
340
|
+
if (storage_types.len == 0) {
|
|
341
|
+
try self.core.sessionClearStorageData(self.partition, "[\"all\"]");
|
|
342
|
+
return;
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
const names = try self.core.allocator.alloc([]const u8, storage_types.len);
|
|
346
|
+
defer self.core.allocator.free(names);
|
|
347
|
+
for (storage_types, 0..) |storage_type, index| {
|
|
348
|
+
names[index] = @tagName(storage_type);
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
const storage_types_json = try std.json.stringifyAlloc(self.core.allocator, names, .{});
|
|
352
|
+
defer self.core.allocator.free(storage_types_json);
|
|
353
|
+
try self.core.sessionClearStorageData(self.partition, storage_types_json);
|
|
354
|
+
}
|
|
355
|
+
};
|
|
356
|
+
|
|
357
|
+
pub const Session = struct {
|
|
358
|
+
pub fn fromPartition(core: *Core, partition: []const u8) SessionPartition {
|
|
359
|
+
return .{
|
|
360
|
+
.core = core,
|
|
361
|
+
.partition = partition,
|
|
362
|
+
};
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
pub fn defaultSession(core: *Core) SessionPartition {
|
|
366
|
+
return fromPartition(core, "persist:default");
|
|
367
|
+
}
|
|
368
|
+
};
|
|
369
|
+
|
|
370
|
+
pub const WgpuAdapterDevice = struct {
|
|
371
|
+
adapter: ?*anyopaque,
|
|
372
|
+
device: ?*anyopaque,
|
|
373
|
+
};
|
|
374
|
+
|
|
375
|
+
pub const WgpuNative = struct {
|
|
376
|
+
lib: std.DynLib,
|
|
377
|
+
symbols: Symbols,
|
|
378
|
+
|
|
379
|
+
const CreateInstanceFn = *const fn (?*const anyopaque) callconv(.C) ?*anyopaque;
|
|
380
|
+
const DeviceGetQueueFn = *const fn (?*anyopaque) callconv(.C) ?*anyopaque;
|
|
381
|
+
|
|
382
|
+
const Symbols = struct {
|
|
383
|
+
create_instance: CreateInstanceFn,
|
|
384
|
+
device_get_queue: DeviceGetQueueFn,
|
|
385
|
+
};
|
|
386
|
+
|
|
387
|
+
pub fn load(allocator: std.mem.Allocator) !WgpuNative {
|
|
388
|
+
const bundle_paths = try resolveBundlePaths(allocator);
|
|
389
|
+
defer bundle_paths.deinit(allocator);
|
|
390
|
+
|
|
391
|
+
const lib_name = switch (builtin.os.tag) {
|
|
392
|
+
.windows => "webgpu_dawn.dll",
|
|
393
|
+
.macos => "libwebgpu_dawn.dylib",
|
|
394
|
+
else => "libwebgpu_dawn.so",
|
|
395
|
+
};
|
|
396
|
+
const lib_path = try std.fs.path.join(allocator, &.{ bundle_paths.exe_dir, lib_name });
|
|
397
|
+
defer allocator.free(lib_path);
|
|
398
|
+
|
|
399
|
+
var lib = try std.DynLib.open(lib_path);
|
|
400
|
+
return .{
|
|
401
|
+
.lib = lib,
|
|
402
|
+
.symbols = .{
|
|
403
|
+
.create_instance = lib.lookup(CreateInstanceFn, "wgpuCreateInstance") orelse return error.MissingCoreSymbol,
|
|
404
|
+
.device_get_queue = lib.lookup(DeviceGetQueueFn, "wgpuDeviceGetQueue") orelse return error.MissingCoreSymbol,
|
|
405
|
+
},
|
|
406
|
+
};
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
pub fn close(self: *WgpuNative) void {
|
|
410
|
+
self.lib.close();
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
pub fn createInstance(self: *WgpuNative) ?*anyopaque {
|
|
414
|
+
return self.symbols.create_instance(null);
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
pub fn deviceGetQueue(self: *WgpuNative, device: ?*anyopaque) ?*anyopaque {
|
|
418
|
+
return self.symbols.device_get_queue(device);
|
|
419
|
+
}
|
|
420
|
+
};
|
|
421
|
+
|
|
422
|
+
pub const WgpuContext = struct {
|
|
423
|
+
view_ptr: ?*anyopaque,
|
|
424
|
+
instance_ptr: ?*anyopaque,
|
|
425
|
+
surface_ptr: ?*anyopaque,
|
|
426
|
+
adapter_ptr: ?*anyopaque,
|
|
427
|
+
device_ptr: ?*anyopaque,
|
|
428
|
+
|
|
429
|
+
pub fn createForView(core: *Core, native: *WgpuNative, view_ptr: ?*anyopaque) !WgpuContext {
|
|
430
|
+
const instance_ptr = native.createInstance() orelse return error.ElectrobunCoreFailure;
|
|
431
|
+
const surface_ptr = try core.wgpuCreateSurfaceForView(instance_ptr, view_ptr);
|
|
432
|
+
|
|
433
|
+
var adapter_device = [2]usize{ 0, 0 };
|
|
434
|
+
try core.wgpuCreateAdapterDeviceMainThread(
|
|
435
|
+
instance_ptr,
|
|
436
|
+
surface_ptr,
|
|
437
|
+
@ptrCast(&adapter_device),
|
|
438
|
+
);
|
|
439
|
+
|
|
440
|
+
const adapter_ptr: ?*anyopaque = @ptrFromInt(adapter_device[0]);
|
|
441
|
+
const device_ptr: ?*anyopaque = @ptrFromInt(adapter_device[1]);
|
|
442
|
+
if (device_ptr == null) {
|
|
443
|
+
return error.ElectrobunCoreFailure;
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
return .{
|
|
447
|
+
.view_ptr = view_ptr,
|
|
448
|
+
.instance_ptr = instance_ptr,
|
|
449
|
+
.surface_ptr = surface_ptr,
|
|
450
|
+
.adapter_ptr = adapter_ptr,
|
|
451
|
+
.device_ptr = device_ptr,
|
|
452
|
+
};
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
pub fn createForWgpuView(core: *Core, native: *WgpuNative, wgpu_view_id: u32) !WgpuContext {
|
|
456
|
+
const view_ptr = try core.getWGPUViewPointer(wgpu_view_id);
|
|
457
|
+
return createForView(core, native, view_ptr);
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
pub fn getQueue(self: WgpuContext, native: *WgpuNative) ?*anyopaque {
|
|
461
|
+
return native.deviceGetQueue(self.device_ptr);
|
|
462
|
+
}
|
|
463
|
+
};
|
|
464
|
+
|
|
465
|
+
pub const WindowRegistry = struct {
|
|
466
|
+
allocator: std.mem.Allocator,
|
|
467
|
+
core: *Core,
|
|
468
|
+
ids: std.AutoHashMap(u32, void),
|
|
469
|
+
|
|
470
|
+
pub fn init(allocator: std.mem.Allocator, core: *Core) WindowRegistry {
|
|
471
|
+
return .{
|
|
472
|
+
.allocator = allocator,
|
|
473
|
+
.core = core,
|
|
474
|
+
.ids = std.AutoHashMap(u32, void).init(allocator),
|
|
475
|
+
};
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
pub fn deinit(self: *WindowRegistry) void {
|
|
479
|
+
self.ids.deinit();
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
pub fn createBrowserWindow(self: *WindowRegistry, options: WindowOptions) !BrowserWindowRef {
|
|
483
|
+
const id = try self.core.createWindow(options);
|
|
484
|
+
try self.ids.put(id, {});
|
|
485
|
+
return .{
|
|
486
|
+
.registry = self,
|
|
487
|
+
.id = id,
|
|
488
|
+
};
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
pub fn getById(self: *WindowRegistry, id: u32) ?BrowserWindowRef {
|
|
492
|
+
if (!self.ids.contains(id)) {
|
|
493
|
+
return null;
|
|
494
|
+
}
|
|
495
|
+
return .{
|
|
496
|
+
.registry = self,
|
|
497
|
+
.id = id,
|
|
498
|
+
};
|
|
499
|
+
}
|
|
500
|
+
};
|
|
501
|
+
|
|
502
|
+
pub const BundlePaths = struct {
|
|
503
|
+
exe_dir: []u8,
|
|
504
|
+
resources_dir: []u8,
|
|
505
|
+
|
|
506
|
+
pub fn deinit(self: *const BundlePaths, allocator: std.mem.Allocator) void {
|
|
507
|
+
allocator.free(self.exe_dir);
|
|
508
|
+
allocator.free(self.resources_dir);
|
|
509
|
+
}
|
|
510
|
+
};
|
|
511
|
+
|
|
512
|
+
pub fn resolveBundlePaths(allocator: std.mem.Allocator) !BundlePaths {
|
|
513
|
+
const exe_path = try std.fs.selfExePathAlloc(allocator);
|
|
514
|
+
defer allocator.free(exe_path);
|
|
515
|
+
|
|
516
|
+
const exe_dir_name = std.fs.path.dirname(exe_path) orelse return error.InvalidExePath;
|
|
517
|
+
const exe_dir = try allocator.dupe(u8, exe_dir_name);
|
|
518
|
+
const resources_dir = try std.fs.path.join(allocator, &.{ exe_dir_name, "..", "Resources" });
|
|
519
|
+
|
|
520
|
+
return .{
|
|
521
|
+
.exe_dir = exe_dir,
|
|
522
|
+
.resources_dir = resources_dir,
|
|
523
|
+
};
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
pub fn resolveAppInfoFromBundle(allocator: std.mem.Allocator, bundle_paths: *const BundlePaths) !OwnedAppInfo {
|
|
527
|
+
const version_json_path = try std.fs.path.join(allocator, &.{ bundle_paths.resources_dir, "version.json" });
|
|
528
|
+
defer allocator.free(version_json_path);
|
|
529
|
+
|
|
530
|
+
const version_json = try readFileAlloc(allocator, version_json_path);
|
|
531
|
+
defer allocator.free(version_json);
|
|
532
|
+
|
|
533
|
+
const ParsedAppInfo = struct {
|
|
534
|
+
identifier: []const u8,
|
|
535
|
+
name: []const u8,
|
|
536
|
+
channel: []const u8,
|
|
537
|
+
};
|
|
538
|
+
|
|
539
|
+
var parsed = try std.json.parseFromSlice(ParsedAppInfo, allocator, version_json, .{
|
|
540
|
+
.ignore_unknown_fields = true,
|
|
541
|
+
});
|
|
542
|
+
defer parsed.deinit();
|
|
543
|
+
|
|
544
|
+
return .{
|
|
545
|
+
.identifier = try allocator.dupe(u8, parsed.value.identifier),
|
|
546
|
+
.name = try allocator.dupe(u8, parsed.value.name),
|
|
547
|
+
.channel = try allocator.dupe(u8, parsed.value.channel),
|
|
548
|
+
};
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
pub const Core = struct {
|
|
552
|
+
allocator: std.mem.Allocator,
|
|
553
|
+
lib: std.DynLib,
|
|
554
|
+
symbols: Symbols,
|
|
555
|
+
|
|
556
|
+
const LastErrorFn = *const fn () callconv(.C) [*:0]const u8;
|
|
557
|
+
const RunMainThreadFn = *const fn ([*:0]const u8, [*:0]const u8, [*:0]const u8, c_int) callconv(.C) c_int;
|
|
558
|
+
const ConfigureWebviewRuntimeFn = *const fn (u32, [*:0]const u8, [*:0]const u8) callconv(.C) bool;
|
|
559
|
+
const GetWindowStyleFn = *const fn (bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool) callconv(.C) u32;
|
|
560
|
+
const CreateWindowFn = *const fn (f64, f64, f64, f64, u32, [*:0]const u8, bool, [*:0]const u8, bool, bool, f64, f64, ?WindowCloseHandler, ?WindowMoveHandler, ?WindowResizeHandler, ?WindowFocusHandler, ?WindowBlurHandler, ?WindowKeyHandler) callconv(.C) u32;
|
|
561
|
+
const CreateWebviewFn = *const fn (u32, u32, [*:0]const u8, [*:0]const u8, f64, f64, f64, f64, bool, [*:0]const u8, ?DecideNavigationHandler, ?WebviewEventHandler, ?WebviewPostMessageHandler, ?WebviewPostMessageHandler, ?WebviewPostMessageHandler, [*:0]const u8, [*:0]const u8, [*:0]const u8, bool, bool, bool) callconv(.C) u32;
|
|
562
|
+
const CreateWGPUViewFn = *const fn (u32, f64, f64, f64, f64, bool, bool, bool) callconv(.C) u32;
|
|
563
|
+
const SetWindowTitleFn = *const fn (u32, [*:0]const u8) callconv(.C) void;
|
|
564
|
+
const MinimizeWindowFn = *const fn (u32) callconv(.C) void;
|
|
565
|
+
const RestoreWindowFn = *const fn (u32) callconv(.C) void;
|
|
566
|
+
const IsWindowMinimizedFn = *const fn (u32) callconv(.C) bool;
|
|
567
|
+
const MaximizeWindowFn = *const fn (u32) callconv(.C) void;
|
|
568
|
+
const UnmaximizeWindowFn = *const fn (u32) callconv(.C) void;
|
|
569
|
+
const IsWindowMaximizedFn = *const fn (u32) callconv(.C) bool;
|
|
570
|
+
const SetWindowFullScreenFn = *const fn (u32, bool) callconv(.C) void;
|
|
571
|
+
const IsWindowFullScreenFn = *const fn (u32) callconv(.C) bool;
|
|
572
|
+
const SetWindowAlwaysOnTopFn = *const fn (u32, bool) callconv(.C) void;
|
|
573
|
+
const IsWindowAlwaysOnTopFn = *const fn (u32) callconv(.C) bool;
|
|
574
|
+
const SetWindowVisibleOnAllWorkspacesFn = *const fn (u32, bool) callconv(.C) void;
|
|
575
|
+
const IsWindowVisibleOnAllWorkspacesFn = *const fn (u32) callconv(.C) bool;
|
|
576
|
+
const ShowWindowFn = *const fn (u32, bool) callconv(.C) void;
|
|
577
|
+
const ActivateWindowFn = *const fn (u32) callconv(.C) void;
|
|
578
|
+
const HideWindowFn = *const fn (u32) callconv(.C) void;
|
|
579
|
+
const SetWindowButtonPositionFn = *const fn (u32, f64, f64) callconv(.C) void;
|
|
580
|
+
const SetWindowPositionFn = *const fn (u32, f64, f64) callconv(.C) void;
|
|
581
|
+
const SetWindowSizeFn = *const fn (u32, f64, f64) callconv(.C) void;
|
|
582
|
+
const SetWindowFrameFn = *const fn (u32, f64, f64, f64, f64) callconv(.C) void;
|
|
583
|
+
const GetWindowFrameFn = *const fn (u32, *f64, *f64, *f64, *f64) callconv(.C) void;
|
|
584
|
+
const CloseWindowFn = *const fn (u32) callconv(.C) void;
|
|
585
|
+
const ResizeWebviewFn = *const fn (u32, f64, f64, f64, f64, [*:0]const u8) callconv(.C) void;
|
|
586
|
+
const LoadURLInWebViewFn = *const fn (u32, [*:0]const u8) callconv(.C) void;
|
|
587
|
+
const LoadHTMLInWebViewFn = *const fn (u32, [*:0]const u8) callconv(.C) void;
|
|
588
|
+
const UpdatePreloadScriptToWebViewFn = *const fn (u32, [*:0]const u8, [*:0]const u8, bool) callconv(.C) void;
|
|
589
|
+
const WebviewCanGoBackFn = *const fn (u32) callconv(.C) bool;
|
|
590
|
+
const WebviewCanGoForwardFn = *const fn (u32) callconv(.C) bool;
|
|
591
|
+
const WebviewGoBackFn = *const fn (u32) callconv(.C) void;
|
|
592
|
+
const WebviewGoForwardFn = *const fn (u32) callconv(.C) void;
|
|
593
|
+
const WebviewReloadFn = *const fn (u32) callconv(.C) void;
|
|
594
|
+
const WebviewRemoveFn = *const fn (u32) callconv(.C) void;
|
|
595
|
+
const SetWebviewHTMLContentFn = *const fn (u32, [*:0]const u8) callconv(.C) void;
|
|
596
|
+
const WebviewSetTransparentFn = *const fn (u32, bool) callconv(.C) void;
|
|
597
|
+
const WebviewSetPassthroughFn = *const fn (u32, bool) callconv(.C) void;
|
|
598
|
+
const WebviewSetHiddenFn = *const fn (u32, bool) callconv(.C) void;
|
|
599
|
+
const SetWebviewNavigationRulesFn = *const fn (u32, [*:0]const u8) callconv(.C) void;
|
|
600
|
+
const WebviewFindInPageFn = *const fn (u32, [*:0]const u8, bool, bool) callconv(.C) void;
|
|
601
|
+
const WebviewStopFindFn = *const fn (u32) callconv(.C) void;
|
|
602
|
+
const SendInternalMessageToWebviewFn = *const fn (u32, [*:0]const u8) callconv(.C) bool;
|
|
603
|
+
const WebviewOpenDevToolsFn = *const fn (u32) callconv(.C) void;
|
|
604
|
+
const WebviewCloseDevToolsFn = *const fn (u32) callconv(.C) void;
|
|
605
|
+
const WebviewToggleDevToolsFn = *const fn (u32) callconv(.C) void;
|
|
606
|
+
const WebviewSetPageZoomFn = *const fn (u32, f64) callconv(.C) void;
|
|
607
|
+
const WebviewGetPageZoomFn = *const fn (u32) callconv(.C) f64;
|
|
608
|
+
const SetWGPUViewFrameFn = *const fn (u32, f64, f64, f64, f64) callconv(.C) void;
|
|
609
|
+
const ResizeWGPUViewFn = *const fn (u32, f64, f64, f64, f64, [*:0]const u8) callconv(.C) void;
|
|
610
|
+
const SetWGPUViewTransparentFn = *const fn (u32, bool) callconv(.C) void;
|
|
611
|
+
const SetWGPUViewPassthroughFn = *const fn (u32, bool) callconv(.C) void;
|
|
612
|
+
const SetWGPUViewHiddenFn = *const fn (u32, bool) callconv(.C) void;
|
|
613
|
+
const RemoveWGPUViewFn = *const fn (u32) callconv(.C) void;
|
|
614
|
+
const GetWGPUViewPointerFn = *const fn (u32) callconv(.C) ?*anyopaque;
|
|
615
|
+
const GetWGPUViewNativeHandleFn = *const fn (u32) callconv(.C) ?*anyopaque;
|
|
616
|
+
const RunWGPUViewTestFn = *const fn (u32) callconv(.C) void;
|
|
617
|
+
const ToggleWGPUViewTestShaderFn = *const fn (u32) callconv(.C) void;
|
|
618
|
+
const EvaluateJavaScriptWithNoCompletionFn = *const fn (u32, [*:0]const u8) callconv(.C) void;
|
|
619
|
+
const CreateTrayFn = *const fn ([*:0]const u8, [*:0]const u8, bool, u32, u32, ?*const fn (u32, [*:0]const u8) callconv(.C) void) callconv(.C) u32;
|
|
620
|
+
const ShowTrayFn = *const fn (u32) callconv(.C) bool;
|
|
621
|
+
const HideTrayFn = *const fn (u32) callconv(.C) void;
|
|
622
|
+
const SetTrayTitleFn = *const fn (u32, [*:0]const u8) callconv(.C) void;
|
|
623
|
+
const RemoveTrayFn = *const fn (u32) callconv(.C) void;
|
|
624
|
+
const GetTrayBoundsFn = *const fn (u32) callconv(.C) [*:0]const u8;
|
|
625
|
+
const SetDockIconVisibleFn = *const fn (bool) callconv(.C) void;
|
|
626
|
+
const IsDockIconVisibleFn = *const fn () callconv(.C) bool;
|
|
627
|
+
const GetPrimaryDisplayFn = *const fn () callconv(.C) ?[*:0]const u8;
|
|
628
|
+
const GetAllDisplaysFn = *const fn () callconv(.C) ?[*:0]const u8;
|
|
629
|
+
const GetCursorScreenPointFn = *const fn () callconv(.C) ?[*:0]const u8;
|
|
630
|
+
const MoveToTrashFn = *const fn ([*:0]const u8) callconv(.C) bool;
|
|
631
|
+
const ShowItemInFolderFn = *const fn ([*:0]const u8) callconv(.C) void;
|
|
632
|
+
const OpenExternalFn = *const fn ([*:0]const u8) callconv(.C) bool;
|
|
633
|
+
const OpenPathFn = *const fn ([*:0]const u8) callconv(.C) bool;
|
|
634
|
+
const ShowNotificationFn = *const fn ([*:0]const u8, [*:0]const u8, [*:0]const u8, bool) callconv(.C) void;
|
|
635
|
+
const ClipboardReadTextFn = *const fn () callconv(.C) ?[*:0]const u8;
|
|
636
|
+
const ClipboardWriteTextFn = *const fn ([*:0]const u8) callconv(.C) void;
|
|
637
|
+
const ClipboardClearFn = *const fn () callconv(.C) void;
|
|
638
|
+
const ClipboardAvailableFormatsFn = *const fn () callconv(.C) ?[*:0]const u8;
|
|
639
|
+
const SetApplicationMenuFn = *const fn ([*:0]const u8, ?StatusItemHandler) callconv(.C) void;
|
|
640
|
+
const ShowContextMenuFn = *const fn ([*:0]const u8, ?StatusItemHandler) callconv(.C) void;
|
|
641
|
+
const OpenFileDialogFn = *const fn ([*:0]const u8, [*:0]const u8, c_int, c_int, c_int) callconv(.C) ?[*:0]const u8;
|
|
642
|
+
const ShowMessageBoxFn = *const fn ([*:0]const u8, [*:0]const u8, [*:0]const u8, [*:0]const u8, [*:0]const u8, c_int, c_int) callconv(.C) c_int;
|
|
643
|
+
const SetGlobalShortcutCallbackFn = *const fn (?GlobalShortcutHandler) callconv(.C) void;
|
|
644
|
+
const RegisterGlobalShortcutFn = *const fn ([*:0]const u8) callconv(.C) bool;
|
|
645
|
+
const UnregisterGlobalShortcutFn = *const fn ([*:0]const u8) callconv(.C) bool;
|
|
646
|
+
const UnregisterAllGlobalShortcutsFn = *const fn () callconv(.C) void;
|
|
647
|
+
const IsGlobalShortcutRegisteredFn = *const fn ([*:0]const u8) callconv(.C) bool;
|
|
648
|
+
const SessionGetCookiesFn = *const fn ([*:0]const u8, [*:0]const u8) callconv(.C) ?[*:0]const u8;
|
|
649
|
+
const SessionSetCookieFn = *const fn ([*:0]const u8, [*:0]const u8) callconv(.C) bool;
|
|
650
|
+
const SessionRemoveCookieFn = *const fn ([*:0]const u8, [*:0]const u8, [*:0]const u8) callconv(.C) bool;
|
|
651
|
+
const SessionClearCookiesFn = *const fn ([*:0]const u8) callconv(.C) void;
|
|
652
|
+
const SessionClearStorageDataFn = *const fn ([*:0]const u8, [*:0]const u8) callconv(.C) void;
|
|
653
|
+
const SetURLOpenHandlerFn = *const fn (?URLOpenHandler) callconv(.C) void;
|
|
654
|
+
const SetAppReopenHandlerFn = *const fn (?AppReopenHandler) callconv(.C) void;
|
|
655
|
+
const SetQuitRequestedHandlerFn = *const fn (?QuitRequestedHandler) callconv(.C) void;
|
|
656
|
+
const StopEventLoopFn = *const fn () callconv(.C) void;
|
|
657
|
+
const WaitForShutdownCompleteFn = *const fn (c_int) callconv(.C) void;
|
|
658
|
+
const ForceExitFn = *const fn (c_int) callconv(.C) void;
|
|
659
|
+
const WgpuCreateSurfaceForViewFn = *const fn (?*anyopaque, ?*anyopaque) callconv(.C) ?*anyopaque;
|
|
660
|
+
const WgpuCreateAdapterDeviceMainThreadFn = *const fn (?*anyopaque, ?*anyopaque, ?*anyopaque) callconv(.C) void;
|
|
661
|
+
const WgpuSurfaceConfigureMainThreadFn = *const fn (?*anyopaque, ?*anyopaque) callconv(.C) void;
|
|
662
|
+
const WgpuSurfaceGetCurrentTextureMainThreadFn = *const fn (?*anyopaque, ?*anyopaque) callconv(.C) void;
|
|
663
|
+
const WgpuSurfacePresentMainThreadFn = *const fn (?*anyopaque) callconv(.C) i32;
|
|
664
|
+
|
|
665
|
+
const Symbols = struct {
|
|
666
|
+
last_error: LastErrorFn,
|
|
667
|
+
run_main_thread: RunMainThreadFn,
|
|
668
|
+
configure_webview_runtime: ConfigureWebviewRuntimeFn,
|
|
669
|
+
get_window_style: GetWindowStyleFn,
|
|
670
|
+
create_window: CreateWindowFn,
|
|
671
|
+
create_webview: CreateWebviewFn,
|
|
672
|
+
create_wgpu_view: CreateWGPUViewFn,
|
|
673
|
+
set_window_title: SetWindowTitleFn,
|
|
674
|
+
minimize_window: MinimizeWindowFn,
|
|
675
|
+
restore_window: RestoreWindowFn,
|
|
676
|
+
is_window_minimized: IsWindowMinimizedFn,
|
|
677
|
+
maximize_window: MaximizeWindowFn,
|
|
678
|
+
unmaximize_window: UnmaximizeWindowFn,
|
|
679
|
+
is_window_maximized: IsWindowMaximizedFn,
|
|
680
|
+
set_window_full_screen: SetWindowFullScreenFn,
|
|
681
|
+
is_window_full_screen: IsWindowFullScreenFn,
|
|
682
|
+
set_window_always_on_top: SetWindowAlwaysOnTopFn,
|
|
683
|
+
is_window_always_on_top: IsWindowAlwaysOnTopFn,
|
|
684
|
+
set_window_visible_on_all_workspaces: SetWindowVisibleOnAllWorkspacesFn,
|
|
685
|
+
is_window_visible_on_all_workspaces: IsWindowVisibleOnAllWorkspacesFn,
|
|
686
|
+
show_window: ShowWindowFn,
|
|
687
|
+
activate_window: ActivateWindowFn,
|
|
688
|
+
hide_window: HideWindowFn,
|
|
689
|
+
set_window_button_position: SetWindowButtonPositionFn,
|
|
690
|
+
set_window_position: SetWindowPositionFn,
|
|
691
|
+
set_window_size: SetWindowSizeFn,
|
|
692
|
+
set_window_frame: SetWindowFrameFn,
|
|
693
|
+
get_window_frame: GetWindowFrameFn,
|
|
694
|
+
close_window: CloseWindowFn,
|
|
695
|
+
resize_webview: ResizeWebviewFn,
|
|
696
|
+
load_url_in_webview: LoadURLInWebViewFn,
|
|
697
|
+
load_html_in_webview: LoadHTMLInWebViewFn,
|
|
698
|
+
update_preload_script_to_webview: UpdatePreloadScriptToWebViewFn,
|
|
699
|
+
webview_can_go_back: WebviewCanGoBackFn,
|
|
700
|
+
webview_can_go_forward: WebviewCanGoForwardFn,
|
|
701
|
+
webview_go_back: WebviewGoBackFn,
|
|
702
|
+
webview_go_forward: WebviewGoForwardFn,
|
|
703
|
+
webview_reload: WebviewReloadFn,
|
|
704
|
+
webview_remove: WebviewRemoveFn,
|
|
705
|
+
set_webview_html_content: SetWebviewHTMLContentFn,
|
|
706
|
+
webview_set_transparent: WebviewSetTransparentFn,
|
|
707
|
+
webview_set_passthrough: WebviewSetPassthroughFn,
|
|
708
|
+
webview_set_hidden: WebviewSetHiddenFn,
|
|
709
|
+
set_webview_navigation_rules: SetWebviewNavigationRulesFn,
|
|
710
|
+
webview_find_in_page: WebviewFindInPageFn,
|
|
711
|
+
webview_stop_find: WebviewStopFindFn,
|
|
712
|
+
send_internal_message_to_webview: SendInternalMessageToWebviewFn,
|
|
713
|
+
webview_open_devtools: WebviewOpenDevToolsFn,
|
|
714
|
+
webview_close_devtools: WebviewCloseDevToolsFn,
|
|
715
|
+
webview_toggle_devtools: WebviewToggleDevToolsFn,
|
|
716
|
+
webview_set_page_zoom: WebviewSetPageZoomFn,
|
|
717
|
+
webview_get_page_zoom: WebviewGetPageZoomFn,
|
|
718
|
+
set_wgpu_view_frame: SetWGPUViewFrameFn,
|
|
719
|
+
resize_wgpu_view: ResizeWGPUViewFn,
|
|
720
|
+
set_wgpu_view_transparent: SetWGPUViewTransparentFn,
|
|
721
|
+
set_wgpu_view_passthrough: SetWGPUViewPassthroughFn,
|
|
722
|
+
set_wgpu_view_hidden: SetWGPUViewHiddenFn,
|
|
723
|
+
remove_wgpu_view: RemoveWGPUViewFn,
|
|
724
|
+
get_wgpu_view_pointer: GetWGPUViewPointerFn,
|
|
725
|
+
get_wgpu_view_native_handle: GetWGPUViewNativeHandleFn,
|
|
726
|
+
run_wgpu_view_test: RunWGPUViewTestFn,
|
|
727
|
+
toggle_wgpu_view_test_shader: ToggleWGPUViewTestShaderFn,
|
|
728
|
+
evaluate_javascript_with_no_completion: EvaluateJavaScriptWithNoCompletionFn,
|
|
729
|
+
create_tray: CreateTrayFn,
|
|
730
|
+
show_tray: ShowTrayFn,
|
|
731
|
+
hide_tray: HideTrayFn,
|
|
732
|
+
set_tray_title: SetTrayTitleFn,
|
|
733
|
+
remove_tray: RemoveTrayFn,
|
|
734
|
+
get_tray_bounds: GetTrayBoundsFn,
|
|
735
|
+
set_dock_icon_visible: SetDockIconVisibleFn,
|
|
736
|
+
is_dock_icon_visible: IsDockIconVisibleFn,
|
|
737
|
+
get_primary_display: GetPrimaryDisplayFn,
|
|
738
|
+
get_all_displays: GetAllDisplaysFn,
|
|
739
|
+
get_cursor_screen_point: GetCursorScreenPointFn,
|
|
740
|
+
move_to_trash: MoveToTrashFn,
|
|
741
|
+
show_item_in_folder: ShowItemInFolderFn,
|
|
742
|
+
open_external: OpenExternalFn,
|
|
743
|
+
open_path: OpenPathFn,
|
|
744
|
+
show_notification: ShowNotificationFn,
|
|
745
|
+
clipboard_read_text: ClipboardReadTextFn,
|
|
746
|
+
clipboard_write_text: ClipboardWriteTextFn,
|
|
747
|
+
clipboard_clear: ClipboardClearFn,
|
|
748
|
+
clipboard_available_formats: ClipboardAvailableFormatsFn,
|
|
749
|
+
set_application_menu: SetApplicationMenuFn,
|
|
750
|
+
show_context_menu: ShowContextMenuFn,
|
|
751
|
+
open_file_dialog: OpenFileDialogFn,
|
|
752
|
+
show_message_box: ShowMessageBoxFn,
|
|
753
|
+
set_global_shortcut_callback: SetGlobalShortcutCallbackFn,
|
|
754
|
+
register_global_shortcut: RegisterGlobalShortcutFn,
|
|
755
|
+
unregister_global_shortcut: UnregisterGlobalShortcutFn,
|
|
756
|
+
unregister_all_global_shortcuts: UnregisterAllGlobalShortcutsFn,
|
|
757
|
+
is_global_shortcut_registered: IsGlobalShortcutRegisteredFn,
|
|
758
|
+
session_get_cookies: SessionGetCookiesFn,
|
|
759
|
+
session_set_cookie: SessionSetCookieFn,
|
|
760
|
+
session_remove_cookie: SessionRemoveCookieFn,
|
|
761
|
+
session_clear_cookies: SessionClearCookiesFn,
|
|
762
|
+
session_clear_storage_data: SessionClearStorageDataFn,
|
|
763
|
+
set_url_open_handler: SetURLOpenHandlerFn,
|
|
764
|
+
set_app_reopen_handler: SetAppReopenHandlerFn,
|
|
765
|
+
set_quit_requested_handler: SetQuitRequestedHandlerFn,
|
|
766
|
+
stop_event_loop: StopEventLoopFn,
|
|
767
|
+
wait_for_shutdown_complete: WaitForShutdownCompleteFn,
|
|
768
|
+
force_exit: ForceExitFn,
|
|
769
|
+
wgpu_create_surface_for_view: WgpuCreateSurfaceForViewFn,
|
|
770
|
+
wgpu_create_adapter_device_main_thread: WgpuCreateAdapterDeviceMainThreadFn,
|
|
771
|
+
wgpu_surface_configure_main_thread: WgpuSurfaceConfigureMainThreadFn,
|
|
772
|
+
wgpu_surface_get_current_texture_main_thread: WgpuSurfaceGetCurrentTextureMainThreadFn,
|
|
773
|
+
wgpu_surface_present_main_thread: WgpuSurfacePresentMainThreadFn,
|
|
774
|
+
};
|
|
775
|
+
|
|
776
|
+
pub fn load(allocator: std.mem.Allocator) !Core {
|
|
777
|
+
const bundle_paths = try resolveBundlePaths(allocator);
|
|
778
|
+
defer bundle_paths.deinit(allocator);
|
|
779
|
+
|
|
780
|
+
const lib_name = switch (builtin.os.tag) {
|
|
781
|
+
.windows => "ElectrobunCore.dll",
|
|
782
|
+
.macos => "libElectrobunCore.dylib",
|
|
783
|
+
else => "libElectrobunCore.so",
|
|
784
|
+
};
|
|
785
|
+
const lib_path = try std.fs.path.join(allocator, &.{ bundle_paths.exe_dir, lib_name });
|
|
786
|
+
defer allocator.free(lib_path);
|
|
787
|
+
|
|
788
|
+
var lib = try std.DynLib.open(lib_path);
|
|
789
|
+
|
|
790
|
+
return .{
|
|
791
|
+
.allocator = allocator,
|
|
792
|
+
.lib = lib,
|
|
793
|
+
.symbols = .{
|
|
794
|
+
.last_error = lib.lookup(LastErrorFn, "electrobun_core_last_error") orelse return error.MissingCoreSymbol,
|
|
795
|
+
.run_main_thread = lib.lookup(RunMainThreadFn, "electrobun_core_run_main_thread") orelse return error.MissingCoreSymbol,
|
|
796
|
+
.configure_webview_runtime = lib.lookup(ConfigureWebviewRuntimeFn, "configureWebviewRuntime") orelse return error.MissingCoreSymbol,
|
|
797
|
+
.get_window_style = lib.lookup(GetWindowStyleFn, "getWindowStyle") orelse return error.MissingCoreSymbol,
|
|
798
|
+
.create_window = lib.lookup(CreateWindowFn, "createWindow") orelse return error.MissingCoreSymbol,
|
|
799
|
+
.create_webview = lib.lookup(CreateWebviewFn, "createWebview") orelse return error.MissingCoreSymbol,
|
|
800
|
+
.create_wgpu_view = lib.lookup(CreateWGPUViewFn, "createWGPUView") orelse return error.MissingCoreSymbol,
|
|
801
|
+
.set_window_title = lib.lookup(SetWindowTitleFn, "setWindowTitle") orelse return error.MissingCoreSymbol,
|
|
802
|
+
.minimize_window = lib.lookup(MinimizeWindowFn, "minimizeWindow") orelse return error.MissingCoreSymbol,
|
|
803
|
+
.restore_window = lib.lookup(RestoreWindowFn, "restoreWindow") orelse return error.MissingCoreSymbol,
|
|
804
|
+
.is_window_minimized = lib.lookup(IsWindowMinimizedFn, "isWindowMinimized") orelse return error.MissingCoreSymbol,
|
|
805
|
+
.maximize_window = lib.lookup(MaximizeWindowFn, "maximizeWindow") orelse return error.MissingCoreSymbol,
|
|
806
|
+
.unmaximize_window = lib.lookup(UnmaximizeWindowFn, "unmaximizeWindow") orelse return error.MissingCoreSymbol,
|
|
807
|
+
.is_window_maximized = lib.lookup(IsWindowMaximizedFn, "isWindowMaximized") orelse return error.MissingCoreSymbol,
|
|
808
|
+
.set_window_full_screen = lib.lookup(SetWindowFullScreenFn, "setWindowFullScreen") orelse return error.MissingCoreSymbol,
|
|
809
|
+
.is_window_full_screen = lib.lookup(IsWindowFullScreenFn, "isWindowFullScreen") orelse return error.MissingCoreSymbol,
|
|
810
|
+
.set_window_always_on_top = lib.lookup(SetWindowAlwaysOnTopFn, "setWindowAlwaysOnTop") orelse return error.MissingCoreSymbol,
|
|
811
|
+
.is_window_always_on_top = lib.lookup(IsWindowAlwaysOnTopFn, "isWindowAlwaysOnTop") orelse return error.MissingCoreSymbol,
|
|
812
|
+
.set_window_visible_on_all_workspaces = lib.lookup(SetWindowVisibleOnAllWorkspacesFn, "setWindowVisibleOnAllWorkspaces") orelse return error.MissingCoreSymbol,
|
|
813
|
+
.is_window_visible_on_all_workspaces = lib.lookup(IsWindowVisibleOnAllWorkspacesFn, "isWindowVisibleOnAllWorkspaces") orelse return error.MissingCoreSymbol,
|
|
814
|
+
.show_window = lib.lookup(ShowWindowFn, "showWindow") orelse return error.MissingCoreSymbol,
|
|
815
|
+
.activate_window = lib.lookup(ActivateWindowFn, "activateWindow") orelse return error.MissingCoreSymbol,
|
|
816
|
+
.hide_window = lib.lookup(HideWindowFn, "hideWindow") orelse return error.MissingCoreSymbol,
|
|
817
|
+
.set_window_button_position = lib.lookup(SetWindowButtonPositionFn, "setWindowButtonPosition") orelse return error.MissingCoreSymbol,
|
|
818
|
+
.set_window_position = lib.lookup(SetWindowPositionFn, "setWindowPosition") orelse return error.MissingCoreSymbol,
|
|
819
|
+
.set_window_size = lib.lookup(SetWindowSizeFn, "setWindowSize") orelse return error.MissingCoreSymbol,
|
|
820
|
+
.set_window_frame = lib.lookup(SetWindowFrameFn, "setWindowFrame") orelse return error.MissingCoreSymbol,
|
|
821
|
+
.get_window_frame = lib.lookup(GetWindowFrameFn, "getWindowFrame") orelse return error.MissingCoreSymbol,
|
|
822
|
+
.close_window = lib.lookup(CloseWindowFn, "closeWindow") orelse return error.MissingCoreSymbol,
|
|
823
|
+
.resize_webview = lib.lookup(ResizeWebviewFn, "resizeWebview") orelse return error.MissingCoreSymbol,
|
|
824
|
+
.load_url_in_webview = lib.lookup(LoadURLInWebViewFn, "loadURLInWebView") orelse return error.MissingCoreSymbol,
|
|
825
|
+
.load_html_in_webview = lib.lookup(LoadHTMLInWebViewFn, "loadHTMLInWebView") orelse return error.MissingCoreSymbol,
|
|
826
|
+
.update_preload_script_to_webview = lib.lookup(UpdatePreloadScriptToWebViewFn, "updatePreloadScriptToWebView") orelse return error.MissingCoreSymbol,
|
|
827
|
+
.webview_can_go_back = lib.lookup(WebviewCanGoBackFn, "webviewCanGoBack") orelse return error.MissingCoreSymbol,
|
|
828
|
+
.webview_can_go_forward = lib.lookup(WebviewCanGoForwardFn, "webviewCanGoForward") orelse return error.MissingCoreSymbol,
|
|
829
|
+
.webview_go_back = lib.lookup(WebviewGoBackFn, "webviewGoBack") orelse return error.MissingCoreSymbol,
|
|
830
|
+
.webview_go_forward = lib.lookup(WebviewGoForwardFn, "webviewGoForward") orelse return error.MissingCoreSymbol,
|
|
831
|
+
.webview_reload = lib.lookup(WebviewReloadFn, "webviewReload") orelse return error.MissingCoreSymbol,
|
|
832
|
+
.webview_remove = lib.lookup(WebviewRemoveFn, "webviewRemove") orelse return error.MissingCoreSymbol,
|
|
833
|
+
.set_webview_html_content = lib.lookup(SetWebviewHTMLContentFn, "setWebviewHTMLContent") orelse return error.MissingCoreSymbol,
|
|
834
|
+
.webview_set_transparent = lib.lookup(WebviewSetTransparentFn, "webviewSetTransparent") orelse return error.MissingCoreSymbol,
|
|
835
|
+
.webview_set_passthrough = lib.lookup(WebviewSetPassthroughFn, "webviewSetPassthrough") orelse return error.MissingCoreSymbol,
|
|
836
|
+
.webview_set_hidden = lib.lookup(WebviewSetHiddenFn, "webviewSetHidden") orelse return error.MissingCoreSymbol,
|
|
837
|
+
.set_webview_navigation_rules = lib.lookup(SetWebviewNavigationRulesFn, "setWebviewNavigationRules") orelse return error.MissingCoreSymbol,
|
|
838
|
+
.webview_find_in_page = lib.lookup(WebviewFindInPageFn, "webviewFindInPage") orelse return error.MissingCoreSymbol,
|
|
839
|
+
.webview_stop_find = lib.lookup(WebviewStopFindFn, "webviewStopFind") orelse return error.MissingCoreSymbol,
|
|
840
|
+
.send_internal_message_to_webview = lib.lookup(SendInternalMessageToWebviewFn, "sendInternalMessageToWebview") orelse return error.MissingCoreSymbol,
|
|
841
|
+
.webview_open_devtools = lib.lookup(WebviewOpenDevToolsFn, "webviewOpenDevTools") orelse return error.MissingCoreSymbol,
|
|
842
|
+
.webview_close_devtools = lib.lookup(WebviewCloseDevToolsFn, "webviewCloseDevTools") orelse return error.MissingCoreSymbol,
|
|
843
|
+
.webview_toggle_devtools = lib.lookup(WebviewToggleDevToolsFn, "webviewToggleDevTools") orelse return error.MissingCoreSymbol,
|
|
844
|
+
.webview_set_page_zoom = lib.lookup(WebviewSetPageZoomFn, "webviewSetPageZoom") orelse return error.MissingCoreSymbol,
|
|
845
|
+
.webview_get_page_zoom = lib.lookup(WebviewGetPageZoomFn, "webviewGetPageZoom") orelse return error.MissingCoreSymbol,
|
|
846
|
+
.set_wgpu_view_frame = lib.lookup(SetWGPUViewFrameFn, "setWGPUViewFrame") orelse return error.MissingCoreSymbol,
|
|
847
|
+
.resize_wgpu_view = lib.lookup(ResizeWGPUViewFn, "resizeWGPUView") orelse return error.MissingCoreSymbol,
|
|
848
|
+
.set_wgpu_view_transparent = lib.lookup(SetWGPUViewTransparentFn, "setWGPUViewTransparent") orelse return error.MissingCoreSymbol,
|
|
849
|
+
.set_wgpu_view_passthrough = lib.lookup(SetWGPUViewPassthroughFn, "setWGPUViewPassthrough") orelse return error.MissingCoreSymbol,
|
|
850
|
+
.set_wgpu_view_hidden = lib.lookup(SetWGPUViewHiddenFn, "setWGPUViewHidden") orelse return error.MissingCoreSymbol,
|
|
851
|
+
.remove_wgpu_view = lib.lookup(RemoveWGPUViewFn, "removeWGPUView") orelse return error.MissingCoreSymbol,
|
|
852
|
+
.get_wgpu_view_pointer = lib.lookup(GetWGPUViewPointerFn, "getWGPUViewPointer") orelse return error.MissingCoreSymbol,
|
|
853
|
+
.get_wgpu_view_native_handle = lib.lookup(GetWGPUViewNativeHandleFn, "getWGPUViewNativeHandle") orelse return error.MissingCoreSymbol,
|
|
854
|
+
.run_wgpu_view_test = lib.lookup(RunWGPUViewTestFn, "runWGPUViewTest") orelse return error.MissingCoreSymbol,
|
|
855
|
+
.toggle_wgpu_view_test_shader = lib.lookup(ToggleWGPUViewTestShaderFn, "toggleWGPUViewTestShader") orelse return error.MissingCoreSymbol,
|
|
856
|
+
.evaluate_javascript_with_no_completion = lib.lookup(EvaluateJavaScriptWithNoCompletionFn, "evaluateJavaScriptWithNoCompletion") orelse return error.MissingCoreSymbol,
|
|
857
|
+
.create_tray = lib.lookup(CreateTrayFn, "createTray") orelse return error.MissingCoreSymbol,
|
|
858
|
+
.show_tray = lib.lookup(ShowTrayFn, "showTray") orelse return error.MissingCoreSymbol,
|
|
859
|
+
.hide_tray = lib.lookup(HideTrayFn, "hideTray") orelse return error.MissingCoreSymbol,
|
|
860
|
+
.set_tray_title = lib.lookup(SetTrayTitleFn, "setTrayTitle") orelse return error.MissingCoreSymbol,
|
|
861
|
+
.remove_tray = lib.lookup(RemoveTrayFn, "removeTray") orelse return error.MissingCoreSymbol,
|
|
862
|
+
.get_tray_bounds = lib.lookup(GetTrayBoundsFn, "getTrayBounds") orelse return error.MissingCoreSymbol,
|
|
863
|
+
.set_dock_icon_visible = lib.lookup(SetDockIconVisibleFn, "setDockIconVisible") orelse return error.MissingCoreSymbol,
|
|
864
|
+
.is_dock_icon_visible = lib.lookup(IsDockIconVisibleFn, "isDockIconVisible") orelse return error.MissingCoreSymbol,
|
|
865
|
+
.get_primary_display = lib.lookup(GetPrimaryDisplayFn, "getPrimaryDisplay") orelse return error.MissingCoreSymbol,
|
|
866
|
+
.get_all_displays = lib.lookup(GetAllDisplaysFn, "getAllDisplays") orelse return error.MissingCoreSymbol,
|
|
867
|
+
.get_cursor_screen_point = lib.lookup(GetCursorScreenPointFn, "getCursorScreenPoint") orelse return error.MissingCoreSymbol,
|
|
868
|
+
.move_to_trash = lib.lookup(MoveToTrashFn, "moveToTrash") orelse return error.MissingCoreSymbol,
|
|
869
|
+
.show_item_in_folder = lib.lookup(ShowItemInFolderFn, "showItemInFolder") orelse return error.MissingCoreSymbol,
|
|
870
|
+
.open_external = lib.lookup(OpenExternalFn, "openExternal") orelse return error.MissingCoreSymbol,
|
|
871
|
+
.open_path = lib.lookup(OpenPathFn, "openPath") orelse return error.MissingCoreSymbol,
|
|
872
|
+
.show_notification = lib.lookup(ShowNotificationFn, "showNotification") orelse return error.MissingCoreSymbol,
|
|
873
|
+
.clipboard_read_text = lib.lookup(ClipboardReadTextFn, "clipboardReadText") orelse return error.MissingCoreSymbol,
|
|
874
|
+
.clipboard_write_text = lib.lookup(ClipboardWriteTextFn, "clipboardWriteText") orelse return error.MissingCoreSymbol,
|
|
875
|
+
.clipboard_clear = lib.lookup(ClipboardClearFn, "clipboardClear") orelse return error.MissingCoreSymbol,
|
|
876
|
+
.clipboard_available_formats = lib.lookup(ClipboardAvailableFormatsFn, "clipboardAvailableFormats") orelse return error.MissingCoreSymbol,
|
|
877
|
+
.set_application_menu = lib.lookup(SetApplicationMenuFn, "setApplicationMenu") orelse return error.MissingCoreSymbol,
|
|
878
|
+
.show_context_menu = lib.lookup(ShowContextMenuFn, "showContextMenu") orelse return error.MissingCoreSymbol,
|
|
879
|
+
.open_file_dialog = lib.lookup(OpenFileDialogFn, "openFileDialog") orelse return error.MissingCoreSymbol,
|
|
880
|
+
.show_message_box = lib.lookup(ShowMessageBoxFn, "showMessageBox") orelse return error.MissingCoreSymbol,
|
|
881
|
+
.set_global_shortcut_callback = lib.lookup(SetGlobalShortcutCallbackFn, "setGlobalShortcutCallback") orelse return error.MissingCoreSymbol,
|
|
882
|
+
.register_global_shortcut = lib.lookup(RegisterGlobalShortcutFn, "registerGlobalShortcut") orelse return error.MissingCoreSymbol,
|
|
883
|
+
.unregister_global_shortcut = lib.lookup(UnregisterGlobalShortcutFn, "unregisterGlobalShortcut") orelse return error.MissingCoreSymbol,
|
|
884
|
+
.unregister_all_global_shortcuts = lib.lookup(UnregisterAllGlobalShortcutsFn, "unregisterAllGlobalShortcuts") orelse return error.MissingCoreSymbol,
|
|
885
|
+
.is_global_shortcut_registered = lib.lookup(IsGlobalShortcutRegisteredFn, "isGlobalShortcutRegistered") orelse return error.MissingCoreSymbol,
|
|
886
|
+
.session_get_cookies = lib.lookup(SessionGetCookiesFn, "sessionGetCookies") orelse return error.MissingCoreSymbol,
|
|
887
|
+
.session_set_cookie = lib.lookup(SessionSetCookieFn, "sessionSetCookie") orelse return error.MissingCoreSymbol,
|
|
888
|
+
.session_remove_cookie = lib.lookup(SessionRemoveCookieFn, "sessionRemoveCookie") orelse return error.MissingCoreSymbol,
|
|
889
|
+
.session_clear_cookies = lib.lookup(SessionClearCookiesFn, "sessionClearCookies") orelse return error.MissingCoreSymbol,
|
|
890
|
+
.session_clear_storage_data = lib.lookup(SessionClearStorageDataFn, "sessionClearStorageData") orelse return error.MissingCoreSymbol,
|
|
891
|
+
.set_url_open_handler = lib.lookup(SetURLOpenHandlerFn, "setURLOpenHandler") orelse return error.MissingCoreSymbol,
|
|
892
|
+
.set_app_reopen_handler = lib.lookup(SetAppReopenHandlerFn, "setAppReopenHandler") orelse return error.MissingCoreSymbol,
|
|
893
|
+
.set_quit_requested_handler = lib.lookup(SetQuitRequestedHandlerFn, "setQuitRequestedHandler") orelse return error.MissingCoreSymbol,
|
|
894
|
+
.stop_event_loop = lib.lookup(StopEventLoopFn, "stopEventLoop") orelse return error.MissingCoreSymbol,
|
|
895
|
+
.wait_for_shutdown_complete = lib.lookup(WaitForShutdownCompleteFn, "waitForShutdownComplete") orelse return error.MissingCoreSymbol,
|
|
896
|
+
.force_exit = lib.lookup(ForceExitFn, "forceExit") orelse return error.MissingCoreSymbol,
|
|
897
|
+
.wgpu_create_surface_for_view = lib.lookup(WgpuCreateSurfaceForViewFn, "wgpuCreateSurfaceForView") orelse return error.MissingCoreSymbol,
|
|
898
|
+
.wgpu_create_adapter_device_main_thread = lib.lookup(WgpuCreateAdapterDeviceMainThreadFn, "wgpuCreateAdapterDeviceMainThread") orelse return error.MissingCoreSymbol,
|
|
899
|
+
.wgpu_surface_configure_main_thread = lib.lookup(WgpuSurfaceConfigureMainThreadFn, "wgpuSurfaceConfigureMainThread") orelse return error.MissingCoreSymbol,
|
|
900
|
+
.wgpu_surface_get_current_texture_main_thread = lib.lookup(WgpuSurfaceGetCurrentTextureMainThreadFn, "wgpuSurfaceGetCurrentTextureMainThread") orelse return error.MissingCoreSymbol,
|
|
901
|
+
.wgpu_surface_present_main_thread = lib.lookup(WgpuSurfacePresentMainThreadFn, "wgpuSurfacePresentMainThread") orelse return error.MissingCoreSymbol,
|
|
902
|
+
},
|
|
903
|
+
};
|
|
904
|
+
}
|
|
905
|
+
|
|
906
|
+
pub fn close(self: *Core) void {
|
|
907
|
+
self.lib.close();
|
|
908
|
+
}
|
|
909
|
+
|
|
910
|
+
fn lastError(self: *Core) []const u8 {
|
|
911
|
+
return std.mem.span(self.symbols.last_error());
|
|
912
|
+
}
|
|
913
|
+
|
|
914
|
+
fn dupeZ(self: *Core, value: []const u8) ![:0]u8 {
|
|
915
|
+
return try self.allocator.dupeZ(u8, value);
|
|
916
|
+
}
|
|
917
|
+
|
|
918
|
+
pub fn configureWebviewRuntimeFromExecutableDir(self: *Core, bundle_paths: *const BundlePaths, rpc_port: u32) !void {
|
|
919
|
+
const full_path = try std.fs.path.join(self.allocator, &.{ bundle_paths.resources_dir, "preload-full.js" });
|
|
920
|
+
defer self.allocator.free(full_path);
|
|
921
|
+
const sandboxed_path = try std.fs.path.join(self.allocator, &.{ bundle_paths.resources_dir, "preload-sandboxed.js" });
|
|
922
|
+
defer self.allocator.free(sandboxed_path);
|
|
923
|
+
|
|
924
|
+
const full_preload = try readFileZ(self.allocator, full_path);
|
|
925
|
+
defer self.allocator.free(full_preload);
|
|
926
|
+
const sandboxed_preload = try readFileZ(self.allocator, sandboxed_path);
|
|
927
|
+
defer self.allocator.free(sandboxed_preload);
|
|
928
|
+
|
|
929
|
+
if (!self.symbols.configure_webview_runtime(rpc_port, full_preload.ptr, sandboxed_preload.ptr)) {
|
|
930
|
+
return errorFromLastError(self.lastError());
|
|
931
|
+
}
|
|
932
|
+
}
|
|
933
|
+
|
|
934
|
+
pub fn defaultWindowStyle(self: *Core) u32 {
|
|
935
|
+
return self.symbols.get_window_style(
|
|
936
|
+
false,
|
|
937
|
+
true,
|
|
938
|
+
true,
|
|
939
|
+
true,
|
|
940
|
+
true,
|
|
941
|
+
false,
|
|
942
|
+
false,
|
|
943
|
+
false,
|
|
944
|
+
false,
|
|
945
|
+
false,
|
|
946
|
+
false,
|
|
947
|
+
false,
|
|
948
|
+
);
|
|
949
|
+
}
|
|
950
|
+
|
|
951
|
+
pub fn createWindow(self: *Core, options: WindowOptions) !u32 {
|
|
952
|
+
const title_z = try self.dupeZ(options.title);
|
|
953
|
+
defer self.allocator.free(title_z);
|
|
954
|
+
const title_bar_style_z = try self.dupeZ(options.title_bar_style);
|
|
955
|
+
defer self.allocator.free(title_bar_style_z);
|
|
956
|
+
|
|
957
|
+
const style_mask = self.symbols.get_window_style(
|
|
958
|
+
options.style.borderless,
|
|
959
|
+
options.style.titled,
|
|
960
|
+
options.style.closable,
|
|
961
|
+
options.style.miniaturizable,
|
|
962
|
+
options.style.resizable,
|
|
963
|
+
options.style.unified_title_and_toolbar,
|
|
964
|
+
options.style.full_screen,
|
|
965
|
+
options.style.full_size_content_view,
|
|
966
|
+
options.style.utility_window,
|
|
967
|
+
options.style.doc_modal_window,
|
|
968
|
+
options.style.nonactivating_panel,
|
|
969
|
+
options.style.hud_window,
|
|
970
|
+
);
|
|
971
|
+
|
|
972
|
+
const window_id = self.symbols.create_window(
|
|
973
|
+
options.frame.x,
|
|
974
|
+
options.frame.y,
|
|
975
|
+
options.frame.width,
|
|
976
|
+
options.frame.height,
|
|
977
|
+
style_mask,
|
|
978
|
+
title_bar_style_z.ptr,
|
|
979
|
+
options.transparent,
|
|
980
|
+
title_z.ptr,
|
|
981
|
+
options.hidden,
|
|
982
|
+
options.activate,
|
|
983
|
+
options.traffic_light_offset.x,
|
|
984
|
+
options.traffic_light_offset.y,
|
|
985
|
+
options.callbacks.close,
|
|
986
|
+
options.callbacks.move,
|
|
987
|
+
options.callbacks.resize,
|
|
988
|
+
options.callbacks.focus,
|
|
989
|
+
options.callbacks.blur,
|
|
990
|
+
options.callbacks.key,
|
|
991
|
+
);
|
|
992
|
+
|
|
993
|
+
if (window_id == 0) {
|
|
994
|
+
return errorFromLastError(self.lastError());
|
|
995
|
+
}
|
|
996
|
+
|
|
997
|
+
return window_id;
|
|
998
|
+
}
|
|
999
|
+
|
|
1000
|
+
pub fn setWindowTitle(self: *Core, window_id: u32, title: []const u8) !void {
|
|
1001
|
+
const title_z = try self.dupeZ(title);
|
|
1002
|
+
defer self.allocator.free(title_z);
|
|
1003
|
+
self.symbols.set_window_title(window_id, title_z.ptr);
|
|
1004
|
+
try self.ensureLastCallSucceeded();
|
|
1005
|
+
}
|
|
1006
|
+
|
|
1007
|
+
pub fn minimizeWindow(self: *Core, window_id: u32) !void {
|
|
1008
|
+
self.symbols.minimize_window(window_id);
|
|
1009
|
+
try self.ensureLastCallSucceeded();
|
|
1010
|
+
}
|
|
1011
|
+
|
|
1012
|
+
pub fn restoreWindow(self: *Core, window_id: u32) !void {
|
|
1013
|
+
self.symbols.restore_window(window_id);
|
|
1014
|
+
try self.ensureLastCallSucceeded();
|
|
1015
|
+
}
|
|
1016
|
+
|
|
1017
|
+
pub fn isWindowMinimized(self: *Core, window_id: u32) bool {
|
|
1018
|
+
return self.symbols.is_window_minimized(window_id);
|
|
1019
|
+
}
|
|
1020
|
+
|
|
1021
|
+
pub fn maximizeWindow(self: *Core, window_id: u32) !void {
|
|
1022
|
+
self.symbols.maximize_window(window_id);
|
|
1023
|
+
try self.ensureLastCallSucceeded();
|
|
1024
|
+
}
|
|
1025
|
+
|
|
1026
|
+
pub fn unmaximizeWindow(self: *Core, window_id: u32) !void {
|
|
1027
|
+
self.symbols.unmaximize_window(window_id);
|
|
1028
|
+
try self.ensureLastCallSucceeded();
|
|
1029
|
+
}
|
|
1030
|
+
|
|
1031
|
+
pub fn isWindowMaximized(self: *Core, window_id: u32) bool {
|
|
1032
|
+
return self.symbols.is_window_maximized(window_id);
|
|
1033
|
+
}
|
|
1034
|
+
|
|
1035
|
+
pub fn setWindowFullScreen(self: *Core, window_id: u32, full_screen: bool) !void {
|
|
1036
|
+
self.symbols.set_window_full_screen(window_id, full_screen);
|
|
1037
|
+
try self.ensureLastCallSucceeded();
|
|
1038
|
+
}
|
|
1039
|
+
|
|
1040
|
+
pub fn isWindowFullScreen(self: *Core, window_id: u32) bool {
|
|
1041
|
+
return self.symbols.is_window_full_screen(window_id);
|
|
1042
|
+
}
|
|
1043
|
+
|
|
1044
|
+
pub fn setWindowAlwaysOnTop(self: *Core, window_id: u32, always_on_top: bool) !void {
|
|
1045
|
+
self.symbols.set_window_always_on_top(window_id, always_on_top);
|
|
1046
|
+
try self.ensureLastCallSucceeded();
|
|
1047
|
+
}
|
|
1048
|
+
|
|
1049
|
+
pub fn isWindowAlwaysOnTop(self: *Core, window_id: u32) bool {
|
|
1050
|
+
return self.symbols.is_window_always_on_top(window_id);
|
|
1051
|
+
}
|
|
1052
|
+
|
|
1053
|
+
pub fn setWindowVisibleOnAllWorkspaces(self: *Core, window_id: u32, visible: bool) !void {
|
|
1054
|
+
self.symbols.set_window_visible_on_all_workspaces(window_id, visible);
|
|
1055
|
+
try self.ensureLastCallSucceeded();
|
|
1056
|
+
}
|
|
1057
|
+
|
|
1058
|
+
pub fn isWindowVisibleOnAllWorkspaces(self: *Core, window_id: u32) bool {
|
|
1059
|
+
return self.symbols.is_window_visible_on_all_workspaces(window_id);
|
|
1060
|
+
}
|
|
1061
|
+
|
|
1062
|
+
pub fn showWindow(self: *Core, window_id: u32, activate: bool) !void {
|
|
1063
|
+
self.symbols.show_window(window_id, activate);
|
|
1064
|
+
try self.ensureLastCallSucceeded();
|
|
1065
|
+
}
|
|
1066
|
+
|
|
1067
|
+
pub fn activateWindow(self: *Core, window_id: u32) !void {
|
|
1068
|
+
self.symbols.activate_window(window_id);
|
|
1069
|
+
try self.ensureLastCallSucceeded();
|
|
1070
|
+
}
|
|
1071
|
+
|
|
1072
|
+
pub fn hideWindow(self: *Core, window_id: u32) !void {
|
|
1073
|
+
self.symbols.hide_window(window_id);
|
|
1074
|
+
try self.ensureLastCallSucceeded();
|
|
1075
|
+
}
|
|
1076
|
+
|
|
1077
|
+
pub fn setWindowButtonPosition(self: *Core, window_id: u32, x: f64, y: f64) !void {
|
|
1078
|
+
self.symbols.set_window_button_position(window_id, x, y);
|
|
1079
|
+
try self.ensureLastCallSucceeded();
|
|
1080
|
+
}
|
|
1081
|
+
|
|
1082
|
+
pub fn setWindowPosition(self: *Core, window_id: u32, x: f64, y: f64) !void {
|
|
1083
|
+
self.symbols.set_window_position(window_id, x, y);
|
|
1084
|
+
try self.ensureLastCallSucceeded();
|
|
1085
|
+
}
|
|
1086
|
+
|
|
1087
|
+
pub fn setWindowSize(self: *Core, window_id: u32, width: f64, height: f64) !void {
|
|
1088
|
+
self.symbols.set_window_size(window_id, width, height);
|
|
1089
|
+
try self.ensureLastCallSucceeded();
|
|
1090
|
+
}
|
|
1091
|
+
|
|
1092
|
+
pub fn setWindowFrame(self: *Core, window_id: u32, frame: Rect) !void {
|
|
1093
|
+
self.symbols.set_window_frame(
|
|
1094
|
+
window_id,
|
|
1095
|
+
frame.x,
|
|
1096
|
+
frame.y,
|
|
1097
|
+
frame.width,
|
|
1098
|
+
frame.height,
|
|
1099
|
+
);
|
|
1100
|
+
try self.ensureLastCallSucceeded();
|
|
1101
|
+
}
|
|
1102
|
+
|
|
1103
|
+
pub fn getWindowFrame(self: *Core, window_id: u32) !Rect {
|
|
1104
|
+
var x: f64 = 0;
|
|
1105
|
+
var y: f64 = 0;
|
|
1106
|
+
var width: f64 = 0;
|
|
1107
|
+
var height: f64 = 0;
|
|
1108
|
+
|
|
1109
|
+
self.symbols.get_window_frame(window_id, &x, &y, &width, &height);
|
|
1110
|
+
try self.ensureLastCallSucceeded();
|
|
1111
|
+
|
|
1112
|
+
return .{
|
|
1113
|
+
.x = x,
|
|
1114
|
+
.y = y,
|
|
1115
|
+
.width = width,
|
|
1116
|
+
.height = height,
|
|
1117
|
+
};
|
|
1118
|
+
}
|
|
1119
|
+
|
|
1120
|
+
pub fn closeWindow(self: *Core, window_id: u32) !void {
|
|
1121
|
+
self.symbols.close_window(window_id);
|
|
1122
|
+
try self.ensureLastCallSucceeded();
|
|
1123
|
+
}
|
|
1124
|
+
|
|
1125
|
+
pub fn createWebview(self: *Core, options: WebviewOptions) !u32 {
|
|
1126
|
+
const renderer_z = try self.dupeZ(@tagName(options.renderer));
|
|
1127
|
+
defer self.allocator.free(renderer_z);
|
|
1128
|
+
const url_z = try self.dupeZ(options.url);
|
|
1129
|
+
defer self.allocator.free(url_z);
|
|
1130
|
+
const partition_z = try self.dupeZ(options.partition);
|
|
1131
|
+
defer self.allocator.free(partition_z);
|
|
1132
|
+
const secret_key_z = try self.dupeZ(options.secret_key);
|
|
1133
|
+
defer self.allocator.free(secret_key_z);
|
|
1134
|
+
const preload_z = try self.dupeZ(options.preload);
|
|
1135
|
+
defer self.allocator.free(preload_z);
|
|
1136
|
+
const views_root_z = try self.dupeZ(options.views_root);
|
|
1137
|
+
defer self.allocator.free(views_root_z);
|
|
1138
|
+
|
|
1139
|
+
const webview_id = self.symbols.create_webview(
|
|
1140
|
+
options.window_id,
|
|
1141
|
+
options.host_webview_id,
|
|
1142
|
+
renderer_z.ptr,
|
|
1143
|
+
url_z.ptr,
|
|
1144
|
+
options.frame.x,
|
|
1145
|
+
options.frame.y,
|
|
1146
|
+
options.frame.width,
|
|
1147
|
+
options.frame.height,
|
|
1148
|
+
options.auto_resize,
|
|
1149
|
+
partition_z.ptr,
|
|
1150
|
+
options.callbacks.decide_navigation,
|
|
1151
|
+
options.callbacks.event,
|
|
1152
|
+
options.callbacks.event_bridge,
|
|
1153
|
+
options.callbacks.bun_bridge,
|
|
1154
|
+
options.callbacks.internal_bridge,
|
|
1155
|
+
secret_key_z.ptr,
|
|
1156
|
+
preload_z.ptr,
|
|
1157
|
+
views_root_z.ptr,
|
|
1158
|
+
options.sandbox,
|
|
1159
|
+
options.start_transparent,
|
|
1160
|
+
options.start_passthrough,
|
|
1161
|
+
);
|
|
1162
|
+
|
|
1163
|
+
if (webview_id == 0) {
|
|
1164
|
+
return errorFromLastError(self.lastError());
|
|
1165
|
+
}
|
|
1166
|
+
|
|
1167
|
+
return webview_id;
|
|
1168
|
+
}
|
|
1169
|
+
|
|
1170
|
+
pub fn resizeWebview(self: *Core, webview_id: u32, frame: Rect, masks_json: []const u8) !void {
|
|
1171
|
+
const masks_json_z = try self.dupeZ(masks_json);
|
|
1172
|
+
defer self.allocator.free(masks_json_z);
|
|
1173
|
+
|
|
1174
|
+
self.symbols.resize_webview(
|
|
1175
|
+
webview_id,
|
|
1176
|
+
frame.x,
|
|
1177
|
+
frame.y,
|
|
1178
|
+
frame.width,
|
|
1179
|
+
frame.height,
|
|
1180
|
+
masks_json_z.ptr,
|
|
1181
|
+
);
|
|
1182
|
+
try self.ensureLastCallSucceeded();
|
|
1183
|
+
}
|
|
1184
|
+
|
|
1185
|
+
pub fn loadURLInWebview(self: *Core, webview_id: u32, url: []const u8) !void {
|
|
1186
|
+
const url_z = try self.dupeZ(url);
|
|
1187
|
+
defer self.allocator.free(url_z);
|
|
1188
|
+
self.symbols.load_url_in_webview(webview_id, url_z.ptr);
|
|
1189
|
+
try self.ensureLastCallSucceeded();
|
|
1190
|
+
}
|
|
1191
|
+
|
|
1192
|
+
pub fn loadHTMLInWebview(self: *Core, webview_id: u32, html: []const u8) !void {
|
|
1193
|
+
const html_z = try self.dupeZ(html);
|
|
1194
|
+
defer self.allocator.free(html_z);
|
|
1195
|
+
self.symbols.load_html_in_webview(webview_id, html_z.ptr);
|
|
1196
|
+
try self.ensureLastCallSucceeded();
|
|
1197
|
+
}
|
|
1198
|
+
|
|
1199
|
+
pub fn updatePreloadScriptToWebview(self: *Core, webview_id: u32, script_identifier: []const u8, script: []const u8, all_frames: bool) !void {
|
|
1200
|
+
const script_identifier_z = try self.dupeZ(script_identifier);
|
|
1201
|
+
defer self.allocator.free(script_identifier_z);
|
|
1202
|
+
const script_z = try self.dupeZ(script);
|
|
1203
|
+
defer self.allocator.free(script_z);
|
|
1204
|
+
|
|
1205
|
+
self.symbols.update_preload_script_to_webview(
|
|
1206
|
+
webview_id,
|
|
1207
|
+
script_identifier_z.ptr,
|
|
1208
|
+
script_z.ptr,
|
|
1209
|
+
all_frames,
|
|
1210
|
+
);
|
|
1211
|
+
try self.ensureLastCallSucceeded();
|
|
1212
|
+
}
|
|
1213
|
+
|
|
1214
|
+
pub fn canWebviewGoBack(self: *Core, webview_id: u32) bool {
|
|
1215
|
+
return self.symbols.webview_can_go_back(webview_id);
|
|
1216
|
+
}
|
|
1217
|
+
|
|
1218
|
+
pub fn canWebviewGoForward(self: *Core, webview_id: u32) bool {
|
|
1219
|
+
return self.symbols.webview_can_go_forward(webview_id);
|
|
1220
|
+
}
|
|
1221
|
+
|
|
1222
|
+
pub fn webviewGoBack(self: *Core, webview_id: u32) !void {
|
|
1223
|
+
self.symbols.webview_go_back(webview_id);
|
|
1224
|
+
try self.ensureLastCallSucceeded();
|
|
1225
|
+
}
|
|
1226
|
+
|
|
1227
|
+
pub fn webviewGoForward(self: *Core, webview_id: u32) !void {
|
|
1228
|
+
self.symbols.webview_go_forward(webview_id);
|
|
1229
|
+
try self.ensureLastCallSucceeded();
|
|
1230
|
+
}
|
|
1231
|
+
|
|
1232
|
+
pub fn reloadWebview(self: *Core, webview_id: u32) !void {
|
|
1233
|
+
self.symbols.webview_reload(webview_id);
|
|
1234
|
+
try self.ensureLastCallSucceeded();
|
|
1235
|
+
}
|
|
1236
|
+
|
|
1237
|
+
pub fn removeWebview(self: *Core, webview_id: u32) !void {
|
|
1238
|
+
self.symbols.webview_remove(webview_id);
|
|
1239
|
+
try self.ensureLastCallSucceeded();
|
|
1240
|
+
}
|
|
1241
|
+
|
|
1242
|
+
pub fn setWebviewHTMLContent(self: *Core, webview_id: u32, html: []const u8) !void {
|
|
1243
|
+
const html_z = try self.dupeZ(html);
|
|
1244
|
+
defer self.allocator.free(html_z);
|
|
1245
|
+
self.symbols.set_webview_html_content(webview_id, html_z.ptr);
|
|
1246
|
+
try self.ensureLastCallSucceeded();
|
|
1247
|
+
}
|
|
1248
|
+
|
|
1249
|
+
pub fn setWebviewTransparent(self: *Core, webview_id: u32, transparent: bool) !void {
|
|
1250
|
+
self.symbols.webview_set_transparent(webview_id, transparent);
|
|
1251
|
+
try self.ensureLastCallSucceeded();
|
|
1252
|
+
}
|
|
1253
|
+
|
|
1254
|
+
pub fn setWebviewPassthrough(self: *Core, webview_id: u32, passthrough: bool) !void {
|
|
1255
|
+
self.symbols.webview_set_passthrough(webview_id, passthrough);
|
|
1256
|
+
try self.ensureLastCallSucceeded();
|
|
1257
|
+
}
|
|
1258
|
+
|
|
1259
|
+
pub fn setWebviewHidden(self: *Core, webview_id: u32, hidden: bool) !void {
|
|
1260
|
+
self.symbols.webview_set_hidden(webview_id, hidden);
|
|
1261
|
+
try self.ensureLastCallSucceeded();
|
|
1262
|
+
}
|
|
1263
|
+
|
|
1264
|
+
pub fn setWebviewNavigationRules(self: *Core, webview_id: u32, rules_json: []const u8) !void {
|
|
1265
|
+
const rules_json_z = try self.dupeZ(rules_json);
|
|
1266
|
+
defer self.allocator.free(rules_json_z);
|
|
1267
|
+
self.symbols.set_webview_navigation_rules(webview_id, rules_json_z.ptr);
|
|
1268
|
+
try self.ensureLastCallSucceeded();
|
|
1269
|
+
}
|
|
1270
|
+
|
|
1271
|
+
pub fn webviewFindInPage(self: *Core, webview_id: u32, search_text: []const u8, forward: bool, match_case: bool) !void {
|
|
1272
|
+
const search_text_z = try self.dupeZ(search_text);
|
|
1273
|
+
defer self.allocator.free(search_text_z);
|
|
1274
|
+
self.symbols.webview_find_in_page(webview_id, search_text_z.ptr, forward, match_case);
|
|
1275
|
+
try self.ensureLastCallSucceeded();
|
|
1276
|
+
}
|
|
1277
|
+
|
|
1278
|
+
pub fn webviewStopFind(self: *Core, webview_id: u32) !void {
|
|
1279
|
+
self.symbols.webview_stop_find(webview_id);
|
|
1280
|
+
try self.ensureLastCallSucceeded();
|
|
1281
|
+
}
|
|
1282
|
+
|
|
1283
|
+
pub fn openWebviewDevTools(self: *Core, webview_id: u32) !void {
|
|
1284
|
+
self.symbols.webview_open_devtools(webview_id);
|
|
1285
|
+
try self.ensureLastCallSucceeded();
|
|
1286
|
+
}
|
|
1287
|
+
|
|
1288
|
+
pub fn closeWebviewDevTools(self: *Core, webview_id: u32) !void {
|
|
1289
|
+
self.symbols.webview_close_devtools(webview_id);
|
|
1290
|
+
try self.ensureLastCallSucceeded();
|
|
1291
|
+
}
|
|
1292
|
+
|
|
1293
|
+
pub fn toggleWebviewDevTools(self: *Core, webview_id: u32) !void {
|
|
1294
|
+
self.symbols.webview_toggle_devtools(webview_id);
|
|
1295
|
+
try self.ensureLastCallSucceeded();
|
|
1296
|
+
}
|
|
1297
|
+
|
|
1298
|
+
pub fn setWebviewPageZoom(self: *Core, webview_id: u32, zoom_level: f64) !void {
|
|
1299
|
+
self.symbols.webview_set_page_zoom(webview_id, zoom_level);
|
|
1300
|
+
try self.ensureLastCallSucceeded();
|
|
1301
|
+
}
|
|
1302
|
+
|
|
1303
|
+
pub fn getWebviewPageZoom(self: *Core, webview_id: u32) f64 {
|
|
1304
|
+
return self.symbols.webview_get_page_zoom(webview_id);
|
|
1305
|
+
}
|
|
1306
|
+
|
|
1307
|
+
pub fn createWGPUView(self: *Core, options: WGPUViewOptions) !u32 {
|
|
1308
|
+
const wgpu_view_id = self.symbols.create_wgpu_view(
|
|
1309
|
+
options.window_id,
|
|
1310
|
+
options.frame.x,
|
|
1311
|
+
options.frame.y,
|
|
1312
|
+
options.frame.width,
|
|
1313
|
+
options.frame.height,
|
|
1314
|
+
options.auto_resize,
|
|
1315
|
+
options.start_transparent,
|
|
1316
|
+
options.start_passthrough,
|
|
1317
|
+
);
|
|
1318
|
+
|
|
1319
|
+
if (wgpu_view_id == 0) {
|
|
1320
|
+
return errorFromLastError(self.lastError());
|
|
1321
|
+
}
|
|
1322
|
+
|
|
1323
|
+
return wgpu_view_id;
|
|
1324
|
+
}
|
|
1325
|
+
|
|
1326
|
+
pub fn setWGPUViewFrame(self: *Core, wgpu_view_id: u32, frame: Rect) !void {
|
|
1327
|
+
self.symbols.set_wgpu_view_frame(
|
|
1328
|
+
wgpu_view_id,
|
|
1329
|
+
frame.x,
|
|
1330
|
+
frame.y,
|
|
1331
|
+
frame.width,
|
|
1332
|
+
frame.height,
|
|
1333
|
+
);
|
|
1334
|
+
try self.ensureLastCallSucceeded();
|
|
1335
|
+
}
|
|
1336
|
+
|
|
1337
|
+
pub fn resizeWGPUView(self: *Core, wgpu_view_id: u32, frame: Rect, masks_json: []const u8) !void {
|
|
1338
|
+
const masks_json_z = try self.dupeZ(masks_json);
|
|
1339
|
+
defer self.allocator.free(masks_json_z);
|
|
1340
|
+
|
|
1341
|
+
self.symbols.resize_wgpu_view(
|
|
1342
|
+
wgpu_view_id,
|
|
1343
|
+
frame.x,
|
|
1344
|
+
frame.y,
|
|
1345
|
+
frame.width,
|
|
1346
|
+
frame.height,
|
|
1347
|
+
masks_json_z.ptr,
|
|
1348
|
+
);
|
|
1349
|
+
try self.ensureLastCallSucceeded();
|
|
1350
|
+
}
|
|
1351
|
+
|
|
1352
|
+
pub fn setWGPUViewTransparent(self: *Core, wgpu_view_id: u32, transparent: bool) !void {
|
|
1353
|
+
self.symbols.set_wgpu_view_transparent(wgpu_view_id, transparent);
|
|
1354
|
+
try self.ensureLastCallSucceeded();
|
|
1355
|
+
}
|
|
1356
|
+
|
|
1357
|
+
pub fn setWGPUViewPassthrough(self: *Core, wgpu_view_id: u32, passthrough: bool) !void {
|
|
1358
|
+
self.symbols.set_wgpu_view_passthrough(wgpu_view_id, passthrough);
|
|
1359
|
+
try self.ensureLastCallSucceeded();
|
|
1360
|
+
}
|
|
1361
|
+
|
|
1362
|
+
pub fn setWGPUViewHidden(self: *Core, wgpu_view_id: u32, hidden: bool) !void {
|
|
1363
|
+
self.symbols.set_wgpu_view_hidden(wgpu_view_id, hidden);
|
|
1364
|
+
try self.ensureLastCallSucceeded();
|
|
1365
|
+
}
|
|
1366
|
+
|
|
1367
|
+
pub fn removeWGPUView(self: *Core, wgpu_view_id: u32) !void {
|
|
1368
|
+
self.symbols.remove_wgpu_view(wgpu_view_id);
|
|
1369
|
+
try self.ensureLastCallSucceeded();
|
|
1370
|
+
}
|
|
1371
|
+
|
|
1372
|
+
pub fn getWGPUViewPointer(self: *Core, wgpu_view_id: u32) !?*anyopaque {
|
|
1373
|
+
const handle = self.symbols.get_wgpu_view_pointer(wgpu_view_id);
|
|
1374
|
+
try self.ensureLastCallSucceeded();
|
|
1375
|
+
return handle;
|
|
1376
|
+
}
|
|
1377
|
+
|
|
1378
|
+
pub fn getWGPUViewNativeHandle(self: *Core, wgpu_view_id: u32) !?*anyopaque {
|
|
1379
|
+
const handle = self.symbols.get_wgpu_view_native_handle(wgpu_view_id);
|
|
1380
|
+
try self.ensureLastCallSucceeded();
|
|
1381
|
+
return handle;
|
|
1382
|
+
}
|
|
1383
|
+
|
|
1384
|
+
pub fn runWGPUViewTest(self: *Core, wgpu_view_id: u32) !void {
|
|
1385
|
+
self.symbols.run_wgpu_view_test(wgpu_view_id);
|
|
1386
|
+
try self.ensureLastCallSucceeded();
|
|
1387
|
+
}
|
|
1388
|
+
|
|
1389
|
+
pub fn toggleWGPUViewTestShader(self: *Core, wgpu_view_id: u32) !void {
|
|
1390
|
+
self.symbols.toggle_wgpu_view_test_shader(wgpu_view_id);
|
|
1391
|
+
try self.ensureLastCallSucceeded();
|
|
1392
|
+
}
|
|
1393
|
+
|
|
1394
|
+
pub fn evaluateJavaScriptWithNoCompletion(self: *Core, webview_id: u32, js: []const u8) !void {
|
|
1395
|
+
const js_z = try self.dupeZ(js);
|
|
1396
|
+
defer self.allocator.free(js_z);
|
|
1397
|
+
|
|
1398
|
+
self.symbols.evaluate_javascript_with_no_completion(webview_id, js_z.ptr);
|
|
1399
|
+
try self.ensureLastCallSucceeded();
|
|
1400
|
+
}
|
|
1401
|
+
|
|
1402
|
+
pub fn sendMessageToWebview(self: *Core, webview_id: u32, message: anytype) !void {
|
|
1403
|
+
const message_json = try std.json.stringifyAlloc(self.allocator, message, .{});
|
|
1404
|
+
defer self.allocator.free(message_json);
|
|
1405
|
+
|
|
1406
|
+
const js = try std.fmt.allocPrint(
|
|
1407
|
+
self.allocator,
|
|
1408
|
+
"window.__electrobun.receiveMessageFromBun({s});",
|
|
1409
|
+
.{message_json},
|
|
1410
|
+
);
|
|
1411
|
+
defer self.allocator.free(js);
|
|
1412
|
+
|
|
1413
|
+
try self.evaluateJavaScriptWithNoCompletion(webview_id, js);
|
|
1414
|
+
}
|
|
1415
|
+
|
|
1416
|
+
pub fn sendInternalMessageToWebview(self: *Core, webview_id: u32, message: anytype) !void {
|
|
1417
|
+
const message_json = try std.json.stringifyAlloc(self.allocator, message, .{});
|
|
1418
|
+
defer self.allocator.free(message_json);
|
|
1419
|
+
const message_json_z = try self.dupeZ(message_json);
|
|
1420
|
+
defer self.allocator.free(message_json_z);
|
|
1421
|
+
|
|
1422
|
+
if (!self.symbols.send_internal_message_to_webview(webview_id, message_json_z.ptr)) {
|
|
1423
|
+
return errorFromLastError(self.lastError());
|
|
1424
|
+
}
|
|
1425
|
+
}
|
|
1426
|
+
|
|
1427
|
+
pub fn createTray(self: *Core, options: TrayOptions) !u32 {
|
|
1428
|
+
const title_z = try self.dupeZ(options.title);
|
|
1429
|
+
defer self.allocator.free(title_z);
|
|
1430
|
+
const image_z = try self.dupeZ(options.image);
|
|
1431
|
+
defer self.allocator.free(image_z);
|
|
1432
|
+
|
|
1433
|
+
const tray_id = self.symbols.create_tray(
|
|
1434
|
+
title_z.ptr,
|
|
1435
|
+
image_z.ptr,
|
|
1436
|
+
options.is_template,
|
|
1437
|
+
options.width,
|
|
1438
|
+
options.height,
|
|
1439
|
+
null,
|
|
1440
|
+
);
|
|
1441
|
+
if (tray_id == 0) {
|
|
1442
|
+
return errorFromLastError(self.lastError());
|
|
1443
|
+
}
|
|
1444
|
+
return tray_id;
|
|
1445
|
+
}
|
|
1446
|
+
|
|
1447
|
+
pub fn setApplicationMenuJson(self: *Core, menu_json: []const u8, handler: ?StatusItemHandler) !void {
|
|
1448
|
+
const menu_json_z = try self.dupeZ(menu_json);
|
|
1449
|
+
defer self.allocator.free(menu_json_z);
|
|
1450
|
+
self.symbols.set_application_menu(menu_json_z.ptr, handler);
|
|
1451
|
+
try self.ensureLastCallSucceeded();
|
|
1452
|
+
}
|
|
1453
|
+
|
|
1454
|
+
pub fn showContextMenuJson(self: *Core, menu_json: []const u8, handler: ?StatusItemHandler) !void {
|
|
1455
|
+
const menu_json_z = try self.dupeZ(menu_json);
|
|
1456
|
+
defer self.allocator.free(menu_json_z);
|
|
1457
|
+
self.symbols.show_context_menu(menu_json_z.ptr, handler);
|
|
1458
|
+
try self.ensureLastCallSucceeded();
|
|
1459
|
+
}
|
|
1460
|
+
|
|
1461
|
+
pub fn showTray(self: *Core, tray_id: u32) !void {
|
|
1462
|
+
if (!self.symbols.show_tray(tray_id)) {
|
|
1463
|
+
return errorFromLastError(self.lastError());
|
|
1464
|
+
}
|
|
1465
|
+
}
|
|
1466
|
+
|
|
1467
|
+
pub fn hideTray(self: *Core, tray_id: u32) !void {
|
|
1468
|
+
self.symbols.hide_tray(tray_id);
|
|
1469
|
+
try self.ensureLastCallSucceeded();
|
|
1470
|
+
}
|
|
1471
|
+
|
|
1472
|
+
pub fn setTrayTitle(self: *Core, tray_id: u32, title: []const u8) !void {
|
|
1473
|
+
const title_z = try self.dupeZ(title);
|
|
1474
|
+
defer self.allocator.free(title_z);
|
|
1475
|
+
self.symbols.set_tray_title(tray_id, title_z.ptr);
|
|
1476
|
+
try self.ensureLastCallSucceeded();
|
|
1477
|
+
}
|
|
1478
|
+
|
|
1479
|
+
pub fn getTrayBounds(self: *Core, tray_id: u32) !Rect {
|
|
1480
|
+
const bounds_json = self.symbols.get_tray_bounds(tray_id);
|
|
1481
|
+
return try parseRectJson(self.allocator, std.mem.span(bounds_json));
|
|
1482
|
+
}
|
|
1483
|
+
|
|
1484
|
+
pub fn removeTray(self: *Core, tray_id: u32) !void {
|
|
1485
|
+
self.symbols.remove_tray(tray_id);
|
|
1486
|
+
try self.ensureLastCallSucceeded();
|
|
1487
|
+
}
|
|
1488
|
+
|
|
1489
|
+
pub fn setDockIconVisible(self: *Core, visible: bool) !void {
|
|
1490
|
+
self.symbols.set_dock_icon_visible(visible);
|
|
1491
|
+
try self.ensureLastCallSucceeded();
|
|
1492
|
+
}
|
|
1493
|
+
|
|
1494
|
+
pub fn isDockIconVisible(self: *Core) bool {
|
|
1495
|
+
return self.symbols.is_dock_icon_visible();
|
|
1496
|
+
}
|
|
1497
|
+
|
|
1498
|
+
pub fn getPrimaryDisplay(self: *Core) !Display {
|
|
1499
|
+
const json = self.symbols.get_primary_display() orelse return error.ElectrobunCoreFailure;
|
|
1500
|
+
return try parseJsonOwned(self.allocator, Display, std.mem.span(json));
|
|
1501
|
+
}
|
|
1502
|
+
|
|
1503
|
+
pub fn getAllDisplays(self: *Core) ![]Display {
|
|
1504
|
+
const json = self.symbols.get_all_displays() orelse return error.ElectrobunCoreFailure;
|
|
1505
|
+
return try parseJsonSliceOwned(self.allocator, Display, std.mem.span(json));
|
|
1506
|
+
}
|
|
1507
|
+
|
|
1508
|
+
pub fn getCursorScreenPoint(self: *Core) !Point {
|
|
1509
|
+
const json = self.symbols.get_cursor_screen_point() orelse return error.ElectrobunCoreFailure;
|
|
1510
|
+
return try parseJsonOwned(self.allocator, Point, std.mem.span(json));
|
|
1511
|
+
}
|
|
1512
|
+
|
|
1513
|
+
pub fn moveToTrash(self: *Core, path: []const u8) !bool {
|
|
1514
|
+
const path_z = try self.dupeZ(path);
|
|
1515
|
+
defer self.allocator.free(path_z);
|
|
1516
|
+
return self.symbols.move_to_trash(path_z.ptr);
|
|
1517
|
+
}
|
|
1518
|
+
|
|
1519
|
+
pub fn showItemInFolder(self: *Core, path: []const u8) !void {
|
|
1520
|
+
const path_z = try self.dupeZ(path);
|
|
1521
|
+
defer self.allocator.free(path_z);
|
|
1522
|
+
self.symbols.show_item_in_folder(path_z.ptr);
|
|
1523
|
+
try self.ensureLastCallSucceeded();
|
|
1524
|
+
}
|
|
1525
|
+
|
|
1526
|
+
pub fn openExternal(self: *Core, url: []const u8) !bool {
|
|
1527
|
+
const url_z = try self.dupeZ(url);
|
|
1528
|
+
defer self.allocator.free(url_z);
|
|
1529
|
+
return self.symbols.open_external(url_z.ptr);
|
|
1530
|
+
}
|
|
1531
|
+
|
|
1532
|
+
pub fn openPath(self: *Core, path: []const u8) !bool {
|
|
1533
|
+
const path_z = try self.dupeZ(path);
|
|
1534
|
+
defer self.allocator.free(path_z);
|
|
1535
|
+
return self.symbols.open_path(path_z.ptr);
|
|
1536
|
+
}
|
|
1537
|
+
|
|
1538
|
+
pub fn openFileDialog(self: *Core, options: OpenFileDialogOptions) ![]u8 {
|
|
1539
|
+
const starting_folder_z = try self.dupeZ(options.starting_folder);
|
|
1540
|
+
defer self.allocator.free(starting_folder_z);
|
|
1541
|
+
const allowed_file_types_z = try self.dupeZ(options.allowed_file_types);
|
|
1542
|
+
defer self.allocator.free(allowed_file_types_z);
|
|
1543
|
+
|
|
1544
|
+
const result = self.symbols.open_file_dialog(
|
|
1545
|
+
starting_folder_z.ptr,
|
|
1546
|
+
allowed_file_types_z.ptr,
|
|
1547
|
+
if (options.can_choose_files) 1 else 0,
|
|
1548
|
+
if (options.can_choose_directory) 1 else 0,
|
|
1549
|
+
if (options.allows_multiple_selection) 1 else 0,
|
|
1550
|
+
) orelse return try self.allocator.dupe(u8, "");
|
|
1551
|
+
return try self.allocator.dupe(u8, std.mem.span(result));
|
|
1552
|
+
}
|
|
1553
|
+
|
|
1554
|
+
pub fn showMessageBox(self: *Core, options: MessageBoxOptions) !c_int {
|
|
1555
|
+
const box_type_z = try self.dupeZ(options.box_type);
|
|
1556
|
+
defer self.allocator.free(box_type_z);
|
|
1557
|
+
const title_z = try self.dupeZ(options.title);
|
|
1558
|
+
defer self.allocator.free(title_z);
|
|
1559
|
+
const message_z = try self.dupeZ(options.message);
|
|
1560
|
+
defer self.allocator.free(message_z);
|
|
1561
|
+
const detail_z = try self.dupeZ(options.detail);
|
|
1562
|
+
defer self.allocator.free(detail_z);
|
|
1563
|
+
const buttons_joined = try std.mem.join(self.allocator, ",", options.buttons);
|
|
1564
|
+
defer self.allocator.free(buttons_joined);
|
|
1565
|
+
const buttons_z = try self.dupeZ(buttons_joined);
|
|
1566
|
+
defer self.allocator.free(buttons_z);
|
|
1567
|
+
|
|
1568
|
+
const response = self.symbols.show_message_box(
|
|
1569
|
+
box_type_z.ptr,
|
|
1570
|
+
title_z.ptr,
|
|
1571
|
+
message_z.ptr,
|
|
1572
|
+
detail_z.ptr,
|
|
1573
|
+
buttons_z.ptr,
|
|
1574
|
+
options.default_id,
|
|
1575
|
+
options.cancel_id,
|
|
1576
|
+
);
|
|
1577
|
+
try self.ensureLastCallSucceeded();
|
|
1578
|
+
return response;
|
|
1579
|
+
}
|
|
1580
|
+
|
|
1581
|
+
pub fn showNotification(self: *Core, options: NotificationOptions) !void {
|
|
1582
|
+
const title_z = try self.dupeZ(options.title);
|
|
1583
|
+
defer self.allocator.free(title_z);
|
|
1584
|
+
const body_z = try self.dupeZ(options.body);
|
|
1585
|
+
defer self.allocator.free(body_z);
|
|
1586
|
+
const subtitle_z = try self.dupeZ(options.subtitle);
|
|
1587
|
+
defer self.allocator.free(subtitle_z);
|
|
1588
|
+
|
|
1589
|
+
self.symbols.show_notification(title_z.ptr, body_z.ptr, subtitle_z.ptr, options.silent);
|
|
1590
|
+
try self.ensureLastCallSucceeded();
|
|
1591
|
+
}
|
|
1592
|
+
|
|
1593
|
+
pub fn setGlobalShortcutCallback(self: *Core, callback: ?GlobalShortcutHandler) !void {
|
|
1594
|
+
self.symbols.set_global_shortcut_callback(callback);
|
|
1595
|
+
try self.ensureLastCallSucceeded();
|
|
1596
|
+
}
|
|
1597
|
+
|
|
1598
|
+
pub fn registerGlobalShortcut(self: *Core, accelerator: []const u8) !bool {
|
|
1599
|
+
const accelerator_z = try self.dupeZ(accelerator);
|
|
1600
|
+
defer self.allocator.free(accelerator_z);
|
|
1601
|
+
return self.symbols.register_global_shortcut(accelerator_z.ptr);
|
|
1602
|
+
}
|
|
1603
|
+
|
|
1604
|
+
pub fn unregisterGlobalShortcut(self: *Core, accelerator: []const u8) !bool {
|
|
1605
|
+
const accelerator_z = try self.dupeZ(accelerator);
|
|
1606
|
+
defer self.allocator.free(accelerator_z);
|
|
1607
|
+
return self.symbols.unregister_global_shortcut(accelerator_z.ptr);
|
|
1608
|
+
}
|
|
1609
|
+
|
|
1610
|
+
pub fn unregisterAllGlobalShortcuts(self: *Core) !void {
|
|
1611
|
+
self.symbols.unregister_all_global_shortcuts();
|
|
1612
|
+
try self.ensureLastCallSucceeded();
|
|
1613
|
+
}
|
|
1614
|
+
|
|
1615
|
+
pub fn isGlobalShortcutRegistered(self: *Core, accelerator: []const u8) !bool {
|
|
1616
|
+
const accelerator_z = try self.dupeZ(accelerator);
|
|
1617
|
+
defer self.allocator.free(accelerator_z);
|
|
1618
|
+
return self.symbols.is_global_shortcut_registered(accelerator_z.ptr);
|
|
1619
|
+
}
|
|
1620
|
+
|
|
1621
|
+
pub fn clipboardReadText(self: *Core) !?[]u8 {
|
|
1622
|
+
const text = self.symbols.clipboard_read_text() orelse return null;
|
|
1623
|
+
return try self.allocator.dupe(u8, std.mem.span(text));
|
|
1624
|
+
}
|
|
1625
|
+
|
|
1626
|
+
pub fn clipboardWriteText(self: *Core, text: []const u8) !void {
|
|
1627
|
+
const text_z = try self.dupeZ(text);
|
|
1628
|
+
defer self.allocator.free(text_z);
|
|
1629
|
+
self.symbols.clipboard_write_text(text_z.ptr);
|
|
1630
|
+
try self.ensureLastCallSucceeded();
|
|
1631
|
+
}
|
|
1632
|
+
|
|
1633
|
+
pub fn clipboardClear(self: *Core) !void {
|
|
1634
|
+
self.symbols.clipboard_clear();
|
|
1635
|
+
try self.ensureLastCallSucceeded();
|
|
1636
|
+
}
|
|
1637
|
+
|
|
1638
|
+
pub fn clipboardAvailableFormatsCsv(self: *Core) ![]u8 {
|
|
1639
|
+
const formats = self.symbols.clipboard_available_formats() orelse return try self.allocator.dupe(u8, "");
|
|
1640
|
+
return try self.allocator.dupe(u8, std.mem.span(formats));
|
|
1641
|
+
}
|
|
1642
|
+
|
|
1643
|
+
pub fn sessionGetCookies(self: *Core, partition: []const u8, filter_json: []const u8) ![]Cookie {
|
|
1644
|
+
const partition_z = try self.dupeZ(partition);
|
|
1645
|
+
defer self.allocator.free(partition_z);
|
|
1646
|
+
const filter_json_z = try self.dupeZ(filter_json);
|
|
1647
|
+
defer self.allocator.free(filter_json_z);
|
|
1648
|
+
const json = self.symbols.session_get_cookies(partition_z.ptr, filter_json_z.ptr) orelse return try self.allocator.alloc(Cookie, 0);
|
|
1649
|
+
const parsed = try std.json.parseFromSlice([]Cookie, self.allocator, std.mem.span(json), .{});
|
|
1650
|
+
return parsed.value;
|
|
1651
|
+
}
|
|
1652
|
+
|
|
1653
|
+
pub fn sessionSetCookie(self: *Core, partition: []const u8, cookie_json: []const u8) !bool {
|
|
1654
|
+
const partition_z = try self.dupeZ(partition);
|
|
1655
|
+
defer self.allocator.free(partition_z);
|
|
1656
|
+
const cookie_json_z = try self.dupeZ(cookie_json);
|
|
1657
|
+
defer self.allocator.free(cookie_json_z);
|
|
1658
|
+
return self.symbols.session_set_cookie(partition_z.ptr, cookie_json_z.ptr);
|
|
1659
|
+
}
|
|
1660
|
+
|
|
1661
|
+
pub fn sessionRemoveCookie(self: *Core, partition: []const u8, url: []const u8, name: []const u8) !bool {
|
|
1662
|
+
const partition_z = try self.dupeZ(partition);
|
|
1663
|
+
defer self.allocator.free(partition_z);
|
|
1664
|
+
const url_z = try self.dupeZ(url);
|
|
1665
|
+
defer self.allocator.free(url_z);
|
|
1666
|
+
const name_z = try self.dupeZ(name);
|
|
1667
|
+
defer self.allocator.free(name_z);
|
|
1668
|
+
return self.symbols.session_remove_cookie(partition_z.ptr, url_z.ptr, name_z.ptr);
|
|
1669
|
+
}
|
|
1670
|
+
|
|
1671
|
+
pub fn sessionClearCookies(self: *Core, partition: []const u8) !void {
|
|
1672
|
+
const partition_z = try self.dupeZ(partition);
|
|
1673
|
+
defer self.allocator.free(partition_z);
|
|
1674
|
+
self.symbols.session_clear_cookies(partition_z.ptr);
|
|
1675
|
+
try self.ensureLastCallSucceeded();
|
|
1676
|
+
}
|
|
1677
|
+
|
|
1678
|
+
pub fn sessionClearStorageData(self: *Core, partition: []const u8, storage_types_json: []const u8) !void {
|
|
1679
|
+
const partition_z = try self.dupeZ(partition);
|
|
1680
|
+
defer self.allocator.free(partition_z);
|
|
1681
|
+
const storage_types_json_z = try self.dupeZ(storage_types_json);
|
|
1682
|
+
defer self.allocator.free(storage_types_json_z);
|
|
1683
|
+
self.symbols.session_clear_storage_data(partition_z.ptr, storage_types_json_z.ptr);
|
|
1684
|
+
try self.ensureLastCallSucceeded();
|
|
1685
|
+
}
|
|
1686
|
+
|
|
1687
|
+
pub fn setURLOpenHandler(self: *Core, handler: ?URLOpenHandler) !void {
|
|
1688
|
+
self.symbols.set_url_open_handler(handler);
|
|
1689
|
+
try self.ensureLastCallSucceeded();
|
|
1690
|
+
}
|
|
1691
|
+
|
|
1692
|
+
pub fn setAppReopenHandler(self: *Core, handler: ?AppReopenHandler) !void {
|
|
1693
|
+
self.symbols.set_app_reopen_handler(handler);
|
|
1694
|
+
try self.ensureLastCallSucceeded();
|
|
1695
|
+
}
|
|
1696
|
+
|
|
1697
|
+
pub fn setQuitRequestedHandler(self: *Core, handler: ?QuitRequestedHandler) !void {
|
|
1698
|
+
self.symbols.set_quit_requested_handler(handler);
|
|
1699
|
+
try self.ensureLastCallSucceeded();
|
|
1700
|
+
}
|
|
1701
|
+
|
|
1702
|
+
pub fn stopEventLoop(self: *Core) !void {
|
|
1703
|
+
self.symbols.stop_event_loop();
|
|
1704
|
+
try self.ensureLastCallSucceeded();
|
|
1705
|
+
}
|
|
1706
|
+
|
|
1707
|
+
pub fn waitForShutdownComplete(self: *Core, timeout_ms: c_int) !void {
|
|
1708
|
+
self.symbols.wait_for_shutdown_complete(timeout_ms);
|
|
1709
|
+
try self.ensureLastCallSucceeded();
|
|
1710
|
+
}
|
|
1711
|
+
|
|
1712
|
+
pub fn forceExit(self: *Core, code: c_int) noreturn {
|
|
1713
|
+
self.symbols.force_exit(code);
|
|
1714
|
+
std.process.exit(@intCast(code));
|
|
1715
|
+
}
|
|
1716
|
+
|
|
1717
|
+
pub fn quitGracefully(self: *Core, code: c_int) noreturn {
|
|
1718
|
+
self.stopEventLoop() catch {};
|
|
1719
|
+
self.waitForShutdownComplete(5000) catch {};
|
|
1720
|
+
self.forceExit(code);
|
|
1721
|
+
}
|
|
1722
|
+
|
|
1723
|
+
pub fn wgpuCreateSurfaceForView(self: *Core, instance_ptr: ?*anyopaque, view_ptr: ?*anyopaque) !?*anyopaque {
|
|
1724
|
+
const surface_ptr = self.symbols.wgpu_create_surface_for_view(instance_ptr, view_ptr);
|
|
1725
|
+
try self.ensureLastCallSucceeded();
|
|
1726
|
+
return surface_ptr;
|
|
1727
|
+
}
|
|
1728
|
+
|
|
1729
|
+
pub fn wgpuCreateAdapterDeviceMainThread(
|
|
1730
|
+
self: *Core,
|
|
1731
|
+
instance_ptr: ?*anyopaque,
|
|
1732
|
+
surface_ptr: ?*anyopaque,
|
|
1733
|
+
out_adapter_device: ?*anyopaque,
|
|
1734
|
+
) !void {
|
|
1735
|
+
self.symbols.wgpu_create_adapter_device_main_thread(instance_ptr, surface_ptr, out_adapter_device);
|
|
1736
|
+
try self.ensureLastCallSucceeded();
|
|
1737
|
+
}
|
|
1738
|
+
|
|
1739
|
+
pub fn wgpuSurfaceConfigureMainThread(self: *Core, surface_ptr: ?*anyopaque, config_ptr: ?*anyopaque) !void {
|
|
1740
|
+
self.symbols.wgpu_surface_configure_main_thread(surface_ptr, config_ptr);
|
|
1741
|
+
try self.ensureLastCallSucceeded();
|
|
1742
|
+
}
|
|
1743
|
+
|
|
1744
|
+
pub fn wgpuSurfaceGetCurrentTextureMainThread(self: *Core, surface_ptr: ?*anyopaque, surface_texture_ptr: ?*anyopaque) !void {
|
|
1745
|
+
self.symbols.wgpu_surface_get_current_texture_main_thread(surface_ptr, surface_texture_ptr);
|
|
1746
|
+
try self.ensureLastCallSucceeded();
|
|
1747
|
+
}
|
|
1748
|
+
|
|
1749
|
+
pub fn wgpuSurfacePresentMainThread(self: *Core, surface_ptr: ?*anyopaque) !i32 {
|
|
1750
|
+
const result = self.symbols.wgpu_surface_present_main_thread(surface_ptr);
|
|
1751
|
+
try self.ensureLastCallSucceeded();
|
|
1752
|
+
return result;
|
|
1753
|
+
}
|
|
1754
|
+
|
|
1755
|
+
pub fn runMainThread(self: *Core, app_info: AppInfo) !void {
|
|
1756
|
+
const identifier_z = try self.dupeZ(app_info.identifier);
|
|
1757
|
+
defer self.allocator.free(identifier_z);
|
|
1758
|
+
const name_z = try self.dupeZ(app_info.name);
|
|
1759
|
+
defer self.allocator.free(name_z);
|
|
1760
|
+
const channel_z = try self.dupeZ(app_info.channel);
|
|
1761
|
+
defer self.allocator.free(channel_z);
|
|
1762
|
+
|
|
1763
|
+
const status = self.symbols.run_main_thread(
|
|
1764
|
+
identifier_z.ptr,
|
|
1765
|
+
name_z.ptr,
|
|
1766
|
+
channel_z.ptr,
|
|
1767
|
+
0,
|
|
1768
|
+
);
|
|
1769
|
+
|
|
1770
|
+
if (status != 0) {
|
|
1771
|
+
return errorFromLastError(self.lastError());
|
|
1772
|
+
}
|
|
1773
|
+
}
|
|
1774
|
+
|
|
1775
|
+
fn ensureLastCallSucceeded(self: *Core) !void {
|
|
1776
|
+
const message = self.lastError();
|
|
1777
|
+
if (message.len != 0) {
|
|
1778
|
+
return errorFromLastError(message);
|
|
1779
|
+
}
|
|
1780
|
+
}
|
|
1781
|
+
};
|
|
1782
|
+
|
|
1783
|
+
pub fn quit(code: u8) noreturn {
|
|
1784
|
+
std.process.exit(code);
|
|
1785
|
+
}
|
|
1786
|
+
|
|
1787
|
+
fn getHomeDirOwned(allocator: std.mem.Allocator) ![]u8 {
|
|
1788
|
+
return switch (builtin.os.tag) {
|
|
1789
|
+
.windows => std.process.getEnvVarOwned(allocator, "USERPROFILE") catch
|
|
1790
|
+
std.process.getEnvVarOwned(allocator, "HOME"),
|
|
1791
|
+
else => std.process.getEnvVarOwned(allocator, "HOME"),
|
|
1792
|
+
};
|
|
1793
|
+
}
|
|
1794
|
+
|
|
1795
|
+
fn getAppDataDirOwned(allocator: std.mem.Allocator, home: []const u8) ![]u8 {
|
|
1796
|
+
return switch (builtin.os.tag) {
|
|
1797
|
+
.macos => std.fs.path.join(allocator, &.{ home, "Library", "Application Support" }),
|
|
1798
|
+
.windows => envOrJoin(allocator, "LOCALAPPDATA", &.{ home, "AppData", "Local" }),
|
|
1799
|
+
else => envOrJoin(allocator, "XDG_DATA_HOME", &.{ home, ".local", "share" }),
|
|
1800
|
+
};
|
|
1801
|
+
}
|
|
1802
|
+
|
|
1803
|
+
fn getCacheDirOwned(allocator: std.mem.Allocator, home: []const u8) ![]u8 {
|
|
1804
|
+
return switch (builtin.os.tag) {
|
|
1805
|
+
.macos => std.fs.path.join(allocator, &.{ home, "Library", "Caches" }),
|
|
1806
|
+
.windows => envOrJoin(allocator, "LOCALAPPDATA", &.{ home, "AppData", "Local" }),
|
|
1807
|
+
else => envOrJoin(allocator, "XDG_CACHE_HOME", &.{ home, ".cache" }),
|
|
1808
|
+
};
|
|
1809
|
+
}
|
|
1810
|
+
|
|
1811
|
+
fn getLogsDirOwned(allocator: std.mem.Allocator, home: []const u8) ![]u8 {
|
|
1812
|
+
return switch (builtin.os.tag) {
|
|
1813
|
+
.macos => std.fs.path.join(allocator, &.{ home, "Library", "Logs" }),
|
|
1814
|
+
.windows => envOrJoin(allocator, "LOCALAPPDATA", &.{ home, "AppData", "Local" }),
|
|
1815
|
+
else => envOrJoin(allocator, "XDG_STATE_HOME", &.{ home, ".local", "state" }),
|
|
1816
|
+
};
|
|
1817
|
+
}
|
|
1818
|
+
|
|
1819
|
+
fn getConfigDirOwned(allocator: std.mem.Allocator, home: []const u8) ![]u8 {
|
|
1820
|
+
return switch (builtin.os.tag) {
|
|
1821
|
+
.macos => std.fs.path.join(allocator, &.{ home, "Library", "Application Support" }),
|
|
1822
|
+
.windows => envOrJoin(allocator, "APPDATA", &.{ home, "AppData", "Roaming" }),
|
|
1823
|
+
else => envOrJoin(allocator, "XDG_CONFIG_HOME", &.{ home, ".config" }),
|
|
1824
|
+
};
|
|
1825
|
+
}
|
|
1826
|
+
|
|
1827
|
+
fn getTempDirOwned(allocator: std.mem.Allocator, home: []const u8) ![]u8 {
|
|
1828
|
+
return switch (builtin.os.tag) {
|
|
1829
|
+
.windows => blk: {
|
|
1830
|
+
break :blk std.process.getEnvVarOwned(allocator, "TEMP") catch
|
|
1831
|
+
std.process.getEnvVarOwned(allocator, "TMP") catch
|
|
1832
|
+
std.fs.path.join(allocator, &.{ home, "AppData", "Local", "Temp" });
|
|
1833
|
+
},
|
|
1834
|
+
else => std.process.getEnvVarOwned(allocator, "TMPDIR") catch allocator.dupe(u8, "/tmp"),
|
|
1835
|
+
};
|
|
1836
|
+
}
|
|
1837
|
+
|
|
1838
|
+
fn getUserDirOwned(
|
|
1839
|
+
allocator: std.mem.Allocator,
|
|
1840
|
+
home: []const u8,
|
|
1841
|
+
mac_name: []const u8,
|
|
1842
|
+
win_name: []const u8,
|
|
1843
|
+
xdg_key: []const u8,
|
|
1844
|
+
fallback_name: []const u8,
|
|
1845
|
+
) ![]u8 {
|
|
1846
|
+
return switch (builtin.os.tag) {
|
|
1847
|
+
.macos => std.fs.path.join(allocator, &.{ home, mac_name }),
|
|
1848
|
+
.windows => std.fs.path.join(allocator, &.{ home, win_name }),
|
|
1849
|
+
else => linuxXdgUserDirOwned(allocator, home, xdg_key, fallback_name),
|
|
1850
|
+
};
|
|
1851
|
+
}
|
|
1852
|
+
|
|
1853
|
+
fn envOrJoin(allocator: std.mem.Allocator, env_name: []const u8, fallback_parts: []const []const u8) ![]u8 {
|
|
1854
|
+
return std.process.getEnvVarOwned(allocator, env_name) catch |err| switch (err) {
|
|
1855
|
+
error.EnvironmentVariableNotFound => std.fs.path.join(allocator, fallback_parts),
|
|
1856
|
+
else => err,
|
|
1857
|
+
};
|
|
1858
|
+
}
|
|
1859
|
+
|
|
1860
|
+
fn linuxXdgUserDirOwned(
|
|
1861
|
+
allocator: std.mem.Allocator,
|
|
1862
|
+
home: []const u8,
|
|
1863
|
+
key: []const u8,
|
|
1864
|
+
fallback_name: []const u8,
|
|
1865
|
+
) ![]u8 {
|
|
1866
|
+
const config_path = try std.fs.path.join(allocator, &.{ home, ".config", "user-dirs.dirs" });
|
|
1867
|
+
defer allocator.free(config_path);
|
|
1868
|
+
|
|
1869
|
+
const fallback = try std.fs.path.join(allocator, &.{ home, fallback_name });
|
|
1870
|
+
errdefer allocator.free(fallback);
|
|
1871
|
+
|
|
1872
|
+
const file = std.fs.openFileAbsolute(config_path, .{}) catch return fallback;
|
|
1873
|
+
defer file.close();
|
|
1874
|
+
|
|
1875
|
+
const content = file.readToEndAlloc(allocator, 64 * 1024) catch return fallback;
|
|
1876
|
+
defer allocator.free(content);
|
|
1877
|
+
|
|
1878
|
+
var lines = std.mem.splitScalar(u8, content, '\n');
|
|
1879
|
+
while (lines.next()) |line| {
|
|
1880
|
+
const trimmed = std.mem.trim(u8, line, " \t\r");
|
|
1881
|
+
if (trimmed.len == 0 or trimmed[0] == '#') continue;
|
|
1882
|
+
|
|
1883
|
+
const eq_index = std.mem.indexOfScalar(u8, trimmed, '=') orelse continue;
|
|
1884
|
+
const line_key = trimmed[0..eq_index];
|
|
1885
|
+
if (!std.mem.eql(u8, line_key, key)) continue;
|
|
1886
|
+
|
|
1887
|
+
var value = trimmed[eq_index + 1 ..];
|
|
1888
|
+
value = std.mem.trim(u8, value, " \t\r");
|
|
1889
|
+
if (value.len >= 2 and value[0] == '"' and value[value.len - 1] == '"') {
|
|
1890
|
+
value = value[1 .. value.len - 1];
|
|
1891
|
+
}
|
|
1892
|
+
|
|
1893
|
+
const replaced = try std.mem.replaceOwned(u8, allocator, value, "$HOME", home);
|
|
1894
|
+
allocator.free(fallback);
|
|
1895
|
+
return replaced;
|
|
1896
|
+
}
|
|
1897
|
+
|
|
1898
|
+
return fallback;
|
|
1899
|
+
}
|
|
1900
|
+
|
|
1901
|
+
fn buildAppScopedDir(allocator: std.mem.Allocator, base: []const u8, app_info: AppInfo) ![]u8 {
|
|
1902
|
+
if (app_info.identifier.len == 0 or app_info.channel.len == 0) {
|
|
1903
|
+
return allocator.dupe(u8, base);
|
|
1904
|
+
}
|
|
1905
|
+
return std.fs.path.join(allocator, &.{ base, app_info.identifier, app_info.channel });
|
|
1906
|
+
}
|
|
1907
|
+
|
|
1908
|
+
fn readFileZ(allocator: std.mem.Allocator, path: []const u8) ![:0]u8 {
|
|
1909
|
+
const file = try std.fs.openFileAbsolute(path, .{});
|
|
1910
|
+
defer file.close();
|
|
1911
|
+
|
|
1912
|
+
const content = try file.readToEndAlloc(allocator, 1024 * 1024);
|
|
1913
|
+
defer allocator.free(content);
|
|
1914
|
+
return try allocator.dupeZ(u8, content);
|
|
1915
|
+
}
|
|
1916
|
+
|
|
1917
|
+
fn readFileAlloc(allocator: std.mem.Allocator, path: []const u8) ![]u8 {
|
|
1918
|
+
const file = try std.fs.openFileAbsolute(path, .{});
|
|
1919
|
+
defer file.close();
|
|
1920
|
+
|
|
1921
|
+
return try file.readToEndAlloc(allocator, 1024 * 1024);
|
|
1922
|
+
}
|
|
1923
|
+
|
|
1924
|
+
fn parseRectJson(allocator: std.mem.Allocator, json: []const u8) !Rect {
|
|
1925
|
+
var parsed = try std.json.parseFromSlice(std.json.Value, allocator, json, .{});
|
|
1926
|
+
defer parsed.deinit();
|
|
1927
|
+
|
|
1928
|
+
if (parsed.value != .object) return error.InvalidRectJson;
|
|
1929
|
+
|
|
1930
|
+
const x = parsed.value.object.get("x") orelse return error.InvalidRectJson;
|
|
1931
|
+
const y = parsed.value.object.get("y") orelse return error.InvalidRectJson;
|
|
1932
|
+
const width = parsed.value.object.get("width") orelse return error.InvalidRectJson;
|
|
1933
|
+
const height = parsed.value.object.get("height") orelse return error.InvalidRectJson;
|
|
1934
|
+
|
|
1935
|
+
return .{
|
|
1936
|
+
.x = jsonValueToF64(x) orelse return error.InvalidRectJson,
|
|
1937
|
+
.y = jsonValueToF64(y) orelse return error.InvalidRectJson,
|
|
1938
|
+
.width = jsonValueToF64(width) orelse return error.InvalidRectJson,
|
|
1939
|
+
.height = jsonValueToF64(height) orelse return error.InvalidRectJson,
|
|
1940
|
+
};
|
|
1941
|
+
}
|
|
1942
|
+
|
|
1943
|
+
fn parseJsonOwned(allocator: std.mem.Allocator, comptime T: type, json: []const u8) !T {
|
|
1944
|
+
var parsed = try std.json.parseFromSlice(T, allocator, json, .{});
|
|
1945
|
+
defer parsed.deinit();
|
|
1946
|
+
return parsed.value;
|
|
1947
|
+
}
|
|
1948
|
+
|
|
1949
|
+
fn parseJsonSliceOwned(allocator: std.mem.Allocator, comptime T: type, json: []const u8) ![]T {
|
|
1950
|
+
var parsed = try std.json.parseFromSlice([]T, allocator, json, .{});
|
|
1951
|
+
defer parsed.deinit();
|
|
1952
|
+
return try allocator.dupe(T, parsed.value);
|
|
1953
|
+
}
|
|
1954
|
+
|
|
1955
|
+
fn jsonValueToF64(value: std.json.Value) ?f64 {
|
|
1956
|
+
return switch (value) {
|
|
1957
|
+
.float => |float_value| float_value,
|
|
1958
|
+
.integer => |int_value| @floatFromInt(int_value),
|
|
1959
|
+
else => null,
|
|
1960
|
+
};
|
|
1961
|
+
}
|
|
1962
|
+
|
|
1963
|
+
fn errorFromLastError(message: []const u8) anyerror {
|
|
1964
|
+
if (message.len == 0) {
|
|
1965
|
+
return error.ElectrobunCoreFailure;
|
|
1966
|
+
}
|
|
1967
|
+
std.debug.print("[electrobun-zig] core error: {s}\n", .{message});
|
|
1968
|
+
return error.ElectrobunCoreFailure;
|
|
1969
|
+
}
|
|
1970
|
+
|
|
1971
|
+
pub fn allowAllNavigation(_: u32, _: [*:0]const u8) callconv(.C) u32 {
|
|
1972
|
+
return 1;
|
|
1973
|
+
}
|
|
1974
|
+
|
|
1975
|
+
pub fn noopWebviewEvent(_: u32, _: [*:0]const u8, _: [*:0]const u8) callconv(.C) void {}
|
|
1976
|
+
|
|
1977
|
+
pub fn noopWebviewPostMessage(_: u32, _: [*:0]const u8) callconv(.C) u32 {
|
|
1978
|
+
return 0;
|
|
1979
|
+
}
|