@bake-native/core 0.0.0 → 0.1.0-rc.0

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.
Files changed (143) hide show
  1. package/LICENSE +21 -0
  2. package/THIRD_PARTY_NOTICES.txt +548 -0
  3. package/bake-prelude.js +189 -0
  4. package/batch-contract.json +21 -0
  5. package/batch-wire.js +674 -0
  6. package/compat.json +64 -0
  7. package/controls.css +108 -0
  8. package/determinism.js +175 -0
  9. package/devtools.d.ts +13 -0
  10. package/devtools.js +73 -0
  11. package/dialogs.js +59 -0
  12. package/direct-style.js +105 -0
  13. package/direct-table.js +261 -0
  14. package/dist/bake.mjs +2211 -0
  15. package/dist/build-CMsvCcZ0.mjs +1 -0
  16. package/dist/build-CkLSZw06.mjs +5514 -0
  17. package/dist/build-tools-Dxyl6XAf.mjs +80 -0
  18. package/dist/client-Cm7o6dQd.mjs +17544 -0
  19. package/dist/compiler.mjs +4 -0
  20. package/dist/config-B1W8gfZY.mjs +12 -0
  21. package/dist/dev-Cskd8Hl4.mjs +986 -0
  22. package/dist/direct-report-Bdda-k_Y.mjs +153 -0
  23. package/dist/direct-report-Du44nNWl.mjs +1 -0
  24. package/dist/index.d.mts +176 -0
  25. package/dist/index.mjs +1 -0
  26. package/dist/intl-ROnAp2qO.mjs +75 -0
  27. package/dist/jiti-stub-CKcaShwE.mjs +5 -0
  28. package/dist/native-views-BuzB9x5H.mjs +7849 -0
  29. package/dist/octane/package.json +5 -0
  30. package/dist/package-KkUSMoji.mjs +2784 -0
  31. package/dist/react/package.json +13 -0
  32. package/dist/rolldown-runtime-D3KUYPsf.mjs +12 -0
  33. package/dist/run-D2aPm54a.mjs +6632 -0
  34. package/dist/scope-8W2aIuQ9.mjs +262 -0
  35. package/dist/screens/BakeNativeScreen.native.ts +9 -0
  36. package/dist/screens/package.json +5 -0
  37. package/dom-exception.js +31 -0
  38. package/element-api.js +158 -0
  39. package/first-screen.js +30 -0
  40. package/fonts/Geist-Italic-Variable.ttf +0 -0
  41. package/fonts/Geist-Variable.ttf +0 -0
  42. package/fonts/GeistMono-Italic-Variable.ttf +0 -0
  43. package/fonts/GeistMono-Variable.ttf +0 -0
  44. package/fonts/OFL.txt +93 -0
  45. package/fonts/README.md +27 -0
  46. package/fonts/geist-italic.css +8 -0
  47. package/fonts/geist-mono-italic.css +8 -0
  48. package/fonts/geist-mono.css +8 -0
  49. package/fonts/geist.css +8 -0
  50. package/header-icons.json +53 -0
  51. package/host-runtime.js +508 -0
  52. package/image-props.js +17 -0
  53. package/index.d.ts +8 -0
  54. package/index.js +7 -0
  55. package/licenses/Apache-2.0.txt +73 -0
  56. package/locale-entry.d.ts +1 -0
  57. package/locale-entry.js +1 -0
  58. package/locale.d.ts +28 -0
  59. package/locale.js +124 -0
  60. package/markup-support.js +87 -0
  61. package/media-element.js +115 -0
  62. package/native-args-entry.js +2 -0
  63. package/native-args.d.ts +7 -0
  64. package/native-args.js +155 -0
  65. package/native-entry.js +1 -0
  66. package/native-globals.d.ts +156 -0
  67. package/native-scenarios.d.ts +17 -0
  68. package/native-scenarios.js +46 -0
  69. package/native-support.json +349 -0
  70. package/native.d.ts +52 -0
  71. package/native.js +237 -0
  72. package/package.json +142 -4
  73. package/page-elements.js +123 -0
  74. package/runtime-provides.json +412 -0
  75. package/safe-area.d.ts +1 -0
  76. package/safe-area.js +44 -0
  77. package/swift-ui/modifiers.js +164 -0
  78. package/tab-icons.js +62 -0
  79. package/templates/create/tabs/AGENTS.md +22 -0
  80. package/templates/create/tabs/README.md +43 -0
  81. package/templates/create/tabs/_gitignore +13 -0
  82. package/templates/create/tabs/android/app/build.gradle.kts +79 -0
  83. package/templates/create/tabs/android/app/src/main/AndroidManifest.xml +39 -0
  84. package/templates/create/tabs/android/app/src/main/kotlin/MainActivity.kt +35 -0
  85. package/templates/create/tabs/android/app/src/main/res/values/themes.xml +8 -0
  86. package/templates/create/tabs/android/build.gradle.kts +5 -0
  87. package/templates/create/tabs/android/gradle/wrapper/gradle-wrapper.jar +0 -0
  88. package/templates/create/tabs/android/gradle/wrapper/gradle-wrapper.properties +9 -0
  89. package/templates/create/tabs/android/gradle.properties +3 -0
  90. package/templates/create/tabs/android/gradlew +248 -0
  91. package/templates/create/tabs/android/settings.gradle.kts +47 -0
  92. package/templates/create/tabs/bake.config.ts +10 -0
  93. package/templates/create/tabs/ios/App/App.swift +30 -0
  94. package/templates/create/tabs/ios/build.sh +23 -0
  95. package/templates/create/tabs/ios/project.yml +57 -0
  96. package/templates/create/tabs/macos/Package.swift +24 -0
  97. package/templates/create/tabs/macos/Sources/__SWIFT_NAME__/App.swift +146 -0
  98. package/templates/create/tabs/macos/build.sh +4 -0
  99. package/templates/create/tabs/package.json +23 -0
  100. package/templates/create/tabs/pnpm-workspace.yaml +6 -0
  101. package/templates/create/tabs/src/App.tsrx +92 -0
  102. package/templates/create/tabs/src/App.tsx +67 -0
  103. package/templates/create/tabs/src/styles.css +32 -0
  104. package/templates/create/tabs/tsconfig.json +5 -0
  105. package/templates/create/tabs/windows/Cargo.toml +29 -0
  106. package/templates/create/tabs/windows/build.rs +9 -0
  107. package/templates/create/tabs/windows/src/main.rs +52 -0
  108. package/templates/create/tabs/windows/src/shell.rs +316 -0
  109. package/templates/module/__NAME__.kt +20 -0
  110. package/templates/module/__NAME__.native.ts +24 -0
  111. package/templates/module/__NAME__.swift +25 -0
  112. package/templates/module/__NAME__.web.ts +13 -0
  113. package/templates/module/__NAME__Test.kt +26 -0
  114. package/templates/module/__NAME__Tests.swift +25 -0
  115. package/templates/module/__SNAKE__.rs +43 -0
  116. package/text.d.ts +20 -0
  117. package/text.js +100 -0
  118. package/transform-entry.js +1 -0
  119. package/transform.d.ts +15 -0
  120. package/transform.js +98 -0
  121. package/tsconfig.native.json +16 -0
  122. package/ui/scope.js +103 -0
  123. package/ui/swift.js +106 -0
  124. package/ui/ui.css +272 -0
  125. package/view-ref-writer.js +268 -0
  126. package/view-ref.d.ts +26 -0
  127. package/view-ref.js +85 -0
  128. package/views/Video.native.ts +68 -0
  129. package/views/generated/VideoViewAndroid.h +68 -0
  130. package/views/generated/VideoViewJSI.h +94 -0
  131. package/views/generated/VideoViewSpec.kt +113 -0
  132. package/views/generated/apple/VideoViewJSI/VideoViewJSIApple.cpp +40 -0
  133. package/views/generated/apple/VideoViewJSI/include/VideoViewJSIApple.h +28 -0
  134. package/views/generated/apple/VideoViewSpec/VideoViewInterop.swift +39 -0
  135. package/views/generated/apple/VideoViewSpec/VideoViewSpec.swift +186 -0
  136. package/views/generated/video_view_spec.rs +189 -0
  137. package/views.d.ts +24 -0
  138. package/views.js +45 -0
  139. package/virtual-window.js +35 -0
  140. package/visibility.js +75 -0
  141. package/web-crypto.js +84 -0
  142. package/web-fetch.js +1071 -0
  143. package/README.md +0 -3
@@ -0,0 +1,30 @@
1
+ import BakeNativeAppModules
2
+ import BakeNativeKit
3
+ import UIKit
4
+
5
+ @main
6
+ final class AppDelegate: UIResponder, UIApplicationDelegate {
7
+ func application(_ application: UIApplication,
8
+ configurationForConnecting session: UISceneSession,
9
+ options: UIScene.ConnectionOptions) -> UISceneConfiguration {
10
+ UISceneConfiguration(name: "Default", sessionRole: session.role)
11
+ }
12
+ }
13
+
14
+ /// The whole app: a navigation controller (Header from __RENDERER_PACKAGE__/ui draws its bar) whose root screen is the
15
+ /// __RENDERER_NAME__ app. TabBar (__RENDERER_PACKAGE__/ui) puts the tab bar under it.
16
+ final class SceneDelegate: UIResponder, UIWindowSceneDelegate {
17
+ var window: UIWindow?
18
+
19
+ func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options: UIScene.ConnectionOptions) {
20
+ guard let scene = scene as? UIWindowScene,
21
+ let url = Bundle.main.url(forResource: "Bundle", withExtension: nil) else { return }
22
+ // The native modules the bundle calls, from the generated registration (ios/build.sh:
23
+ // BakeNativeAppModules): one registry, never looked up by name.
24
+ let screen = BakeNativeViewController(bundle: BakeNativeBundle(directory: url), modules: BakeNativeBundleModules.root())
25
+ let window = UIWindow(windowScene: scene)
26
+ window.rootViewController = UINavigationController(rootViewController: screen)
27
+ window.makeKeyAndVisible()
28
+ self.window = window
29
+ }
30
+ }
@@ -0,0 +1,23 @@
1
+ #!/bin/sh
2
+ # Builds the app for iOS (Hermes bytecode + the baked first screen) into ios/App/Bundle, and the
3
+ # registration of the first-party modules the bundle uses (Clipboard, Linking, Share) into
4
+ # .bake/native/ios, the BakeNativeAppModules package the app links. Run it from the project root
5
+ # (pnpm build:ios) before xcodegen / Xcode, and after every change.
6
+ set -eu
7
+ here="$(cd "$(dirname "$0")" && pwd)"
8
+ root="$(cd "$here/.." && pwd)"
9
+ cd "$root"
10
+ pnpm exec bake build --target ios --bake --viewport 393x852
11
+ # manifest.json requires.modules -> .bake/native/ios, against the BakeNative Swift package of
12
+ # ios/project.yml: __BAKENATIVE_SWIFT_FROM__.
13
+ pnpm exec bake native link --target ios__LINK_BAKENATIVE__
14
+ native_app="$root/dist/ios/native-app"
15
+ test -f "$native_app/settings.yml" || { echo "Set app in bake.config.ts for the iOS host." >&2; exit 1; }
16
+ rm -rf "$here/App/BakeNativeBrand.xcassets"
17
+ if [ -d "$native_app/BakeNativeBrand.xcassets" ]; then
18
+ cp -R "$native_app/BakeNativeBrand.xcassets" "$here/App/BakeNativeBrand.xcassets"
19
+ fi
20
+ rm -rf "$here/App/Bundle"
21
+ mkdir -p "$here/App/Bundle"
22
+ cp dist/ios/app.hbc dist/ios/app.css dist/ios/*.baked dist/ios/manifest.json dist/ios/THIRD_PARTY_NOTICES.txt dist/ios/THIRD_PARTY_NOTICES.json "$here/App/Bundle/"
23
+ echo "==> ios/App/Bundle ready. Next: cd ios && xcodegen generate && open __SWIFT_NAME__.xcodeproj"
@@ -0,0 +1,57 @@
1
+ # XcodeGen spec of the iOS app: one window whose content is the __RENDERER_NAME__ app (__APP_ENTRY__).
2
+ # sh ios/build.sh # bake build --target ios --bake → ios/App/Bundle
3
+ # cd ios && xcodegen generate && open __SWIFT_NAME__.xcodeproj
4
+ # The app depends on two local Swift packages:
5
+ # BakeNative (product BakeNativeKit): __BAKENATIVE_SWIFT_FROM__
6
+ # BakeNativeAppModules (../.bake/native/ios, written by ios/build.sh): the first-party modules
7
+ # (Clipboard, Linking, Share) the bundle uses and BakeNativeBundleModules.root(), which App.swift passes in.
8
+ name: __SWIFT_NAME__
9
+ include:
10
+ - path: ../dist/ios/native-app/settings.yml
11
+ relativePaths: false
12
+ settings:
13
+ base:
14
+ BAKENATIVE_DISPLAY_NAME: "__TITLE__"
15
+ options:
16
+ bundleIdPrefix: __APP_ID__
17
+ deploymentTarget:
18
+ iOS: "16.0"
19
+ packages:
20
+ BakeNative:
21
+ path: __BAKENATIVE_SWIFT__
22
+ BakeNativeAppModules:
23
+ path: ../.bake/native/ios
24
+ targets:
25
+ __SWIFT_NAME__:
26
+ type: application
27
+ templates: [BakeNativeBranding]
28
+ platform: iOS
29
+ sources:
30
+ - path: ../.bake/native/ios/BakeNativeBundleModules.swift
31
+ - path: App
32
+ excludes:
33
+ - Bundle
34
+ - Bundle/**
35
+ # The baked bundle (ios/build.sh), copied into the app as a folder.
36
+ - path: App/Bundle
37
+ type: folder
38
+ buildPhase: resources
39
+ dependencies:
40
+ - package: BakeNative
41
+ product: BakeNativeKit
42
+ - package: BakeNativeAppModules
43
+ info:
44
+ path: App/Info.plist
45
+ properties:
46
+ # ProMotion: without it an iPhone caps the display link at 60 Hz.
47
+ CADisableMinimumFrameDurationOnPhone: true
48
+ CFBundleDisplayName: $(BAKENATIVE_DISPLAY_NAME)
49
+ UIApplicationSceneManifest:
50
+ UIApplicationSupportsMultipleScenes: false
51
+ UISceneConfigurations:
52
+ UIWindowSceneSessionRoleApplication:
53
+ - UISceneConfigurationName: Default
54
+ UISceneDelegateClassName: $(PRODUCT_MODULE_NAME).SceneDelegate
55
+ settings:
56
+ base:
57
+ SWIFT_VERSION: "5.0"
@@ -0,0 +1,24 @@
1
+ // swift-tools-version: 6.0
2
+ import PackageDescription
3
+
4
+ // Run pnpm build:mac to build the bundle, generate BakeNativeAppModules and package the app.
5
+ // BakeNative: __BAKENATIVE_SWIFT_FROM__.
6
+ let package = Package(
7
+ name: "__SWIFT_NAME__",
8
+ platforms: [.macOS("14.0")],
9
+ dependencies: [
10
+ .package(name: "BakeNative", path: "__BAKENATIVE_SWIFT__"),
11
+ .package(name: "BakeNativeAppModules", path: "../.bake/native/mac"),
12
+ ],
13
+ targets: [
14
+ .executableTarget(
15
+ name: "__SWIFT_NAME__",
16
+ dependencies: [
17
+ .product(name: "BakeNativeAppKit", package: "BakeNative"),
18
+ // The modules the bundle uses and BakeNativeBundleModules.root(), which App.swift passes in.
19
+ .product(name: "BakeNativeAppModules", package: "BakeNativeAppModules"),
20
+ ],
21
+ resources: [.copy("Bundle")]
22
+ ),
23
+ ]
24
+ )
@@ -0,0 +1,146 @@
1
+ import AppKit
2
+ import BakeNativeAppKit
3
+ import BakeNativeAppModules
4
+ import SwiftUI
5
+
6
+ private struct Shell: Decodable {
7
+ struct Window: Decodable {
8
+ enum TitleBar: String, Decodable { case system, hidden }
9
+ let startVisible: Bool
10
+ let titleBar: TitleBar
11
+ let showInTaskbar: Bool
12
+ let alwaysOnTop: Bool
13
+ }
14
+ struct Tray: Decodable {
15
+ enum Click: String, Decodable { case menu, toggle }
16
+ enum Action: String, Decodable { case show, hide, toggle, quit, app }
17
+ struct Item: Decodable {
18
+ let label: String
19
+ let action: Action
20
+ let id: String?
21
+ }
22
+ let click: Click
23
+ let menu: [Item]
24
+ }
25
+ let width: CGFloat
26
+ let height: CGFloat
27
+ let name: String
28
+ let window: Window
29
+ let tray: Tray?
30
+ }
31
+
32
+ @main
33
+ enum __SWIFT_NAME__App {
34
+ @MainActor static func main() {
35
+ let app = NSApplication.shared
36
+ let shell = DesktopShell()
37
+ app.delegate = shell
38
+ withExtendedLifetime(shell) {
39
+ app.run()
40
+ }
41
+ }
42
+ }
43
+
44
+ @MainActor
45
+ final class DesktopShell: NSObject, NSApplicationDelegate, NSWindowDelegate {
46
+ private var window: NSWindow?
47
+ private var status: BakeNativeStatusItem?
48
+
49
+ func applicationDidFinishLaunching(_ notification: Notification) {
50
+ let packaged = Bundle.main.url(forResource: "__MAC_RESOURCE_BUNDLE__", withExtension: "bundle")
51
+ .flatMap(Bundle.init(url:))
52
+ guard let bundle = (packaged ?? Bundle.module).url(forResource: "Bundle", withExtension: nil) else {
53
+ fatalError("Missing the BakeNative bundle. Run pnpm build:mac.")
54
+ }
55
+ guard let config = Bundle.main.url(forResource: "Shell", withExtension: "json") else {
56
+ fatalError("Missing the desktop shell settings. Open the .app from pnpm build:mac.")
57
+ }
58
+ let shell: Shell
59
+ do {
60
+ shell = try JSONDecoder().decode(Shell.self, from: Data(contentsOf: config))
61
+ } catch {
62
+ fatalError("Could not load desktop shell settings: \(error)")
63
+ }
64
+ NSApp.setActivationPolicy(shell.window.showInTaskbar ? .regular : .accessory)
65
+ let window = NSWindow(
66
+ contentRect: NSRect(x: 0, y: 0, width: shell.width, height: shell.height),
67
+ styleMask: [.titled, .closable, .miniaturizable, .fullSizeContentView],
68
+ backing: .buffered, defer: false
69
+ )
70
+ window.title = shell.name
71
+ if shell.window.titleBar == .hidden {
72
+ window.titleVisibility = .hidden
73
+ window.titlebarAppearsTransparent = true
74
+ for kind: NSWindow.ButtonType in [.closeButton, .miniaturizeButton, .zoomButton] {
75
+ window.standardWindowButton(kind)?.isHidden = true
76
+ }
77
+ window.isMovableByWindowBackground = true
78
+ } else {
79
+ window.styleMask.remove(.fullSizeContentView)
80
+ }
81
+ window.setContentSize(NSSize(width: shell.width, height: shell.height))
82
+ window.level = shell.window.alwaysOnTop ? .floating : .normal
83
+ window.isReleasedWhenClosed = false
84
+ window.delegate = self
85
+ window.contentView = NSHostingView(rootView: BakeNativeSurface(
86
+ bundle: BakeNativeBundle(directory: bundle), modules: BakeNativeBundleModules.root()
87
+ ))
88
+ window.center()
89
+ self.window = window
90
+ if let tray = shell.tray {
91
+ let icon = Bundle.main.url(forResource: "AppIcon", withExtension: "icns").flatMap(NSImage.init(contentsOf:))
92
+ let items: [(String, @MainActor () -> Void)] = tray.menu.map { item in
93
+ let action: @MainActor () -> Void = { [weak self] in
94
+ self?.perform(item.action, id: item.id)
95
+ }
96
+ return (item.label, action)
97
+ }
98
+ let primary: (@MainActor () -> Void)?
99
+ if tray.click == .toggle {
100
+ primary = { [weak self] in self?.perform(.toggle) }
101
+ } else {
102
+ primary = nil
103
+ }
104
+ status = BakeNativeStatusItem(name: shell.name, image: icon, menuItems: items, primaryAction: primary)
105
+ }
106
+ if shell.window.startVisible { showWindow() }
107
+ }
108
+
109
+ private func showWindow() {
110
+ window?.deminiaturize(nil)
111
+ window?.makeKeyAndOrderFront(nil)
112
+ NSApp.activate()
113
+ }
114
+
115
+ func applicationShouldHandleReopen(_ sender: NSApplication, hasVisibleWindows: Bool) -> Bool {
116
+ showWindow()
117
+ return false
118
+ }
119
+
120
+ func windowShouldClose(_ sender: NSWindow) -> Bool {
121
+ if status != nil {
122
+ sender.orderOut(nil)
123
+ return false
124
+ }
125
+ return true
126
+ }
127
+
128
+ func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool { status == nil }
129
+
130
+ private func perform(_ action: Shell.Tray.Action, id: String? = nil) {
131
+ switch action {
132
+ case .show: showWindow()
133
+ case .hide: window?.orderOut(nil)
134
+ case .toggle:
135
+ if window?.isVisible == true && window?.isMiniaturized == false { window?.orderOut(nil) }
136
+ else { showWindow() }
137
+ case .quit: NSApp.terminate(nil)
138
+ case .app:
139
+ if let id { handleTrayAction(id) }
140
+ }
141
+ }
142
+
143
+ private func handleTrayAction(_ id: String) {
144
+ // Match your app.desktop.tray.menu IDs here. This runs even while the window is hidden.
145
+ }
146
+ }
@@ -0,0 +1,4 @@
1
+ #!/bin/sh
2
+ set -eu
3
+ cd "$(dirname "$0")/.."
4
+ pnpm exec bake package --standalone --target mac --viewport 640x480__LINK_BAKENATIVE__
@@ -0,0 +1,23 @@
1
+ {
2
+ "name": "__NAME__",
3
+ "private": true,
4
+ "version": "0.1.0",
5
+ "type": "module",
6
+ "packageManager": "pnpm@10.24.0",
7
+ "scripts": {
8
+ "build": "bake build --target web",
9
+ "build:web": "bake build --target web",
10
+ "build:windows": "bake package --standalone --target windows --viewport 640x480 --bakenative \"__BAKENATIVE__\"",
11
+ "build:ios": "sh ios/build.sh",
12
+ "build:mac": "sh macos/build.sh",
13
+ "build:android": "bake build --target android --bake"
14
+ },
15
+ "dependencies": {
16
+ "__RENDERER_PACKAGE__": "__RENDERER_VERSION__",
17
+ "__RENDERER__": "__FRAMEWORK_VERSION__"
18
+ },
19
+ "devDependencies": {
20
+ "@bake-native/core": "__BAKENATIVE_JS__",
21
+ "vite": "__VITE__"
22
+ }
23
+ }
@@ -0,0 +1,6 @@
1
+ # This app is its own pnpm workspace (it does not join a workspace in a parent directory).
2
+ packages:
3
+ - .
4
+
5
+ onlyBuiltDependencies:
6
+ - esbuild
@@ -0,0 +1,92 @@
1
+ import { useState } from 'octane';
2
+ import { Header, TabBar } from '@bake-native/octane/ui';
3
+
4
+ // Three CSS pages under the platform's tab bar (@bake-native/octane/ui TabBar): UITabBarController on
5
+ // iOS, a toolbar tab group on macOS, a Material navigation bar on Android, and the same CSS bar on
6
+ // the web and Windows. The selected tab is app state; the header shows its title.
7
+
8
+ const APP = '__TITLE__';
9
+
10
+ const TITLES: Record<string, string> = { home: 'Home', inbox: 'Inbox', settings: 'Settings' };
11
+
12
+ const TASKS = [
13
+ { id: 'read', title: 'Read src/App.tsrx', detail: 'This screen, its tabs and their pages' },
14
+ { id: 'style', title: 'Change src/styles.css', detail: 'One stylesheet for every target' },
15
+ { id: 'build', title: 'Build the app', detail: 'Use the build command for your target in README.md' },
16
+ ];
17
+
18
+ const MESSAGES = [
19
+ { id: 1, from: 'Ada', subject: 'Welcome aboard' },
20
+ { id: 2, from: 'Grace', subject: 'Notes from the design review' },
21
+ { id: 3, from: 'Linus', subject: 'Your build finished' },
22
+ { id: 4, from: 'Margaret', subject: 'Launch checklist' },
23
+ ];
24
+
25
+ export function App() @{
26
+ const [tab, setTab] = useState('home');
27
+ const [done, setDone] = useState<string[]>([]);
28
+ const [read, setRead] = useState<number[]>([]);
29
+ const [compact, setCompact] = useState(false);
30
+ const unread = MESSAGES.length - read.length;
31
+ const tabs = [
32
+ { id: 'home', title: 'Home', icon: 'home' },
33
+ { id: 'inbox', title: 'Inbox', icon: 'inbox', badge: unread > 0 ? unread : undefined },
34
+ { id: 'settings', title: 'Settings', icon: 'settings' },
35
+ ];
36
+ const toggleTask = (id: string) => setDone(done.includes(id) ? done.filter((d) => d !== id) : [...done, id]);
37
+ const markRead = (id: number) => setRead(read.includes(id) ? read : [...read, id]);
38
+
39
+ <>
40
+ <Header title={TITLES[tab]} largeTitle />
41
+ <div class={compact ? 'page compact' : 'page'}>
42
+ @if (tab === 'home') {
43
+ <>
44
+ <div class="card">
45
+ <div class="name">{'Welcome to ' + APP}</div>
46
+ <div class="sub">{done.length + ' of ' + TASKS.length + ' done'}</div>
47
+ </div>
48
+ @for (const task of TASKS; key task.id) {
49
+ <div class={done.includes(task.id) ? 'row done' : 'row'} onClick={() => toggleTask(task.id)}>
50
+ <div class="check">{done.includes(task.id) ? '✓' : ''}</div>
51
+ <div>
52
+ <div class="name">{task.title}</div>
53
+ <div class="sub">{task.detail}</div>
54
+ </div>
55
+ </div>
56
+ }
57
+ </>
58
+ } @else if (tab === 'inbox') {
59
+ <>
60
+ <div class="actions">
61
+ <button onClick={() => setRead(MESSAGES.map((m) => m.id))}>Mark all read</button>
62
+ <button onClick={() => setRead([])}>Reset</button>
63
+ </div>
64
+ @for (const m of MESSAGES; key m.id) {
65
+ <div class={read.includes(m.id) ? 'row' : 'row unread'} onClick={() => markRead(m.id)}>
66
+ <div class="avatar">{m.from[0]}</div>
67
+ <div>
68
+ <div class="name">{m.from}</div>
69
+ <div class="sub">{m.subject}</div>
70
+ </div>
71
+ </div>
72
+ }
73
+ </>
74
+ } @else {
75
+ <>
76
+ <div class="row" onClick={() => setCompact(!compact)}>
77
+ <div class="name grow">Compact rows</div>
78
+ <div class={compact ? 'switch on' : 'switch'}>
79
+ <div class="knob"></div>
80
+ </div>
81
+ </div>
82
+ <div class="card">
83
+ <div class="avatar big">{APP[0]}</div>
84
+ <div class="name">{APP}</div>
85
+ <div class="sub">{unread + ' unread, ' + done.length + ' tasks done'}</div>
86
+ </div>
87
+ </>
88
+ }
89
+ </div>
90
+ <TabBar tabs={tabs} selected={tab} tintColor="#0f766e" onSelect={(id: string) => setTab(id)} />
91
+ </>
92
+ }
@@ -0,0 +1,67 @@
1
+ import { useState } from 'react';
2
+ import { Pressable, Text, View } from '@bake-native/react';
3
+ import { Header, TabBar, type Tab } from '@bake-native/react/ui';
4
+
5
+ const APP = '__TITLE__';
6
+ const tabs: Tab[] = [
7
+ { id: 'home', title: 'Home', icon: 'home' },
8
+ { id: 'inbox', title: 'Inbox', icon: 'inbox' },
9
+ { id: 'settings', title: 'Settings', icon: 'settings' },
10
+ ];
11
+ const tasks = [
12
+ 'Read src/App.tsx',
13
+ 'Change src/styles.css',
14
+ 'Use the build command for your target in README.md',
15
+ ];
16
+ // A View lays out its children in a column, like React Native's, and a className does not change
17
+ // that: the direction goes in its style. The rest of a row (padding, background) is in .row.
18
+ const row = { flexDirection: 'row' } as const;
19
+
20
+ export default function App() {
21
+ const [tab, setTab] = useState('home');
22
+ const [done, setDone] = useState<string[]>([]);
23
+ const [unread, setUnread] = useState(true);
24
+ const title = tabs.find((item) => item.id === tab)?.title ?? 'Home';
25
+
26
+ return (
27
+ <>
28
+ <Header title={title} largeTitle />
29
+ <View className="page">
30
+ {tab === 'home' && (
31
+ <>
32
+ <View className="card">
33
+ <Text className="name">Welcome to {APP}</Text>
34
+ <Text className="sub">{done.length} of {tasks.length} done</Text>
35
+ </View>
36
+ {tasks.map((task) => (
37
+ <Pressable key={task} onPress={() => setDone((items) =>
38
+ items.includes(task) ? items.filter((item) => item !== task) : [...items, task]
39
+ )}>
40
+ <View className="row" style={row}>
41
+ <Text>{done.includes(task) ? '✓ ' : ''}{task}</Text>
42
+ </View>
43
+ </Pressable>
44
+ ))}
45
+ </>
46
+ )}
47
+ {tab === 'inbox' && (
48
+ <Pressable onPress={() => setUnread(false)}>
49
+ <View className="row" style={row}>
50
+ <View className="grow">
51
+ <Text className="name">Welcome aboard</Text>
52
+ <Text className="sub">{unread ? 'Tap to mark as read' : 'Read'}</Text>
53
+ </View>
54
+ </View>
55
+ </Pressable>
56
+ )}
57
+ {tab === 'settings' && (
58
+ <View className="card">
59
+ <Text className="name">{APP}</Text>
60
+ <Text className="sub">{unread ? '1 unread' : 'Inbox up to date'}</Text>
61
+ </View>
62
+ )}
63
+ </View>
64
+ <TabBar tabs={tabs} selected={tab} tintColor="#0f766e" onSelect={setTab} />
65
+ </>
66
+ );
67
+ }
@@ -0,0 +1,32 @@
1
+ :root { color-scheme: light dark; }
2
+ body { margin: 0; font-family: system-ui, sans-serif; background: #f2f2f7; color: #1c1c1e; }
3
+
4
+ .page { display: flex; flex-direction: column; }
5
+ .row { display: flex; align-items: center; gap: 12px; padding: 14px 16px; background: white; border-bottom: 1px solid #e5e5ea; }
6
+ .compact .row { padding: 8px 16px; }
7
+ .grow { flex: 1; }
8
+ .name { font-weight: 600; }
9
+ .sub { color: #8e8e93; font-size: 14px; }
10
+ .done .name { color: #8e8e93; }
11
+ .unread .name { color: #0f766e; }
12
+
13
+ .check { width: 24px; height: 24px; border-radius: 12px; border: 2px solid #0f766e; display: flex; align-items: center; justify-content: center; color: white; font-size: 14px; font-weight: 700; }
14
+ .done .check { background: #0f766e; }
15
+
16
+ .avatar { width: 40px; height: 40px; border-radius: 20px; display: flex; align-items: center; justify-content: center; color: white; font-weight: 700; background: #0f766e; }
17
+ .avatar.big { width: 72px; height: 72px; border-radius: 36px; font-size: 28px; }
18
+
19
+ .card { margin: 16px; padding: 24px; border-radius: 16px; background: white; display: flex; flex-direction: column; align-items: center; gap: 8px; }
20
+ .actions { display: flex; gap: 8px; padding: 12px 16px; }
21
+ .actions button { flex: 1; }
22
+
23
+ .switch { width: 44px; height: 26px; border-radius: 13px; background: #d1d1d6; display: flex; align-items: center; padding: 2px; box-sizing: border-box; }
24
+ .switch.on { background: #0f766e; justify-content: flex-end; }
25
+ .knob { width: 22px; height: 22px; border-radius: 11px; background: white; }
26
+
27
+ @media (prefers-color-scheme: dark) {
28
+ body { background: #1c1c1e; color: #f2f2f7; }
29
+ .row, .card { background: #2c2c2e; border-bottom-color: rgba(255, 255, 255, 0.1); }
30
+ .sub { color: #98989f; }
31
+ .switch { background: #48484a; }
32
+ }
@@ -0,0 +1,5 @@
1
+ {
2
+ "extends": "@bake-native/react/tsconfig.native.json",
3
+ "compilerOptions": { "strict": true },
4
+ "include": ["src", "bake.config.ts"]
5
+ }
@@ -0,0 +1,29 @@
1
+ [package]
2
+ name = "__NAME__"
3
+ version = "0.1.0"
4
+ edition = "2024"
5
+ publish = false
6
+
7
+ [[bin]]
8
+ name = "__SWIFT_NAME__"
9
+ path = "src/main.rs"
10
+
11
+ [dependencies]
12
+ bake-host-windows = { path = "__BAKENATIVE__/native/rust/crates/bake-host-windows", features = ["hermes-dlopen"] }
13
+ bakenative-app-modules = { path = "../.bake/native/windows" }
14
+ serde = { version = "1", features = ["derive"] }
15
+ serde_json = "1"
16
+ windows = { version = "=0.62.2", features = [
17
+ "Win32_Foundation",
18
+ "Win32_System_Com",
19
+ "Win32_System_LibraryLoader",
20
+ "Win32_UI_HiDpi",
21
+ "Win32_UI_Shell",
22
+ "Win32_UI_WindowsAndMessaging",
23
+ ] }
24
+
25
+ [build-dependencies]
26
+ embed-resource = "3"
27
+
28
+ [patch.crates-io]
29
+ taffy = { path = "__BAKENATIVE__/native/rust/vendor/taffy" }
@@ -0,0 +1,9 @@
1
+ fn main() {
2
+ println!("cargo:rerun-if-env-changed=BAKE_DESKTOP_RC");
3
+ println!("cargo:rerun-if-env-changed=BAKE_DESKTOP_CONFIG");
4
+ println!("cargo:rustc-link-arg=/MANIFEST:NO");
5
+ let rc = std::env::var_os("BAKE_DESKTOP_RC").expect("run pnpm build:windows");
6
+ embed_resource::compile(rc, embed_resource::NONE)
7
+ .manifest_required()
8
+ .expect("embed the app manifest and icon");
9
+ }
@@ -0,0 +1,52 @@
1
+ #![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
2
+
3
+ mod shell;
4
+
5
+ use std::time::Duration;
6
+
7
+ use bake_host_windows::{BakeNativeWindow, ViewOptions, enable_per_monitor_dpi, first_screen_frame, run_message_loop};
8
+ use windows::Win32::System::Com::{COINIT_APARTMENTTHREADED, CoInitializeEx};
9
+ use windows::Win32::UI::Shell::SetCurrentProcessExplicitAppUserModelID;
10
+ use windows::Win32::UI::WindowsAndMessaging::{MB_ICONERROR, MessageBoxW};
11
+ use windows::core::HSTRING;
12
+
13
+ fn main() {
14
+ let result = run();
15
+ bake_host_windows::shutdown(Duration::from_secs(10));
16
+ if let Err(error) = result {
17
+ let text = HSTRING::from(error.to_string());
18
+ unsafe { MessageBoxW(None, &text, windows::core::w!("BakeNative"), MB_ICONERROR) };
19
+ std::process::exit(1);
20
+ }
21
+ }
22
+
23
+ fn run() -> Result<(), Box<dyn std::error::Error>> {
24
+ let config: shell::Config = serde_json::from_str(include_str!(env!("BAKE_DESKTOP_CONFIG")))?;
25
+ unsafe {
26
+ CoInitializeEx(None, COINIT_APARTMENTTHREADED).ok()?;
27
+ SetCurrentProcessExplicitAppUserModelID(&HSTRING::from(&config.app_id))?;
28
+ }
29
+ enable_per_monitor_dpi();
30
+
31
+ let bundle = std::env::current_exe()?.with_file_name("bundle");
32
+ let mut options = ViewOptions::new(bundle.join("app.hbc"));
33
+ options.frame = first_screen_frame(&options.hbc);
34
+ for module in bakenative_app_modules::modules()
35
+ .into_iter()
36
+ .chain(bakenative_app_modules::bundle_modules::root())
37
+ {
38
+ options.modules.register_arc(module);
39
+ }
40
+ let window = BakeNativeWindow::new(&config.name, config.width, config.height, options)?;
41
+ let start_visible = config.window.start_visible;
42
+ let always_on_top = config.window.always_on_top;
43
+ let shell = shell::Shell::attach(window.hwnd, config)?;
44
+ if start_visible {
45
+ window.show();
46
+ shell::apply_topmost(window.hwnd, always_on_top)?;
47
+ }
48
+ run_message_loop();
49
+ drop(shell);
50
+ drop(window);
51
+ Ok(())
52
+ }