Skip to content

Commit c566176

Browse files
committed
some work
1 parent 392d64f commit c566176

File tree

103 files changed

+127183
-64017
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

103 files changed

+127183
-64017
lines changed

examples/metal_graphics.js

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
// @ts-check
2+
3+
import "objc";
4+
5+
export class ApplicationDelegate extends NSObject {
6+
static ObjCProtocols = [NSApplicationDelegate, NSWindowDelegate];
7+
8+
static {
9+
NativeClass(this);
10+
}
11+
12+
/**
13+
* @param {NSNotification} _notification
14+
*/
15+
applicationDidFinishLaunching(_notification) {
16+
const menu = NSMenu.new();
17+
NSApp.mainMenu = menu;
18+
19+
const appMenuItem = NSMenuItem.new();
20+
menu.addItem(appMenuItem);
21+
22+
const appMenu = NSMenu.new();
23+
appMenuItem.submenu = appMenu;
24+
25+
appMenu.addItemWithTitleActionKeyEquivalent("Quit", "terminate:", "q");
26+
27+
const controller = ViewController.new();
28+
const window = NSWindow.windowWithContentViewController(controller);
29+
30+
window.title = "NativeScript for macOS";
31+
window.delegate = this;
32+
window.styleMask = NSWindowStyleMask.Titled | NSWindowStyleMask.Closable |
33+
NSWindowStyleMask.Miniaturizable | NSWindowStyleMask.Resizable |
34+
NSWindowStyleMask.FullSizeContentView;
35+
36+
window.titlebarAppearsTransparent = true;
37+
window.titleVisibility = NSWindowTitleVisibility.Hidden;
38+
39+
window.backgroundColor = NSColor.colorWithSRGBRedGreenBlueAlpha(
40+
118 / 255,
41+
171 / 255,
42+
235 / 255,
43+
1,
44+
);
45+
46+
window.makeKeyAndOrderFront(this);
47+
48+
NSApp.activateIgnoringOtherApps(false);
49+
}
50+
51+
/**
52+
* @param {NSNotification} _notification
53+
*/
54+
windowWillClose(_notification) {
55+
NSApp.terminate(this);
56+
}
57+
}
58+
59+
export class ViewController extends NSViewController {
60+
static {
61+
NativeClass(this);
62+
}
63+
64+
loadView() {
65+
this.view = NSView.new();
66+
}
67+
68+
viewDidLoad() {
69+
super.viewDidLoad();
70+
}
71+
}
72+
73+
const NSApp = NSApplication.sharedApplication;
74+
75+
NSApp.delegate = ApplicationDelegate.new();
76+
77+
NSApp.setActivationPolicy(NSApplicationActivationPolicy.Regular);
78+
79+
NSApplicationMain(0, null);

metadata/metadata.ios.nsmd

1010 KB
Binary file not shown.

metadata/metadata.macos.nsmd

0 Bytes
Binary file not shown.

scripts/metagen.ts

Lines changed: 35 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3,41 +3,43 @@ const COMMON_FRAMEWORKS = [
33
"CoreFoundation",
44
"CoreGraphics",
55
"CoreText",
6-
// "CoreServices",
7-
// "CoreMedia",
8-
// "CoreVideo",
9-
// "CoreImage",
10-
// "CoreData",
11-
// "CoreMIDI",
12-
// "CoreML",
13-
// "CoreBluetooth",
14-
// "CoreLocation",
15-
// "CoreMotion",
16-
// "MLCompute",
17-
// "AudioToolbox",
18-
// "AudioUnit",
19-
// "AVFoundation",
206
"QuartzCore",
21-
// "Metal",
22-
// "MetalKit",
23-
// "MetalPerformanceShaders",
24-
// "SpriteKit",
25-
// "SceneKit",
26-
// "ModelIO",
27-
// "GameController",
28-
// "GameKit",
29-
// "GameplayKit",
307
"WebKit",
31-
// "CloudKit",
32-
// "Intents",
33-
// "Contacts",
34-
// "CoreSpotlight",
35-
// "JavaScriptCore",
36-
// "UserNotifications",
37-
// "CoreHaptics",
38-
// "EventKit",
39-
// "AddressBook",
40-
// "MapKit",
8+
9+
// Optional for core compat
10+
"Metal",
11+
"MetalKit",
12+
"MetalPerformanceShaders",
13+
"SpriteKit",
14+
"SceneKit",
15+
"ModelIO",
16+
"GameController",
17+
"GameKit",
18+
"GameplayKit",
19+
"CloudKit",
20+
"Intents",
21+
"Contacts",
22+
"CoreSpotlight",
23+
"JavaScriptCore",
24+
"UserNotifications",
25+
"CoreHaptics",
26+
"EventKit",
27+
"AddressBook",
28+
"MapKit",
29+
"CoreServices",
30+
"CoreMedia",
31+
"CoreVideo",
32+
"CoreImage",
33+
"CoreData",
34+
"CoreMIDI",
35+
"CoreML",
36+
"CoreBluetooth",
37+
"CoreLocation",
38+
"CoreMotion",
39+
"MLCompute",
40+
"AudioToolbox",
41+
"AudioUnit",
42+
"AVFoundation",
4143
];
4244

4345
const MACOS_FRAMEWORKS = [

src/ClassMember.mm

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,6 @@
126126
inline void objcNativeCall(napi_env env, napi_value jsThis, MethodCif *cif,
127127
id self, void **avalues, void *rvalue,
128128
bool classMethod) {
129-
// TODO: This seems bad for performance. Is there a better way?
130129
bool supercall =
131130
classMethod
132131
? class_conformsToProtocol(self,

src/Object.mm

Lines changed: 30 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -22,30 +22,30 @@
2222
}
2323
}
2424
25-
return target.__customProps__?.[name];
25+
// return target[name];
2626
},
2727
28-
set (target, name, value) {
29-
if (name in target) {
30-
target[name] = value;
31-
return true;
32-
}
33-
34-
// if (isArray) {
35-
// const index = Number(name);
36-
// if (!isNaN(index)) {
37-
// target.setObjectAtIndexedSubscript(value, index);
38-
// return true;
39-
// }
40-
// }
41-
42-
if (!target.__customProps__) {
43-
target.__customProps__ = {};
44-
}
45-
46-
target.__customProps__[name] = value;
47-
return true;
48-
},
28+
// set (target, name, value) {
29+
// if (name in target) {
30+
// target[name] = value;
31+
// return true;
32+
// }
33+
34+
// // if (isArray) {
35+
// // const index = Number(name);
36+
// // if (!isNaN(index)) {
37+
// // target.setObjectAtIndexedSubscript(value, index);
38+
// // return true;
39+
// // }
40+
// // }
41+
42+
// if (!target.__customProps__) {
43+
// target.__customProps__ = {};
44+
// }
45+
46+
// target.__customProps__[name] = value;
47+
// return true;
48+
// },
4949
});
5050
})
5151
)";
@@ -117,34 +117,14 @@ void finalize_objc_object_borrowed(napi_env, void *data, void *hint) {
117117
return nullptr;
118118
}
119119

120-
// napi_value orig = result;
121-
122-
// result =
123-
// proxyNativeObject(env, result, [obj isKindOfClass:[NSArray class]]);
124-
125-
// We need to wrap the proxied object separately
126-
// NAPI_GUARD(napi_wrap(env, result, obj, nullptr, nullptr, nullptr)) {
127-
// NAPI_THROW_LAST_ERROR
128-
// return nullptr;
129-
// }
130-
131-
// void *check = nullptr;
132-
// NAPI_GUARD(napi_unwrap(env, orig, &check)) {
133-
// NAPI_THROW_LAST_ERROR
134-
// return nullptr;
135-
// }
136-
// if (check != obj) {
137-
// NSLog(@"wrap failed on orig: %p, %p", check, obj);
138-
// }
139-
140-
// check = nullptr;
141-
// NAPI_GUARD(napi_unwrap(env, result, &check)) {
142-
// NAPI_THROW_LAST_ERROR
143-
// return nullptr;
144-
// }
145-
// if (check != obj) {
146-
// NSLog(@"wrap failed on result: %p, %p", check, obj);
147-
// }
120+
napi_value orig = result;
121+
122+
result =
123+
proxyNativeObject(env, result, [obj isKindOfClass:[NSArray class]]);
124+
125+
// We need to wrap the proxied object separately except for Hermes,
126+
// We'll just ignore the error there.
127+
napi_wrap(env, result, obj, nullptr, nullptr, nullptr);
148128

149129
napi_ref ref = nullptr;
150130
NAPI_GUARD(napi_add_finalizer(env, result, obj,

0 commit comments

Comments
 (0)