Repository navigation
Expand file tree
/
Copy pathmenubar.js
More file actions
104 lines (80 loc) · 2.26 KB
/
Copy pathmenubar.js
File metadata and controls
104 lines (80 loc) · 2.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
// @ts-check
import "@nativescript/macos-node-api";
/**
* @implements {NSApplicationDelegate}
*/
export class ApplicationDelegate extends NSObject {
static ObjCProtocols = [NSApplicationDelegate];
static ObjCExposedMethods = {
buttonClicked: {
params: [NSView],
returns: interop.types.void,
},
};
static {
NativeClass(this);
}
popover = NSPopover.new();
/**
* @param {NSNotification} _notification
*/
applicationDidFinishLaunching(_notification) {
const statusBar = NSStatusBar.systemStatusBar;
const statusItem = statusBar.statusItemWithLength(
NSVariableStatusItemLength
);
if (statusItem.button != null) {
statusItem.button.image =
NSImage.imageWithSystemSymbolNameAccessibilityDescription("star", null);
statusItem.button.action = "buttonClicked";
statusItem.button.target = this;
this.popover.contentViewController = ViewController.new();
}
}
/**
* @param {NSView} sender
*/
buttonClicked(sender) {
if (this.popover.isShown) {
this.popover.performClose(sender);
} else {
this.popover.showRelativeToRectOfViewPreferredEdge(
sender.bounds,
sender,
NSRectEdge.MinYEdge
);
}
}
}
export class ViewController extends NSViewController {
static {
NativeClass(this);
}
loadView() {
this.view = NSView.new();
}
viewDidLoad() {
super.viewDidLoad();
this.view.frame = {
origin: { x: 0, y: 0 },
size: { width: 300, height: 300 },
};
const image = NSImage.alloc().initWithContentsOfFile(
new URL("../assets/NativeScript.png", import.meta.url).pathname
);
image.size = { width: 128, height: 128 };
const imageView = NSImageView.imageViewWithImage(image);
imageView.translatesAutoresizingMaskIntoConstraints = false;
this.view.addSubview(imageView);
imageView.centerXAnchor.constraintEqualToAnchor(
this.view.centerXAnchor
).isActive = true;
imageView.centerYAnchor.constraintEqualToAnchor(
this.view.centerYAnchor
).isActive = true;
}
}
const NSApp = NSApplication.sharedApplication;
NSApp.delegate = ApplicationDelegate.new();
NSApp.setActivationPolicy(NSApplicationActivationPolicy.Accessory);
NSApplicationMain(0, null);