nitro-ui-macos 0.0.0 → 0.0.2
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/CONTRIBUTING.md +49 -0
- package/LICENSE +4 -3
- package/PARITY.md +373 -0
- package/README.md +144 -5
- package/native/nitro-core/Package.swift +78 -0
- package/native/nitro-ui-core/Package.swift +112 -0
- package/native/nitro-ui-core/Sources/NitroUICoreMac/AnimationFrameDisplayLink.swift +127 -0
- package/native/nitro-ui-core/Sources/NitroUICoreMac/HybridAnimationFrameScheduler.swift +91 -0
- package/native/nitro-ui-core/Sources/NitroUICoreMac/HybridLinking.swift +18 -0
- package/native/nitro-ui-dev/Package.swift +102 -0
- package/native/nitro-ui-dev/Sources/NitroUIDevMac/DevBundleLoad.swift +14 -0
- package/native/nitro-ui-dev/Sources/NitroUIDevMac/DevBundleLoader.swift +85 -0
- package/native/nitro-ui-dev/Sources/NitroUIDevMac/DevLauncher.swift +192 -0
- package/native/nitro-ui-dev/Sources/NitroUIDevMac/DevMenu.swift +172 -0
- package/native/nitro-ui-dev/Sources/NitroUIDevMac/DevServerBrowser.swift +86 -0
- package/native/nitro-ui-dev/Sources/NitroUIDevMac/DevSession.swift +151 -0
- package/native/nitro-ui-dev/Sources/NitroUIDevMac/DevShortcuts.swift +85 -0
- package/native/nitro-ui-dev/Sources/NitroUIDevMac/DevToast.swift +85 -0
- package/native/nitro-ui-dev/Sources/NitroUIDevMac/DevTools.swift +141 -0
- package/native/nitro-ui-dev/Sources/NitroUIDevMac/ErrorModels.swift +97 -0
- package/native/nitro-ui-dev/Sources/NitroUIDevMac/ErrorOverlay.swift +698 -0
- package/native/nitro-ui-dev/Sources/NitroUIDevMac/HybridDevBundles.swift +64 -0
- package/native/nitro-ui-dev/Sources/NitroUIDevMac/HybridDevErrors.swift +56 -0
- package/native/nitro-ui-dev/Sources/NitroUIDevMac/HybridDevLoadingView.swift +27 -0
- package/native/nitro-ui-dev/Sources/NitroUIDevMac/HybridDevMenu.swift +40 -0
- package/native/nitro-ui-dev/Sources/NitroUIDevMac/HybridDevToast.swift +19 -0
- package/native/nitro-ui-dev/Sources/NitroUIDevMac/LauncherWindowController.swift +217 -0
- package/native/nitro-ui-dev/Sources/NitroUIDevMac/LoadingOverlay.swift +104 -0
- package/native/nitro-ui-dev/Sources/NitroUIDevMac/RegisterDevLoader.swift +22 -0
- package/native/nitro-ui-dev/Sources/NitroUIDevMac/SavedBundles.swift +70 -0
- package/native/nitro-ui-glass/Package.swift +103 -0
- package/native/nitro-ui-glass/macos/HybridLiquidGlass.swift +5 -0
- package/native/nitro-ui-glass/macos/HybridNativeLiquidGlassContainerView.swift +40 -0
- package/native/nitro-ui-glass/macos/HybridNativeLiquidGlassView.swift +80 -0
- package/native/nitro-ui-glass/macos/LiquidGlassEffectView.swift +181 -0
- package/native/nitro-ui-glass/macos/LiquidGlassSupport.swift +17 -0
- package/native/nitro-ui-navigation/Package.swift +105 -0
- package/native/nitro-ui-navigation/Sources/NitroUINavigationMac/HybridNavigationScreen.swift +199 -0
- package/native/nitro-ui-navigation/Sources/NitroUINavigationMac/HybridNavigationSharedElement.swift +17 -0
- package/native/nitro-ui-navigation/Sources/NitroUINavigationMac/HybridNavigationSplit.swift +889 -0
- package/native/nitro-ui-navigation/Sources/NitroUINavigationMac/HybridNavigationStack.swift +404 -0
- package/native/nitro-ui-navigation/Sources/NitroUINavigationMac/HybridNavigationTabs.swift +186 -0
- package/native/nitro-ui-navigation/Sources/NitroUINavigationMac/MacStackContainerController.swift +260 -0
- package/native/nitro-ui-navigation/Sources/NitroUINavigationMac/NavigationSharedElementView.swift +28 -0
- package/native/nitro-ui-renderer/Package.swift +105 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Animations/HybridAnimator.swift +502 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Animations/NitroAnimationContext.swift +54 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Animations/View+Animations.swift +35 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/AssetFonts.swift +36 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/FlippedView.swift +360 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/HybridContainerView.swift +28 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/HybridFonts.swift +7 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/HybridLabel.swift +127 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/HybridMaskedView.swift +185 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/HybridScrollView.swift +255 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/HybridScrollViewContent.swift +22 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/HybridView.swift +18 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/Image/HybridImage.swift +281 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/Image/HybridImageFactory.swift +132 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/Image/HybridImageLoader.swift +149 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/Image/HybridImageView.swift +601 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/Image/ImagePixelSupport.swift +418 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/LabelView.swift +198 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/List/HybridListView.swift +177 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/List/NativeListCell.swift +98 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/List/NativeListContentView.swift +12 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/List/NativeListFenwickTree.swift +94 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/List/NativeListScrollView.swift +1100 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/List/NativeListSnapshot.swift +24 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/List/NativeListUpdate.swift +11 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/List/NativeListView.swift +260 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/NativeContainerView.swift +443 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/NitroViewProtocols.swift +275 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/ShadowLayers.swift +338 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/TextInput/HybridTextInput.swift +252 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/TextInput/NitroTextInputView.swift +447 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/View.swift +660 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/CustomViewController.swift +254 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/DesktopHostDelegate.swift +14 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Extensions.swift +102 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Gestures/GestureRecognizerDelegate.swift +24 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Gestures/HybridGestureRecognizer.swift +41 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Gestures/HybridLongPressGestureRecognizer.swift +172 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Gestures/HybridPanGestureRecognizer.swift +193 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Gestures/HybridTapGestureRecognizer.swift +165 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/HybridAppearance.swift +75 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/HybridApplication.swift +29 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/HybridKeyboard.swift +26 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/HybridScreen.swift +29 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/HybridViewController.swift +232 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/HybridWindow.swift +61 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/HybridWindowScene.swift +17 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/LayoutNode.swift +73 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/NSColor+rgba.swift +29 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/RegisterRootCallback.swift +27 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/RuntimeReloadableAppDelegate.swift +7 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/SafeAreaInsetsListeners.swift +26 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/SizeListeners.swift +27 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/UIErrorHandler.swift +15 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/ViewController.swift +6 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Window.swift +156 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/WindowScene.swift +23 -0
- package/native/nitro-ui-runtime/Package.swift +67 -0
- package/native/nitro-ui-runtime/Sources/NitroUIRuntimeMac/DevLoader.swift +16 -0
- package/native/nitro-ui-runtime/Sources/NitroUIRuntimeMac/NitroUIAppDelegate.swift +253 -0
- package/package.json +59 -8
- package/src/Platform.ts +43 -0
- package/src/bin.js +18 -0
- package/src/build.ts +453 -0
- package/src/bundleWorker.ts +80 -0
- package/src/cli.ts +157 -0
- package/src/config.ts +233 -0
- package/src/create.ts +67 -0
- package/src/files.ts +70 -0
- package/src/index.ts +1 -0
- package/src/init.ts +301 -0
- package/src/inlinePlatform.ts +140 -0
- package/src/modules.ts +385 -0
- package/src/packageApp.ts +103 -0
- package/src/packageDirectory.ts +61 -0
- package/src/preload.ts +40 -0
- package/src/prepare.ts +433 -0
- package/src/run.ts +41 -0
- package/src/runApp.ts +81 -0
- package/src/start.ts +152 -0
- package/src/toolchain.ts +83 -0
- package/src/versions.ts +103 -0
- package/templates/AppIcon.icns +0 -0
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
public import AppKit
|
|
2
|
+
|
|
3
|
+
public final class MacWindowScene {
|
|
4
|
+
public let title: String
|
|
5
|
+
public let defaultContentSize: CGSize
|
|
6
|
+
internal var managedWindows: [NSWindow] = []
|
|
7
|
+
|
|
8
|
+
public init(
|
|
9
|
+
title: String = "NitroUI",
|
|
10
|
+
defaultContentSize: CGSize = CGSize(width: 640, height: 480)
|
|
11
|
+
) {
|
|
12
|
+
self.title = title
|
|
13
|
+
self.defaultContentSize = defaultContentSize
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
public func clearManagedWindows() {
|
|
17
|
+
managedWindows.removeAll()
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
public protocol WindowScene {
|
|
22
|
+
var scene: MacWindowScene { get }
|
|
23
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
// swift-tools-version: 6.4
|
|
2
|
+
|
|
3
|
+
import PackageDescription
|
|
4
|
+
|
|
5
|
+
let package = Package(
|
|
6
|
+
name: "NitroUIRuntime",
|
|
7
|
+
platforms: [.macOS(.v13)],
|
|
8
|
+
products: [
|
|
9
|
+
.library(name: "NitroUIRuntime", targets: ["NitroUIRuntime"]),
|
|
10
|
+
],
|
|
11
|
+
dependencies: [
|
|
12
|
+
.package(path: "../nitro-ui-layout"),
|
|
13
|
+
.package(path: "../nitro-hermes"),
|
|
14
|
+
.package(path: "../nitro-core"),
|
|
15
|
+
.package(path: "../nitro-ui-core"),
|
|
16
|
+
.package(path: "../nitro-networking"),
|
|
17
|
+
.package(path: "../nitro-ui-renderer"),
|
|
18
|
+
.package(path: "../nitro-ui-navigation"),
|
|
19
|
+
],
|
|
20
|
+
targets: [
|
|
21
|
+
.target(
|
|
22
|
+
name: "NitroUIRuntimeCxx",
|
|
23
|
+
dependencies: [
|
|
24
|
+
.product(name: "NitroUILayout", package: "nitro-ui-layout"),
|
|
25
|
+
.product(name: "Hermes", package: "nitro-hermes"),
|
|
26
|
+
.product(name: "NitroModules", package: "nitro-core"),
|
|
27
|
+
.product(name: "NitroUICore", package: "nitro-ui-core"),
|
|
28
|
+
.product(name: "NitroUINetworking", package: "nitro-networking"),
|
|
29
|
+
.product(name: "NitroUIRenderer", package: "nitro-ui-renderer"),
|
|
30
|
+
.product(name: "NitroUINavigation", package: "nitro-ui-navigation"),
|
|
31
|
+
],
|
|
32
|
+
cxxSettings: [
|
|
33
|
+
.define("DEBUG", .when(configuration: .debug)),
|
|
34
|
+
.define("NDEBUG", .when(configuration: .release)),
|
|
35
|
+
.disableWarning("nullability-extension"),
|
|
36
|
+
]
|
|
37
|
+
),
|
|
38
|
+
.target(
|
|
39
|
+
name: "NitroUIRuntime",
|
|
40
|
+
dependencies: [
|
|
41
|
+
"NitroUIRuntimeCxx",
|
|
42
|
+
.product(name: "NitroModules", package: "nitro-core"),
|
|
43
|
+
.product(name: "NitroUIRenderer", package: "nitro-ui-renderer"),
|
|
44
|
+
],
|
|
45
|
+
path: "Sources",
|
|
46
|
+
exclude: [
|
|
47
|
+
"NitroUIRuntimeCxx",
|
|
48
|
+
],
|
|
49
|
+
sources: [
|
|
50
|
+
"NitroUIRuntime/JSRuntime.swift",
|
|
51
|
+
"NitroUIRuntime/PreparedJavaScript.swift",
|
|
52
|
+
"NitroUIRuntimeMac",
|
|
53
|
+
],
|
|
54
|
+
cxxSettings: [
|
|
55
|
+
.define("DEBUG", .when(configuration: .debug)),
|
|
56
|
+
.define("NDEBUG", .when(configuration: .release)),
|
|
57
|
+
],
|
|
58
|
+
swiftSettings: [
|
|
59
|
+
.enableUpcomingFeature("InternalImportsByDefault"),
|
|
60
|
+
.enableUpcomingFeature("MemberImportVisibility"),
|
|
61
|
+
.interoperabilityMode(.Cxx),
|
|
62
|
+
.unsafeFlags(["-Xfrontend", "-clang-header-expose-decls=has-expose-attr-or-stdlib"]),
|
|
63
|
+
]
|
|
64
|
+
),
|
|
65
|
+
],
|
|
66
|
+
cxxLanguageStandard: .cxx20
|
|
67
|
+
)
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
public import AppKit
|
|
2
|
+
|
|
3
|
+
/// Loads the app's JavaScript from a dev server instead of its bundle. nitro-ui-dev sets one in Debug builds.
|
|
4
|
+
@MainActor
|
|
5
|
+
public protocol DevLoader: AnyObject {
|
|
6
|
+
/// Starts or resumes a dev session, invoking `registerAppModules` before running JS
|
|
7
|
+
/// and `onAppLoaded` after `app.js` has run and registered the root component.
|
|
8
|
+
func showLauncher(
|
|
9
|
+
registerAppModules: @escaping () -> Void,
|
|
10
|
+
onAppLoaded: @escaping (JSRuntime) -> Void
|
|
11
|
+
)
|
|
12
|
+
func handleMemoryPressure()
|
|
13
|
+
func bind(to window: NSWindow)
|
|
14
|
+
func unbind(from window: NSWindow)
|
|
15
|
+
func beforeReload()
|
|
16
|
+
}
|
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
public import AppKit
|
|
2
|
+
public import Foundation
|
|
3
|
+
public import NitroUIRenderer
|
|
4
|
+
|
|
5
|
+
@objc private protocol NitroEditUndoActions {
|
|
6
|
+
func undo(_ sender: Any?)
|
|
7
|
+
func redo(_ sender: Any?)
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/// Runs the app's JavaScript in a native AppKit host and manages its main window.
|
|
11
|
+
@MainActor
|
|
12
|
+
open class NitroUIAppDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate, @MainActor RuntimeReloadableAppDelegate, @MainActor NitroDesktopHostDelegate {
|
|
13
|
+
public static var devLoader: (any DevLoader)?
|
|
14
|
+
private var runtime: JSRuntime?
|
|
15
|
+
public var activeRuntime: JSRuntime? { runtime }
|
|
16
|
+
public private(set) var window: NSWindow?
|
|
17
|
+
private var activeScene: MacWindowScene?
|
|
18
|
+
public var shouldTerminateAfterLastWindowClosedHandler: (() -> Bool)?
|
|
19
|
+
public var shouldTerminateHandler: (() -> Bool)?
|
|
20
|
+
public var dockMenuProvider: (() -> NSMenu?)?
|
|
21
|
+
public var openURLsHandler: (([URL]) -> Void)?
|
|
22
|
+
public var beforeReloadHandler: (() -> Void)?
|
|
23
|
+
|
|
24
|
+
open var windowTitle: String {
|
|
25
|
+
Bundle.main.object(forInfoDictionaryKey: "CFBundleDisplayName") as? String
|
|
26
|
+
?? Bundle.main.object(forInfoDictionaryKey: "CFBundleName") as? String
|
|
27
|
+
?? "NitroUI"
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
open var defaultContentSize: CGSize {
|
|
31
|
+
CGSize(width: 640, height: 480)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/// Override in an app subclass to register app-level Nitro modules before JS evaluates.
|
|
35
|
+
open func registerAppModules() {}
|
|
36
|
+
|
|
37
|
+
open func applicationDidFinishLaunching(_ notification: Notification) {
|
|
38
|
+
setupMainMenu()
|
|
39
|
+
if let devLoader = Self.devLoader {
|
|
40
|
+
startWithDevLoader(devLoader)
|
|
41
|
+
} else {
|
|
42
|
+
runtime = JSRuntime()
|
|
43
|
+
registerAppModules()
|
|
44
|
+
runJavaScript()
|
|
45
|
+
mountRoot()
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
open func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool {
|
|
50
|
+
if let handler = shouldTerminateAfterLastWindowClosedHandler {
|
|
51
|
+
return handler()
|
|
52
|
+
}
|
|
53
|
+
return false
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
open func applicationShouldTerminate(_ sender: NSApplication) -> NSApplication.TerminateReply {
|
|
57
|
+
if let handler = shouldTerminateHandler {
|
|
58
|
+
return handler() ? .terminateNow : .terminateCancel
|
|
59
|
+
}
|
|
60
|
+
return .terminateNow
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
open func applicationWillTerminate(_ notification: Notification) {
|
|
64
|
+
autoreleasepool {
|
|
65
|
+
beforeReloadHandler?()
|
|
66
|
+
RegisterRootCallback.clear()
|
|
67
|
+
if let existingWindow = window {
|
|
68
|
+
Self.devLoader?.unbind(from: existingWindow)
|
|
69
|
+
NitroWindowTeardown.teardown(existingWindow)
|
|
70
|
+
}
|
|
71
|
+
window = nil
|
|
72
|
+
activeScene?.clearManagedWindows()
|
|
73
|
+
activeScene = nil
|
|
74
|
+
Self.devLoader?.beforeReload()
|
|
75
|
+
runtime = nil
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
open func applicationDockMenu(_ sender: NSApplication) -> NSMenu? {
|
|
80
|
+
return dockMenuProvider?()
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
open func application(_ application: NSApplication, open urls: [URL]) {
|
|
84
|
+
openURLsHandler?(urls)
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
open func applicationShouldHandleReopen(_ sender: NSApplication, hasVisibleWindows flag: Bool) -> Bool {
|
|
88
|
+
if !flag {
|
|
89
|
+
reopenMainWindow()
|
|
90
|
+
}
|
|
91
|
+
return true
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
open func reopenMainWindow() {
|
|
95
|
+
if let window {
|
|
96
|
+
window.makeKeyAndOrderFront(nil)
|
|
97
|
+
if NSApp.activationPolicy() == .regular {
|
|
98
|
+
NSApp.activate(ignoringOtherApps: true)
|
|
99
|
+
}
|
|
100
|
+
} else if Self.devLoader == nil || runtime != nil {
|
|
101
|
+
mountRoot()
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
public func reloadRuntime() {
|
|
106
|
+
// JavaScript calls this, so the old runtime is replaced after the call returns.
|
|
107
|
+
DispatchQueue.main.async {
|
|
108
|
+
autoreleasepool {
|
|
109
|
+
self.beforeReloadHandler?()
|
|
110
|
+
RegisterRootCallback.clear()
|
|
111
|
+
if let existingWindow = self.window {
|
|
112
|
+
Self.devLoader?.unbind(from: existingWindow)
|
|
113
|
+
NitroWindowTeardown.teardown(existingWindow)
|
|
114
|
+
}
|
|
115
|
+
self.window = nil
|
|
116
|
+
self.activeScene?.clearManagedWindows()
|
|
117
|
+
self.activeScene = nil
|
|
118
|
+
Self.devLoader?.beforeReload()
|
|
119
|
+
self.runtime = nil
|
|
120
|
+
}
|
|
121
|
+
if let devLoader = Self.devLoader {
|
|
122
|
+
self.startWithDevLoader(devLoader)
|
|
123
|
+
} else {
|
|
124
|
+
self.runtime = JSRuntime()
|
|
125
|
+
self.registerAppModules()
|
|
126
|
+
self.runJavaScript()
|
|
127
|
+
self.mountRoot()
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
open func resolveBundleURL() -> URL {
|
|
133
|
+
#if DEBUG
|
|
134
|
+
let name = "main"
|
|
135
|
+
let ext = "js"
|
|
136
|
+
#else
|
|
137
|
+
let name = "main"
|
|
138
|
+
let ext = "hbc"
|
|
139
|
+
#endif
|
|
140
|
+
if let resourceURL = Bundle.main.url(forResource: name, withExtension: ext) {
|
|
141
|
+
return resourceURL
|
|
142
|
+
}
|
|
143
|
+
return Bundle.main.bundleURL.appendingPathComponent("\(name).\(ext)")
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
open func mountRoot() {
|
|
147
|
+
if let existingWindow = window {
|
|
148
|
+
Self.devLoader?.unbind(from: existingWindow)
|
|
149
|
+
NitroWindowTeardown.teardown(existingWindow)
|
|
150
|
+
window = nil
|
|
151
|
+
}
|
|
152
|
+
activeScene?.clearManagedWindows()
|
|
153
|
+
|
|
154
|
+
let scene = MacWindowScene(title: windowTitle, defaultContentSize: defaultContentSize)
|
|
155
|
+
activeScene = scene
|
|
156
|
+
do {
|
|
157
|
+
let window = try RegisterRootCallback.onSceneCreated(scene)
|
|
158
|
+
window.delegate = self
|
|
159
|
+
self.window = window
|
|
160
|
+
Self.devLoader?.bind(to: window)
|
|
161
|
+
window.makeKeyAndOrderFront(nil)
|
|
162
|
+
} catch {
|
|
163
|
+
fatalError("Could not mount NitroUI: \(error)")
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
private func startWithDevLoader(_ devLoader: any DevLoader) {
|
|
168
|
+
devLoader.showLauncher(
|
|
169
|
+
registerAppModules: { [weak self] in
|
|
170
|
+
self?.registerAppModules()
|
|
171
|
+
},
|
|
172
|
+
onAppLoaded: { [weak self] newRuntime in
|
|
173
|
+
guard let self else { return }
|
|
174
|
+
self.runtime = newRuntime
|
|
175
|
+
self.mountRoot()
|
|
176
|
+
}
|
|
177
|
+
)
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
private func runJavaScript() {
|
|
181
|
+
guard let runtime else {
|
|
182
|
+
fatalError("JSRuntime was not initialized before running JavaScript.")
|
|
183
|
+
}
|
|
184
|
+
let url = resolveBundleURL()
|
|
185
|
+
do {
|
|
186
|
+
_ = try runtime.runJavaScript(fromFileURL: url, sourceURL: url)
|
|
187
|
+
} catch {
|
|
188
|
+
fatalError("Could not start NitroUI: \(error)")
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
@objc private func handleReopenMenuItem(_ sender: Any?) {
|
|
193
|
+
reopenMainWindow()
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
private func setupMainMenu() {
|
|
197
|
+
let mainMenu = NSMenu()
|
|
198
|
+
let appName = windowTitle
|
|
199
|
+
|
|
200
|
+
let appMenuItem = NSMenuItem()
|
|
201
|
+
let appMenu = NSMenu(title: appName)
|
|
202
|
+
let quitItem = NSMenuItem(
|
|
203
|
+
title: "Quit \(appName)",
|
|
204
|
+
action: #selector(NSApplication.terminate(_:)),
|
|
205
|
+
keyEquivalent: "q"
|
|
206
|
+
)
|
|
207
|
+
appMenu.addItem(quitItem)
|
|
208
|
+
appMenuItem.submenu = appMenu
|
|
209
|
+
mainMenu.addItem(appMenuItem)
|
|
210
|
+
|
|
211
|
+
let editMenuItem = NSMenuItem()
|
|
212
|
+
let editMenu = NSMenu(title: "Edit")
|
|
213
|
+
editMenu.addItem(NSMenuItem(title: "Undo", action: #selector(NitroEditUndoActions.undo(_:)), keyEquivalent: "z"))
|
|
214
|
+
editMenu.addItem(NSMenuItem(title: "Redo", action: #selector(NitroEditUndoActions.redo(_:)), keyEquivalent: "Z"))
|
|
215
|
+
editMenu.addItem(.separator())
|
|
216
|
+
editMenu.addItem(NSMenuItem(title: "Cut", action: #selector(NSText.cut(_:)), keyEquivalent: "x"))
|
|
217
|
+
editMenu.addItem(NSMenuItem(title: "Copy", action: #selector(NSText.copy(_:)), keyEquivalent: "c"))
|
|
218
|
+
editMenu.addItem(NSMenuItem(title: "Paste", action: #selector(NSText.paste(_:)), keyEquivalent: "v"))
|
|
219
|
+
editMenu.addItem(NSMenuItem(title: "Delete", action: #selector(NSText.delete(_:)), keyEquivalent: ""))
|
|
220
|
+
editMenu.addItem(NSMenuItem(title: "Select All", action: #selector(NSText.selectAll(_:)), keyEquivalent: "a"))
|
|
221
|
+
editMenuItem.submenu = editMenu
|
|
222
|
+
mainMenu.addItem(editMenuItem)
|
|
223
|
+
|
|
224
|
+
let windowMenuItem = NSMenuItem()
|
|
225
|
+
let windowMenu = NSMenu(title: "Window")
|
|
226
|
+
let reopenItem = NSMenuItem(
|
|
227
|
+
title: "Show Window",
|
|
228
|
+
action: #selector(handleReopenMenuItem(_:)),
|
|
229
|
+
keyEquivalent: "n"
|
|
230
|
+
)
|
|
231
|
+
reopenItem.target = self
|
|
232
|
+
windowMenu.addItem(reopenItem)
|
|
233
|
+
windowMenu.addItem(
|
|
234
|
+
NSMenuItem(
|
|
235
|
+
title: "Close",
|
|
236
|
+
action: #selector(NSWindow.performClose(_:)),
|
|
237
|
+
keyEquivalent: "w"
|
|
238
|
+
)
|
|
239
|
+
)
|
|
240
|
+
windowMenu.addItem(
|
|
241
|
+
NSMenuItem(
|
|
242
|
+
title: "Minimize",
|
|
243
|
+
action: #selector(NSWindow.performMiniaturize(_:)),
|
|
244
|
+
keyEquivalent: "m"
|
|
245
|
+
)
|
|
246
|
+
)
|
|
247
|
+
windowMenuItem.submenu = windowMenu
|
|
248
|
+
mainMenu.addItem(windowMenuItem)
|
|
249
|
+
|
|
250
|
+
NSApp.mainMenu = mainMenu
|
|
251
|
+
NSApp.windowsMenu = windowMenu
|
|
252
|
+
}
|
|
253
|
+
}
|
package/package.json
CHANGED
|
@@ -1,12 +1,63 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nitro-ui-macos",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"description": "Unofficial macOS
|
|
3
|
+
"version": "0.0.2",
|
|
4
|
+
"description": "Unofficial macOS (AppKit) target, bundler platform plugin, and CLI for NitroUI.",
|
|
5
5
|
"license": "MIT",
|
|
6
|
-
"
|
|
7
|
-
"
|
|
8
|
-
"
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
6
|
+
"homepage": "https://github.com/imranbarbhuiya/nitro-ui-desktop/tree/main/packages/nitro-ui-macos#readme",
|
|
7
|
+
"bugs": "https://github.com/imranbarbhuiya/nitro-ui-desktop/issues",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/imranbarbhuiya/nitro-ui-desktop.git",
|
|
11
|
+
"directory": "packages/nitro-ui-macos"
|
|
12
|
+
},
|
|
13
|
+
"type": "module",
|
|
14
|
+
"publishConfig": {
|
|
15
|
+
"access": "public"
|
|
16
|
+
},
|
|
17
|
+
"bin": {
|
|
18
|
+
"nitro-ui-macos": "src/bin.js"
|
|
19
|
+
},
|
|
20
|
+
"exports": {
|
|
21
|
+
".": {
|
|
22
|
+
"types": "./src/index.ts",
|
|
23
|
+
"default": "./src/index.ts"
|
|
24
|
+
},
|
|
25
|
+
"./preload": "./src/preload.ts",
|
|
26
|
+
"./package.json": "./package.json"
|
|
27
|
+
},
|
|
28
|
+
"files": [
|
|
29
|
+
"src",
|
|
30
|
+
"native",
|
|
31
|
+
"templates",
|
|
32
|
+
"LICENSE",
|
|
33
|
+
"README.md",
|
|
34
|
+
"PARITY.md",
|
|
35
|
+
"CONTRIBUTING.md"
|
|
36
|
+
],
|
|
37
|
+
"scripts": {
|
|
38
|
+
"typecheck": "tsc --noEmit",
|
|
39
|
+
"test": "bun test test"
|
|
40
|
+
},
|
|
41
|
+
"dependencies": {
|
|
42
|
+
"nitro-core": "1.0.0-alpha.nightly.137.gd4793c40b8b8",
|
|
43
|
+
"nitrogen": "1.0.0-alpha.nightly.137.gd4793c40b8b8",
|
|
44
|
+
"nitro-hermes": "0.3.0",
|
|
45
|
+
"nitro-networking": "0.3.0",
|
|
46
|
+
"nitro-ui-bundler": "0.3.0",
|
|
47
|
+
"nitro-ui-core": "0.3.0",
|
|
48
|
+
"nitro-ui-dev": "0.3.0",
|
|
49
|
+
"nitro-ui-layout": "0.3.0",
|
|
50
|
+
"nitro-ui-layout-starlight": "0.3.0",
|
|
51
|
+
"nitro-ui-navigation": "0.3.0",
|
|
52
|
+
"nitro-ui-renderer": "0.3.0",
|
|
53
|
+
"nitro-ui-runtime": "0.3.0",
|
|
54
|
+
"oxc-walker": "1.1.1",
|
|
55
|
+
"rolldown": "1.3.4",
|
|
56
|
+
"zod": "4.6.7"
|
|
57
|
+
},
|
|
58
|
+
"devDependencies": {
|
|
59
|
+
"@types/bun": "^1.4.2",
|
|
60
|
+
"nitro-ui-glass": "0.3.0",
|
|
61
|
+
"typescript": "7.0.2"
|
|
62
|
+
}
|
|
12
63
|
}
|
package/src/Platform.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { Platform as CorePlatform } from 'nitro-ui-core'
|
|
2
|
+
|
|
3
|
+
export type PlatformOS = 'ios' | 'android' | 'macos'
|
|
4
|
+
|
|
5
|
+
export interface MacOSPlatform {
|
|
6
|
+
/** The platform the app runs on. Replaced with `'macos'` in macOS bundles. */
|
|
7
|
+
readonly OS: PlatformOS
|
|
8
|
+
/**
|
|
9
|
+
* Returns the value for the current platform.
|
|
10
|
+
* On macOS, returns `macos` when provided and falls back to `ios` otherwise.
|
|
11
|
+
*/
|
|
12
|
+
select<IOS, Android>(values: { ios: IOS; android: Android }): IOS | Android
|
|
13
|
+
select<IOS, Android, MacOS>(values: { ios: IOS; android: Android; macos: MacOS }): IOS | Android | MacOS
|
|
14
|
+
select<IOS, Android, MacOS>(values: { ios: IOS; android: Android; macos?: MacOS }): IOS | Android | MacOS
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function readCoreOS(): PlatformOS {
|
|
18
|
+
const value: string = CorePlatform.OS
|
|
19
|
+
if (value === 'macos') return 'macos'
|
|
20
|
+
if (value === 'android') return 'android'
|
|
21
|
+
return 'ios'
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function selectPlatform<IOS, Android>(values: { ios: IOS; android: Android }): IOS | Android
|
|
25
|
+
function selectPlatform<IOS, Android, MacOS>(values: { ios: IOS; android: Android; macos: MacOS }): IOS | Android | MacOS
|
|
26
|
+
function selectPlatform<IOS, Android, MacOS>(values: { ios: IOS; android: Android; macos?: MacOS }): IOS | Android | MacOS
|
|
27
|
+
function selectPlatform<IOS, Android, MacOS>(values: { ios: IOS; android: Android; macos?: MacOS }): IOS | Android | MacOS {
|
|
28
|
+
const os = readCoreOS()
|
|
29
|
+
if (os === 'macos') {
|
|
30
|
+
if (values.macos !== undefined) {
|
|
31
|
+
return values.macos
|
|
32
|
+
}
|
|
33
|
+
return values.ios
|
|
34
|
+
}
|
|
35
|
+
return CorePlatform.select(values)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export const Platform: MacOSPlatform = {
|
|
39
|
+
get OS(): PlatformOS {
|
|
40
|
+
return readCoreOS()
|
|
41
|
+
},
|
|
42
|
+
select: selectPlatform,
|
|
43
|
+
}
|
package/src/bin.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
import { spawnSync } from 'node:child_process'
|
|
3
|
+
import { fileURLToPath } from 'node:url'
|
|
4
|
+
|
|
5
|
+
if (process.versions.bun) {
|
|
6
|
+
await import('./cli.ts')
|
|
7
|
+
} else {
|
|
8
|
+
const result = spawnSync('bun', [fileURLToPath(import.meta.url), ...process.argv.slice(2)], {
|
|
9
|
+
stdio: 'inherit',
|
|
10
|
+
})
|
|
11
|
+
if (result.error) {
|
|
12
|
+
console.error('nitro-ui-macos requires Bun (https://bun.com/docs/installation).')
|
|
13
|
+
console.error('Install Bun and ensure `bun` is in PATH, then re-run this command.')
|
|
14
|
+
process.exitCode = 1
|
|
15
|
+
} else {
|
|
16
|
+
process.exitCode = result.status ?? 1
|
|
17
|
+
}
|
|
18
|
+
}
|