Skip to content

Commit ec2ba41

Browse files
committed
fix: finalize ClassBuilder in special alloc binding
1 parent 4db6ed6 commit ec2ba41

File tree

2 files changed

+33
-9
lines changed

2 files changed

+33
-9
lines changed

examples/split_view.js

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export class ApplicationDelegate extends NSObject {
4242
toolbar.allowsUserCustomization = true;
4343
toolbar.autosavesConfiguration = true;
4444

45-
window.toolbarStyle = NSWindowToolbarStyle.Unified;
45+
window.toolbarStyle = NSWindowToolbarStyle.Automatic;
4646

4747
window.toolbar = toolbar;
4848
toolbar.validateVisibleItems();
@@ -94,6 +94,9 @@ export class SidebarViewController extends NSViewController {
9494
]),
9595
];
9696

97+
/**
98+
* @override
99+
*/
97100
loadView() {
98101
const outline = NSOutlineView.new();
99102

@@ -241,6 +244,9 @@ export class ContentViewController extends NSViewController {
241244
/** @type {NSTextField | null} */
242245
label = null;
243246

247+
/**
248+
* @override
249+
*/
244250
loadView() {
245251
const view = NSView.new();
246252

@@ -313,6 +319,9 @@ export class SplitViewController extends NSSplitViewController {
313319
sidebarView = SidebarViewController.new();
314320
contentView = ContentViewController.new();
315321

322+
/**
323+
* @override
324+
*/
316325
viewDidLoad() {
317326
this.view.frame = {
318327
origin: { x: 0, y: 0 },
@@ -341,19 +350,20 @@ export class SplitViewController extends NSSplitViewController {
341350
* @returns
342351
*/
343352
toolbarAllowedItemIdentifiers(_toolbar) {
344-
const array = NSMutableArray.new();
345-
array.addObject("NSToolbarToggleSidebarItem");
346-
return array;
353+
return this.toolbarDefaultItemIdentifiers(_toolbar);
347354
}
348355

349356
/**
350357
* @param {NSToolbar} _toolbar
351358
* @returns
352359
*/
353360
toolbarDefaultItemIdentifiers(_toolbar) {
354-
const array = NSMutableArray.new();
355-
array.addObject("NSToolbarToggleSidebarItem");
356-
return array;
361+
return NSArray.arrayWithArray([
362+
NSToolbarToggleSidebarItemIdentifier,
363+
NSToolbarFlexibleSpaceItemIdentifier,
364+
"run",
365+
NSToolbarSidebarTrackingSeparatorItemIdentifier,
366+
]);
357367
}
358368

359369
/**
@@ -369,10 +379,14 @@ export class SplitViewController extends NSSplitViewController {
369379
) {
370380
const item = NSToolbarItem.alloc().initWithItemIdentifier(identifier);
371381

372-
if (identifier === "NSToolbarToggleSidebarItem") {
382+
if (identifier === "run") {
373383
item.target = this;
374384
item.action = "toggleSidebar:";
375-
item.image = NSImage.imageNamed("sidebar.leading");
385+
item.image = NSImage.imageWithSystemSymbolNameAccessibilityDescription(
386+
"play.fill",
387+
null,
388+
);
389+
// item.isBordered = true;
376390
}
377391

378392
return item;
@@ -381,6 +395,7 @@ export class SplitViewController extends NSSplitViewController {
381395
/**
382396
* @param {NSObject} _item
383397
* @returns
398+
* @override
384399
*/
385400
validateToolbarItem(_item) {
386401
return true;

src/ClassMember.mm

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,15 @@ napi_value JS_NSObject_alloc(napi_env env, napi_callback_info cbinfo) {
2121
id self;
2222
napi_unwrap(env, jsThis, (void **)&self);
2323

24+
bool supercall = class_conformsToProtocol(self, @protocol(ObjCBridgeClassBuilderProtocol));
25+
26+
if (supercall) {
27+
ObjCBridgeState *state = ObjCBridgeState::InstanceData(env);
28+
ClassBuilder *builder = (ClassBuilder *)state->classesByPointer[self];
29+
if (!builder->isFinal)
30+
builder->build();
31+
}
32+
2433
id result = [self alloc];
2534
return ObjCBridgeState::InstanceData(env)->getObject(env, result, jsThis,
2635
kOwnedObject);

0 commit comments

Comments
 (0)