@geastack/apple 0.2.33 → 0.2.35
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/package.json +7 -7
- package/targets/ios/main/ios_display.mm +10 -0
- package/targets/macos/README.md +178 -6
- package/targets/macos/build-macos.sh +22 -3
- package/targets/macos/main/font_registry.h +8 -1
- package/targets/macos/main/font_registry.mm +42 -17
- package/targets/macos/main/macos_content_view.h +20 -0
- package/targets/macos/main/macos_main.mm +233 -34
- package/targets/macos/main/macos_microphone.mm +134 -0
- package/targets/macos/main/macos_native_shell.h +12 -0
- package/targets/macos/main/macos_native_shell.mm +102 -3
- package/targets/macos/main/macos_renderer.h +40 -0
- package/targets/macos/main/macos_renderer.mm +681 -12
- package/targets/macos/main/macos_windows.h +46 -0
- package/targets/macos/main/macos_windows.mm +704 -0
- package/targets/macos/window-config.mjs +9 -4
- package/targets/shared/apple_audio.mm +121 -2
- package/targets/shared/apple_audio_selftest.mm +74 -2
- package/targets/watchos/Info.plist.in +18 -0
- package/targets/watchos/README.md +116 -0
- package/targets/watchos/build-watchos.sh +255 -0
- package/targets/watchos/generate-xcode-project.mjs +434 -0
- package/targets/watchos/main/watchos_app.swift +140 -0
- package/targets/watchos/main/watchos_bridge.h +48 -0
- package/targets/watchos/main/watchos_host.mm +224 -0
- package/targets/watchos/main/watchos_platform.mm +95 -0
|
@@ -0,0 +1,434 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import crypto from 'node:crypto'
|
|
3
|
+
import fs from 'node:fs'
|
|
4
|
+
import path from 'node:path'
|
|
5
|
+
import { fileURLToPath } from 'node:url'
|
|
6
|
+
|
|
7
|
+
import { execFileSync } from 'node:child_process'
|
|
8
|
+
|
|
9
|
+
// Generates a single-target, watch-only watchOS app project (WKWatchOnly): a
|
|
10
|
+
// SwiftUI shell plus the gea runtime compiled from C++. It mirrors the iOS
|
|
11
|
+
// generator next door -- same source manifest, same generated program -- but
|
|
12
|
+
// renders through the framebuffer only, since watchOS has no UIView tree.
|
|
13
|
+
const scriptDir = path.dirname(fileURLToPath(import.meta.url))
|
|
14
|
+
const projectDir = process.cwd()
|
|
15
|
+
const geaCli = process.env.GEA_CLI_BIN || path.join(scriptDir, '../../node_modules/@geastack/cli/bin/gea.mjs')
|
|
16
|
+
function gea(args) {
|
|
17
|
+
return execFileSync(process.execPath, [geaCli, ...args], { encoding: 'utf8', stdio: ['ignore', 'pipe', 'inherit'] })
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const args = process.argv.slice(2)
|
|
21
|
+
|
|
22
|
+
function opt(name) {
|
|
23
|
+
const i = args.indexOf(name)
|
|
24
|
+
return i >= 0 ? args[i + 1] : ''
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function fail(message) {
|
|
28
|
+
process.stderr.write(`${message}\n`)
|
|
29
|
+
process.exit(1)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const appId = opt('--app-id')
|
|
33
|
+
const appName = opt('--app-name')
|
|
34
|
+
const displayName = opt('--display-name') || appName
|
|
35
|
+
const bundleId = opt('--bundle-id')
|
|
36
|
+
const cssDevicePixelRatio = Number(opt('--css-device-pixel-ratio') || 1.5)
|
|
37
|
+
const generatedDir = path.resolve(opt('--generated-dir'))
|
|
38
|
+
const projectPath = path.resolve(opt('--project-path'))
|
|
39
|
+
|
|
40
|
+
if (!appId || !appName || !bundleId || !generatedDir || !projectPath || !(cssDevicePixelRatio > 0)) {
|
|
41
|
+
fail('usage: generate-xcode-project.mjs --app-id <id> --app-name <name> [--display-name <name>] --bundle-id <id> [--css-device-pixel-ratio <r>] --generated-dir <path> --project-path <path> (run from the app directory)')
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const watchDir = scriptDir
|
|
45
|
+
const iosMainDir = path.join(scriptDir, '../ios/main')
|
|
46
|
+
const geaCore = process.env.GEA_CORE || ''
|
|
47
|
+
if (!geaCore) fail('GEA_CORE is not set: run this generator through build-watchos.sh, which resolves @geastack/core for it.')
|
|
48
|
+
const plistOut = path.join(projectPath, 'Info.plist')
|
|
49
|
+
let appMeta
|
|
50
|
+
try {
|
|
51
|
+
appMeta = JSON.parse(gea(['apps', 'inspect', appId, '--json']))
|
|
52
|
+
} catch {
|
|
53
|
+
fail(`Unknown app id: ${appId}`)
|
|
54
|
+
}
|
|
55
|
+
const appRoot = appMeta.root
|
|
56
|
+
const appIconAssetsDir = path.join(generatedDir, 'Assets.xcassets')
|
|
57
|
+
|
|
58
|
+
// Same escape hatch as iOS: actool refuses a catalog when no installed
|
|
59
|
+
// simulator runtime matches the SDK build exactly.
|
|
60
|
+
let hasAppIcon = process.env.GEA_WATCHOS_SKIP_APP_ICON !== '1'
|
|
61
|
+
|
|
62
|
+
fs.rmSync(projectPath, { recursive: true, force: true })
|
|
63
|
+
fs.mkdirSync(path.join(projectPath, 'project.xcworkspace'), { recursive: true })
|
|
64
|
+
fs.mkdirSync(path.join(projectPath, 'xcshareddata/xcschemes'), { recursive: true })
|
|
65
|
+
|
|
66
|
+
// Many example apps declare no icon. A missing icon is not a reason to refuse
|
|
67
|
+
// the build: the app gets the system's default icon instead.
|
|
68
|
+
if (hasAppIcon) {
|
|
69
|
+
try {
|
|
70
|
+
gea(['apps', 'apple-icons', appId, '--platform', 'watchos', '--assets-dir', appIconAssetsDir])
|
|
71
|
+
} catch {
|
|
72
|
+
process.stderr.write(`No app icon for ${appId}; building with the default icon.\n`)
|
|
73
|
+
hasAppIcon = false
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const plistTemplate = fs.readFileSync(path.join(watchDir, 'Info.plist.in'), 'utf8')
|
|
78
|
+
fs.writeFileSync(
|
|
79
|
+
plistOut,
|
|
80
|
+
plistTemplate
|
|
81
|
+
.replaceAll('@APP_EXEC@', appName)
|
|
82
|
+
.replaceAll('@APP_NAME@', appName)
|
|
83
|
+
.replaceAll('@APP_DISPLAY_NAME@', displayName.replaceAll('&', '&').replaceAll('<', '<'))
|
|
84
|
+
.replaceAll('@BUNDLE_ID@', bundleId),
|
|
85
|
+
)
|
|
86
|
+
|
|
87
|
+
function id(label) {
|
|
88
|
+
return crypto.createHash('sha1').update(label).digest('hex').slice(0, 24).toUpperCase()
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function q(value) {
|
|
92
|
+
return `"${String(value).replaceAll('\\', '\\\\').replaceAll('"', '\\"')}"`
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function rel(file) {
|
|
96
|
+
return path.relative(projectDir, file).replaceAll(path.sep, '/')
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function source(file, kind = 'sourcecode.cpp.cpp') {
|
|
100
|
+
return { file: path.resolve(file), kind }
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function existing(entry) {
|
|
104
|
+
return fs.existsSync(entry.file)
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function readGeatscSources(dir) {
|
|
108
|
+
const sourceList = path.join(dir, 'geatsc-sources.txt')
|
|
109
|
+
if (!fs.existsSync(sourceList)) return []
|
|
110
|
+
return fs.readFileSync(sourceList, 'utf8')
|
|
111
|
+
.split(/\r?\n/)
|
|
112
|
+
.map((line) => line.trim())
|
|
113
|
+
.filter(Boolean)
|
|
114
|
+
.map((file) => source(file))
|
|
115
|
+
.filter(existing)
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function nativeSourceKind(file) {
|
|
119
|
+
if (/\.mm$/i.test(file)) return 'sourcecode.cpp.objcpp'
|
|
120
|
+
if (/\.m$/i.test(file)) return 'sourcecode.c.objc'
|
|
121
|
+
if (/\.c$/i.test(file)) return 'sourcecode.c.c'
|
|
122
|
+
return 'sourcecode.cpp.cpp'
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// An app's own native code for this target lives in <app>/watchos, the way
|
|
126
|
+
// iOS-only code lives in <app>/ios.
|
|
127
|
+
function findAppNativeSources() {
|
|
128
|
+
const dir = path.join(appRoot, 'watchos')
|
|
129
|
+
if (!fs.existsSync(dir)) return []
|
|
130
|
+
const out = []
|
|
131
|
+
const visit = (current) => {
|
|
132
|
+
for (const entry of fs.readdirSync(current, { withFileTypes: true })) {
|
|
133
|
+
const file = path.join(current, entry.name)
|
|
134
|
+
if (entry.isDirectory()) visit(file)
|
|
135
|
+
else if (entry.isFile() && /\.(c|cc|cpp|m|mm)$/i.test(entry.name)) out.push(source(file, nativeSourceKind(file)))
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
visit(dir)
|
|
139
|
+
return out.sort((a, b) => a.file.localeCompare(b.file))
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
const sources = [
|
|
143
|
+
source(path.join(watchDir, 'main/watchos_app.swift'), 'sourcecode.swift'),
|
|
144
|
+
source(path.join(watchDir, 'main/watchos_host.mm'), 'sourcecode.cpp.objcpp'),
|
|
145
|
+
// Camera-less camera backend, plus battery and haptics through WatchKit.
|
|
146
|
+
source(path.join(watchDir, 'main/watchos_platform.mm'), 'sourcecode.cpp.objcpp'),
|
|
147
|
+
// Platform backends shared verbatim with iOS: the RGBA8888 framebuffer, the
|
|
148
|
+
// frame clock, allocator, touch state
|
|
149
|
+
// plus CoreMotion, and the AVAudioEngine audio backend.
|
|
150
|
+
source(path.join(iosMainDir, 'ios_display.mm'), 'sourcecode.cpp.objcpp'),
|
|
151
|
+
source(path.join(iosMainDir, 'ios_timers.mm'), 'sourcecode.cpp.objcpp'),
|
|
152
|
+
source(path.join(iosMainDir, 'ios_memory.cpp')),
|
|
153
|
+
source(path.join(iosMainDir, 'ios_sensors.mm'), 'sourcecode.cpp.objcpp'),
|
|
154
|
+
source(path.join(watchDir, '../shared/apple_audio.mm'), 'sourcecode.cpp.objcpp'),
|
|
155
|
+
...findAppNativeSources(),
|
|
156
|
+
// Framework sources from @geastack/core/gea_sources.sh, curated by
|
|
157
|
+
// build-watchos.sh (no services or single-app runtime shell).
|
|
158
|
+
...(process.env.GEA_FW_C_SOURCES || '').split('\n').filter(Boolean).map((f) => source(f, 'sourcecode.c.c')),
|
|
159
|
+
...(process.env.GEA_FW_CXX_SOURCES || '').split('\n').filter(Boolean).map((f) => source(f)),
|
|
160
|
+
// Application::init/frame, which call the __gea_top_level geatsc emitted.
|
|
161
|
+
source(path.join(geaCore, 'gea_app_entry.cpp')),
|
|
162
|
+
...readGeatscSources(generatedDir),
|
|
163
|
+
source(path.join(generatedDir, 'gea_embedded_font_generated.cpp')),
|
|
164
|
+
source(path.join(generatedDir, 'gea_embedded_assets_generated.cpp')),
|
|
165
|
+
].filter(existing)
|
|
166
|
+
const hasGeneratedFonts = sources.some((entry) => path.basename(entry.file) === 'gea_embedded_font_generated.cpp')
|
|
167
|
+
|
|
168
|
+
const resources = hasAppIcon ? [{ file: appIconAssetsDir, kind: 'folder.assetcatalog' }] : []
|
|
169
|
+
const frameworks = [
|
|
170
|
+
'SwiftUI.framework',
|
|
171
|
+
'WatchKit.framework',
|
|
172
|
+
'UIKit.framework',
|
|
173
|
+
'CoreGraphics.framework',
|
|
174
|
+
'CoreMotion.framework',
|
|
175
|
+
'AVFoundation.framework',
|
|
176
|
+
'Foundation.framework',
|
|
177
|
+
]
|
|
178
|
+
|
|
179
|
+
// The UI test lives under test/, which the npm package leaves out, so only a
|
|
180
|
+
// checkout of this repo gets the target (as with the iOS rubber-band test).
|
|
181
|
+
const uiTestSource = source(path.join(watchDir, 'test/GeaWatchCounterUITests.swift'), 'sourcecode.swift')
|
|
182
|
+
const hasUiTests = existing(uiTestSource)
|
|
183
|
+
|
|
184
|
+
const productId = id('product')
|
|
185
|
+
const targetId = id('target')
|
|
186
|
+
const projectId = id('project')
|
|
187
|
+
const mainGroupId = id('group-main')
|
|
188
|
+
const productGroupId = id('group-products')
|
|
189
|
+
const sourcesPhaseId = id('phase-sources')
|
|
190
|
+
const frameworksPhaseId = id('phase-frameworks')
|
|
191
|
+
const resourcesPhaseId = id('phase-resources')
|
|
192
|
+
const configListProjectId = id('configs-project')
|
|
193
|
+
const configListTargetId = id('configs-target')
|
|
194
|
+
const debugProjectId = id('debug-project')
|
|
195
|
+
const releaseProjectId = id('release-project')
|
|
196
|
+
const debugTargetId = id('debug-target')
|
|
197
|
+
const releaseTargetId = id('release-target')
|
|
198
|
+
const uiTestProductId = id('product-ui-tests')
|
|
199
|
+
const uiTestTargetId = id('target-ui-tests')
|
|
200
|
+
const uiTestSourcesPhaseId = id('phase-ui-test-sources')
|
|
201
|
+
const uiTestFrameworksPhaseId = id('phase-ui-test-frameworks')
|
|
202
|
+
const uiTestConfigListId = id('configs-ui-test-target')
|
|
203
|
+
const uiTestDebugId = id('debug-ui-test-target')
|
|
204
|
+
const uiTestReleaseId = id('release-ui-test-target')
|
|
205
|
+
const uiTestDependencyId = id('dependency-ui-test-app')
|
|
206
|
+
const uiTestProxyId = id('proxy-ui-test-app')
|
|
207
|
+
|
|
208
|
+
const fileRefs = []
|
|
209
|
+
const buildFiles = []
|
|
210
|
+
const ref = (file) => `${id(`file:${rel(file)}`)} /* ${path.basename(file)} */`
|
|
211
|
+
const buildRef = (file, phase) => `${id(`build:${rel(file)}`)} /* ${path.basename(file)} in ${phase} */`
|
|
212
|
+
const fwRef = (fw) => `${id(`file:${fw}`)} /* ${fw} */`
|
|
213
|
+
const fwBuildRef = (fw) => `${id(`build:${fw}`)} /* ${fw} in Frameworks */`
|
|
214
|
+
|
|
215
|
+
function addFile(entry, phase) {
|
|
216
|
+
const settings = entry.kind === 'sourcecode.cpp.objcpp' ? ' settings = {COMPILER_FLAGS = "-fobjc-exceptions"; };' : ''
|
|
217
|
+
fileRefs.push(`${ref(entry.file)} = {isa = PBXFileReference; lastKnownFileType = ${entry.kind}; path = ${q(entry.file)}; sourceTree = "<absolute>"; };`)
|
|
218
|
+
buildFiles.push(`${buildRef(entry.file, phase)} = {isa = PBXBuildFile; fileRef = ${ref(entry.file)};${settings} };`)
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
function addFramework(fw) {
|
|
222
|
+
fileRefs.push(`${fwRef(fw)} = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = ${fw}; path = System/Library/Frameworks/${fw}; sourceTree = SDKROOT; };`)
|
|
223
|
+
buildFiles.push(`${fwBuildRef(fw)} = {isa = PBXBuildFile; fileRef = ${fwRef(fw)}; };`)
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
for (const s of sources) addFile(s, 'Sources')
|
|
227
|
+
for (const r of resources) addFile(r, 'Resources')
|
|
228
|
+
for (const fw of frameworks) addFramework(fw)
|
|
229
|
+
if (hasUiTests) {
|
|
230
|
+
addFile(uiTestSource, 'Sources')
|
|
231
|
+
addFramework('XCTest.framework')
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
const includePaths = [
|
|
235
|
+
path.join(watchDir, 'main'),
|
|
236
|
+
iosMainDir,
|
|
237
|
+
generatedDir,
|
|
238
|
+
path.join(appRoot, 'watchos'),
|
|
239
|
+
...(process.env.GEA_FW_INCLUDE_DIRS || '').split('\n').filter(Boolean),
|
|
240
|
+
]
|
|
241
|
+
|
|
242
|
+
// Settings both targets share: a watch-only watchOS 10 bundle.
|
|
243
|
+
const watchSettings = `
|
|
244
|
+
SDKROOT = watchos;
|
|
245
|
+
SUPPORTED_PLATFORMS = "watchos watchsimulator";
|
|
246
|
+
SWIFT_VERSION = 5.0;
|
|
247
|
+
TARGETED_DEVICE_FAMILY = 4;
|
|
248
|
+
WATCHOS_DEPLOYMENT_TARGET = 10.0;`
|
|
249
|
+
|
|
250
|
+
function buildSettings(configuration) {
|
|
251
|
+
const preprocessorDefinitions = [
|
|
252
|
+
'GEA_EMBEDDED_GIF_C_API=1',
|
|
253
|
+
// No text field to host a native input in, and no room for a keyboard.
|
|
254
|
+
'GEA_EMBEDDED_ENABLE_NATIVE_TEXT_INPUT=0',
|
|
255
|
+
'GEA_EMBEDDED_ENABLE_VIRTUAL_KEYBOARD=0',
|
|
256
|
+
'GEA_CPP_USE_TO_CHARS_DOUBLE=0',
|
|
257
|
+
'GEA_CPP_USE_FROM_CHARS_DOUBLE=0',
|
|
258
|
+
// Full colour like iOS: pixel::native_t is RGBA8888 (1 == GEA_PIXEL_RGBA8888).
|
|
259
|
+
'GEA_EMBEDDED_PIXEL_FORMAT=1',
|
|
260
|
+
// The ratio watchos_host.mm lays the app out at; the font atlas was baked
|
|
261
|
+
// at the same one.
|
|
262
|
+
`GEA_EMBEDDED_CSS_LAYOUT_DEVICE_PIXEL_RATIO=${cssDevicePixelRatio}`,
|
|
263
|
+
...(hasGeneratedFonts ? ['GEA_EMBEDDED_HAS_GENERATED_FONTS=1'] : []),
|
|
264
|
+
]
|
|
265
|
+
return `{
|
|
266
|
+
ALWAYS_SEARCH_USER_PATHS = NO;${hasAppIcon ? `
|
|
267
|
+
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;` : ''}
|
|
268
|
+
CLANG_CXX_LANGUAGE_STANDARD = "c++20";
|
|
269
|
+
CLANG_CXX_LIBRARY = "libc++";
|
|
270
|
+
CLANG_ENABLE_MODULES = YES;
|
|
271
|
+
CLANG_ENABLE_OBJC_ARC = YES;
|
|
272
|
+
CODE_SIGN_STYLE = Automatic;
|
|
273
|
+
CURRENT_PROJECT_VERSION = 1;
|
|
274
|
+
DEFINES_MODULE = NO;
|
|
275
|
+
GCC_ENABLE_OBJC_EXCEPTIONS = YES;
|
|
276
|
+
GCC_PREPROCESSOR_DEFINITIONS = (${preprocessorDefinitions.map(q).join(', ')});
|
|
277
|
+
HEADER_SEARCH_PATHS = (${includePaths.map(q).join(', ')});
|
|
278
|
+
INFOPLIST_FILE = ${q(plistOut)};
|
|
279
|
+
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
|
|
280
|
+
ONLY_ACTIVE_ARCH = ${configuration === 'Debug' ? 'YES' : 'NO'};
|
|
281
|
+
PRODUCT_BUNDLE_IDENTIFIER = ${q(bundleId)};
|
|
282
|
+
PRODUCT_NAME = ${q(appName)};
|
|
283
|
+
SKIP_INSTALL = NO;
|
|
284
|
+
SWIFT_OBJC_BRIDGING_HEADER = ${q(path.join(watchDir, 'main/watchos_bridge.h'))};
|
|
285
|
+
SWIFT_OPTIMIZATION_LEVEL = ${configuration === 'Debug' ? '"-Onone"' : '"-O"'};${watchSettings}
|
|
286
|
+
}`
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
function uiTestBuildSettings(configuration) {
|
|
290
|
+
return `{
|
|
291
|
+
ALWAYS_SEARCH_USER_PATHS = NO;
|
|
292
|
+
CLANG_ENABLE_MODULES = YES;
|
|
293
|
+
CODE_SIGN_STYLE = Automatic;
|
|
294
|
+
GENERATE_INFOPLIST_FILE = YES;
|
|
295
|
+
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
|
|
296
|
+
ONLY_ACTIVE_ARCH = ${configuration === 'Debug' ? 'YES' : 'NO'};
|
|
297
|
+
PRODUCT_BUNDLE_IDENTIFIER = ${q(`${bundleId}.ui-tests`)};
|
|
298
|
+
PRODUCT_NAME = GeaWatchUITests;
|
|
299
|
+
TEST_TARGET_NAME = GeaWatch;${watchSettings}
|
|
300
|
+
}`
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
const appProduct = `${productId} /* ${appName}.app */`
|
|
304
|
+
const uiTestProduct = `${uiTestProductId} /* GeaWatchUITests.xctest */`
|
|
305
|
+
const mainGroupChildren = [
|
|
306
|
+
...sources.map((s) => ref(s.file)),
|
|
307
|
+
...resources.map((r) => ref(r.file)),
|
|
308
|
+
...frameworks.map(fwRef),
|
|
309
|
+
...(hasUiTests ? [ref(uiTestSource.file), fwRef('XCTest.framework')] : []),
|
|
310
|
+
`${productGroupId} /* Products */`,
|
|
311
|
+
]
|
|
312
|
+
const nativeTargets = [
|
|
313
|
+
`${targetId} = {isa = PBXNativeTarget; buildConfigurationList = ${configListTargetId}; buildPhases = (${sourcesPhaseId}, ${frameworksPhaseId}, ${resourcesPhaseId}); buildRules = (); dependencies = (); name = GeaWatch; productName = ${q(appName)}; productReference = ${appProduct}; productType = "com.apple.product-type.application"; };`,
|
|
314
|
+
...(hasUiTests ? [`${uiTestTargetId} = {isa = PBXNativeTarget; buildConfigurationList = ${uiTestConfigListId}; buildPhases = (${uiTestSourcesPhaseId}, ${uiTestFrameworksPhaseId}); buildRules = (); dependencies = (${uiTestDependencyId}); name = GeaWatchUITests; productName = GeaWatchUITests; productReference = ${uiTestProduct}; productType = "com.apple.product-type.bundle.ui-testing"; };`] : []),
|
|
315
|
+
]
|
|
316
|
+
const targetAttributes = `${targetId} = {CreatedOnToolsVersion = 16.0;};${hasUiTests ? ` ${uiTestTargetId} = {CreatedOnToolsVersion = 16.0; TestTargetID = ${targetId};};` : ''}`
|
|
317
|
+
|
|
318
|
+
const pbxproj = `// !$*UTF8*$!
|
|
319
|
+
{
|
|
320
|
+
archiveVersion = 1;
|
|
321
|
+
classes = {};
|
|
322
|
+
objectVersion = 56;
|
|
323
|
+
objects = {
|
|
324
|
+
|
|
325
|
+
/* Begin PBXBuildFile section */
|
|
326
|
+
${buildFiles.join('\n\t\t')}
|
|
327
|
+
/* End PBXBuildFile section */
|
|
328
|
+
${hasUiTests ? `
|
|
329
|
+
/* Begin PBXContainerItemProxy section */
|
|
330
|
+
${uiTestProxyId} = {isa = PBXContainerItemProxy; containerPortal = ${projectId} /* Project object */; proxyType = 1; remoteGlobalIDString = ${targetId}; remoteInfo = GeaWatch; };
|
|
331
|
+
/* End PBXContainerItemProxy section */
|
|
332
|
+
` : ''}
|
|
333
|
+
/* Begin PBXFileReference section */
|
|
334
|
+
${fileRefs.join('\n\t\t')}
|
|
335
|
+
${appProduct} = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = ${q(`${appName}.app`)}; sourceTree = BUILT_PRODUCTS_DIR; };${hasUiTests ? `
|
|
336
|
+
${uiTestProduct} = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = GeaWatchUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };` : ''}
|
|
337
|
+
/* End PBXFileReference section */
|
|
338
|
+
|
|
339
|
+
/* Begin PBXFrameworksBuildPhase section */
|
|
340
|
+
${frameworksPhaseId} = {isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = (${frameworks.map(fwBuildRef).join(', ')}); runOnlyForDeploymentPostprocessing = 0; };${hasUiTests ? `
|
|
341
|
+
${uiTestFrameworksPhaseId} = {isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = (${fwBuildRef('XCTest.framework')}); runOnlyForDeploymentPostprocessing = 0; };` : ''}
|
|
342
|
+
/* End PBXFrameworksBuildPhase section */
|
|
343
|
+
|
|
344
|
+
/* Begin PBXGroup section */
|
|
345
|
+
${mainGroupId} = {isa = PBXGroup; children = (${mainGroupChildren.join(', ')}); sourceTree = "<group>"; };
|
|
346
|
+
${productGroupId} = {isa = PBXGroup; children = (${[appProduct, ...(hasUiTests ? [uiTestProduct] : [])].join(', ')}); name = Products; sourceTree = "<group>"; };
|
|
347
|
+
/* End PBXGroup section */
|
|
348
|
+
|
|
349
|
+
/* Begin PBXNativeTarget section */
|
|
350
|
+
${nativeTargets.join('\n\t\t')}
|
|
351
|
+
/* End PBXNativeTarget section */
|
|
352
|
+
|
|
353
|
+
/* Begin PBXProject section */
|
|
354
|
+
${projectId} = {isa = PBXProject; attributes = {LastUpgradeCheck = 1600; TargetAttributes = {${targetAttributes}};}; buildConfigurationList = ${configListProjectId}; compatibilityVersion = "Xcode 14.0"; developmentRegion = en; hasScannedForEncodings = 0; knownRegions = (en, Base); mainGroup = ${mainGroupId}; productRefGroup = ${productGroupId}; projectDirPath = ""; projectRoot = ""; targets = (${[targetId, ...(hasUiTests ? [uiTestTargetId] : [])].join(', ')}); };
|
|
355
|
+
/* End PBXProject section */
|
|
356
|
+
|
|
357
|
+
/* Begin PBXResourcesBuildPhase section */
|
|
358
|
+
${resourcesPhaseId} = {isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = (${resources.map((r) => buildRef(r.file, 'Resources')).join(', ')}); runOnlyForDeploymentPostprocessing = 0; };
|
|
359
|
+
/* End PBXResourcesBuildPhase section */
|
|
360
|
+
|
|
361
|
+
/* Begin PBXSourcesBuildPhase section */
|
|
362
|
+
${sourcesPhaseId} = {isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = (${sources.map((s) => buildRef(s.file, 'Sources')).join(', ')}); runOnlyForDeploymentPostprocessing = 0; };${hasUiTests ? `
|
|
363
|
+
${uiTestSourcesPhaseId} = {isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = (${buildRef(uiTestSource.file, 'Sources')}); runOnlyForDeploymentPostprocessing = 0; };` : ''}
|
|
364
|
+
/* End PBXSourcesBuildPhase section */
|
|
365
|
+
${hasUiTests ? `
|
|
366
|
+
/* Begin PBXTargetDependency section */
|
|
367
|
+
${uiTestDependencyId} = {isa = PBXTargetDependency; target = ${targetId} /* GeaWatch */; targetProxy = ${uiTestProxyId}; };
|
|
368
|
+
/* End PBXTargetDependency section */
|
|
369
|
+
` : ''}
|
|
370
|
+
/* Begin XCBuildConfiguration section */
|
|
371
|
+
${debugProjectId} = {isa = XCBuildConfiguration; buildSettings = {}; name = Debug; };
|
|
372
|
+
${releaseProjectId} = {isa = XCBuildConfiguration; buildSettings = {}; name = Release; };
|
|
373
|
+
${debugTargetId} = {isa = XCBuildConfiguration; buildSettings = ${buildSettings('Debug')}; name = Debug; };
|
|
374
|
+
${releaseTargetId} = {isa = XCBuildConfiguration; buildSettings = ${buildSettings('Release')}; name = Release; };${hasUiTests ? `
|
|
375
|
+
${uiTestDebugId} = {isa = XCBuildConfiguration; buildSettings = ${uiTestBuildSettings('Debug')}; name = Debug; };
|
|
376
|
+
${uiTestReleaseId} = {isa = XCBuildConfiguration; buildSettings = ${uiTestBuildSettings('Release')}; name = Release; };` : ''}
|
|
377
|
+
/* End XCBuildConfiguration section */
|
|
378
|
+
|
|
379
|
+
/* Begin XCConfigurationList section */
|
|
380
|
+
${configListProjectId} = {isa = XCConfigurationList; buildConfigurations = (${debugProjectId}, ${releaseProjectId}); defaultConfigurationIsVisible = 0; defaultConfigurationName = Debug; };
|
|
381
|
+
${configListTargetId} = {isa = XCConfigurationList; buildConfigurations = (${debugTargetId}, ${releaseTargetId}); defaultConfigurationIsVisible = 0; defaultConfigurationName = Debug; };${hasUiTests ? `
|
|
382
|
+
${uiTestConfigListId} = {isa = XCConfigurationList; buildConfigurations = (${uiTestDebugId}, ${uiTestReleaseId}); defaultConfigurationIsVisible = 0; defaultConfigurationName = Debug; };` : ''}
|
|
383
|
+
/* End XCConfigurationList section */
|
|
384
|
+
};
|
|
385
|
+
rootObject = ${projectId};
|
|
386
|
+
}
|
|
387
|
+
`
|
|
388
|
+
|
|
389
|
+
const buildable = `<BuildableReference BuildableIdentifier="primary" BlueprintIdentifier="${targetId}" BuildableName="${appName}.app" BlueprintName="GeaWatch" ReferencedContainer="container:GeaWatch.xcodeproj"/>`
|
|
390
|
+
const uiTestBuildable = `<BuildableReference BuildableIdentifier="primary" BlueprintIdentifier="${uiTestTargetId}" BuildableName="GeaWatchUITests.xctest" BlueprintName="GeaWatchUITests" ReferencedContainer="container:GeaWatch.xcodeproj"/>`
|
|
391
|
+
const scheme = `<?xml version="1.0" encoding="UTF-8"?>
|
|
392
|
+
<Scheme LastUpgradeVersion="1600" version="1.7">
|
|
393
|
+
<BuildAction parallelizeBuildables="YES" buildImplicitDependencies="YES" buildArchitectures="Automatic">
|
|
394
|
+
<BuildActionEntries>
|
|
395
|
+
<BuildActionEntry buildForTesting="YES" buildForRunning="YES" buildForProfiling="YES" buildForArchiving="YES" buildForAnalyzing="YES">
|
|
396
|
+
${buildable}
|
|
397
|
+
</BuildActionEntry>${hasUiTests ? `
|
|
398
|
+
<BuildActionEntry buildForTesting="YES" buildForRunning="NO" buildForProfiling="NO" buildForArchiving="NO" buildForAnalyzing="NO">
|
|
399
|
+
${uiTestBuildable}
|
|
400
|
+
</BuildActionEntry>` : ''}
|
|
401
|
+
</BuildActionEntries>
|
|
402
|
+
</BuildAction>${hasUiTests ? `
|
|
403
|
+
<TestAction buildConfiguration="Debug" selectedDebuggerIdentifier="Xcode.DebuggerFoundation.Debugger.LLDB" selectedLauncherIdentifier="Xcode.DebuggerFoundation.Launcher.LLDB" shouldUseLaunchSchemeArgsEnv="YES" shouldAutocreateTestPlan="YES">
|
|
404
|
+
<Testables>
|
|
405
|
+
<TestableReference skipped="NO">
|
|
406
|
+
${uiTestBuildable}
|
|
407
|
+
</TestableReference>
|
|
408
|
+
</Testables>
|
|
409
|
+
<MacroExpansion>
|
|
410
|
+
${buildable}
|
|
411
|
+
</MacroExpansion>
|
|
412
|
+
</TestAction>` : ''}
|
|
413
|
+
<LaunchAction buildConfiguration="Debug" selectedDebuggerIdentifier="Xcode.DebuggerFoundation.Debugger.LLDB" selectedLauncherIdentifier="Xcode.DebuggerFoundation.Launcher.LLDB" launchStyle="0" useCustomWorkingDirectory="NO" ignoresPersistentStateOnLaunch="NO" debugDocumentVersioning="YES" debugServiceExtension="internal" allowLocationSimulation="YES">
|
|
414
|
+
<BuildableProductRunnable runnableDebuggingMode="0">
|
|
415
|
+
${buildable}
|
|
416
|
+
</BuildableProductRunnable>
|
|
417
|
+
</LaunchAction>
|
|
418
|
+
<ProfileAction buildConfiguration="Release" shouldUseLaunchSchemeArgsEnv="YES" savedToolIdentifier="" useCustomWorkingDirectory="NO" debugDocumentVersioning="YES">
|
|
419
|
+
<BuildableProductRunnable runnableDebuggingMode="0">
|
|
420
|
+
${buildable}
|
|
421
|
+
</BuildableProductRunnable>
|
|
422
|
+
</ProfileAction>
|
|
423
|
+
<AnalyzeAction buildConfiguration="Debug"/>
|
|
424
|
+
<ArchiveAction buildConfiguration="Release" revealArchiveInOrganizer="YES"/>
|
|
425
|
+
</Scheme>
|
|
426
|
+
`
|
|
427
|
+
|
|
428
|
+
fs.writeFileSync(path.join(projectPath, 'project.pbxproj'), pbxproj)
|
|
429
|
+
fs.writeFileSync(
|
|
430
|
+
path.join(projectPath, 'project.xcworkspace/contents.xcworkspacedata'),
|
|
431
|
+
'<?xml version="1.0" encoding="UTF-8"?>\n<Workspace version="1.0"><FileRef location="self:"></FileRef></Workspace>\n',
|
|
432
|
+
)
|
|
433
|
+
fs.writeFileSync(path.join(projectPath, 'xcshareddata/xcschemes/GeaWatch.xcscheme'), scheme)
|
|
434
|
+
console.log(`Generated ${projectPath}`)
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import Combine
|
|
2
|
+
import SwiftUI
|
|
3
|
+
import WatchKit
|
|
4
|
+
|
|
5
|
+
// watchOS apps have no UIApplication or UIView hierarchy to host a renderer in,
|
|
6
|
+
// so the shell is SwiftUI: gea paints into its framebuffer (watchos_host.mm) and
|
|
7
|
+
// this view shows each presented frame as an image and feeds touches back.
|
|
8
|
+
|
|
9
|
+
@main
|
|
10
|
+
struct GeaWatchApp: App {
|
|
11
|
+
var body: some Scene {
|
|
12
|
+
WindowGroup {
|
|
13
|
+
GeaWatchRootView()
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
final class GeaWatchHost: ObservableObject {
|
|
19
|
+
@Published private(set) var frame: CGImage?
|
|
20
|
+
// The Crown's value is the scroll position in Crown units, bounded by the
|
|
21
|
+
// scroll range, so the system's Crown indicator shows where the list is.
|
|
22
|
+
@Published var crownValue = 0.0
|
|
23
|
+
@Published private(set) var crownMax = 1.0
|
|
24
|
+
let scale: CGFloat = max(1, WKInterfaceDevice.current().screenScale)
|
|
25
|
+
private var timer: AnyCancellable?
|
|
26
|
+
private var touching = false
|
|
27
|
+
private var lastCrownOffset = 0.0
|
|
28
|
+
|
|
29
|
+
// SwiftUI reports the Crown in its own units, not points; this sets how far
|
|
30
|
+
// one unit scrolls. Tune it on a real watch.
|
|
31
|
+
static let crownPointsPerUnit = 20.0
|
|
32
|
+
|
|
33
|
+
func start(size: CGSize) {
|
|
34
|
+
guard size.width > 0, size.height > 0 else { return }
|
|
35
|
+
gea_watchos_start(Int32((size.width * scale).rounded()), Int32((size.height * scale).rounded()), Double(scale))
|
|
36
|
+
tick()
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// The frame loop runs only while the app is frontmost: an inactive watch app
|
|
40
|
+
// (wrist down, always-on dimmed) keeps no display link and should not spin.
|
|
41
|
+
func setActive(_ active: Bool) {
|
|
42
|
+
if !active {
|
|
43
|
+
timer = nil
|
|
44
|
+
return
|
|
45
|
+
}
|
|
46
|
+
guard timer == nil else { return }
|
|
47
|
+
timer = Timer.publish(every: 1.0 / 60.0, on: .main, in: .common)
|
|
48
|
+
.autoconnect()
|
|
49
|
+
.sink { [weak self] _ in self?.tick() }
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
func touch(_ phase: GeaWatchTouchPhase, at point: CGPoint) {
|
|
53
|
+
gea_watchos_touch(phase, Double(point.x), Double(point.y))
|
|
54
|
+
// Present the result of the tap now rather than on the next timer tick.
|
|
55
|
+
tick()
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
func drag(at point: CGPoint) {
|
|
59
|
+
touch(touching ? GeaWatchTouchMove : GeaWatchTouchDown, at: point)
|
|
60
|
+
touching = true
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
func lift(at point: CGPoint) {
|
|
64
|
+
guard touching else { return }
|
|
65
|
+
touching = false
|
|
66
|
+
touch(GeaWatchTouchUp, at: point)
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
func crown(to offset: Double) {
|
|
70
|
+
let delta = offset - lastCrownOffset
|
|
71
|
+
lastCrownOffset = offset
|
|
72
|
+
gea_watchos_crown(delta * Self.crownPointsPerUnit)
|
|
73
|
+
tick()
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
private func tick() {
|
|
77
|
+
guard gea_watchos_frame() != 0 else { return }
|
|
78
|
+
frame = gea_watchos_copy_frame_image()
|
|
79
|
+
syncCrown()
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// Follows scrolls the Crown did not make (touch, momentum, range changes) so
|
|
83
|
+
// the indicator stays true. A Crown turn already left the two in step, so
|
|
84
|
+
// this writes only when they differ by a pixel or more.
|
|
85
|
+
private func syncCrown() {
|
|
86
|
+
var top = 0.0
|
|
87
|
+
var maxTop = 0.0
|
|
88
|
+
guard gea_watchos_scroll_metrics(&top, &maxTop) != 0 else { return }
|
|
89
|
+
let unitsMax = Swift.max(maxTop / Self.crownPointsPerUnit, 1)
|
|
90
|
+
if crownMax != unitsMax { crownMax = unitsMax }
|
|
91
|
+
let units = top / Self.crownPointsPerUnit
|
|
92
|
+
guard abs(units - lastCrownOffset) * Self.crownPointsPerUnit * Double(scale) >= 1 else { return }
|
|
93
|
+
lastCrownOffset = units
|
|
94
|
+
crownValue = units
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
struct GeaWatchRootView: View {
|
|
99
|
+
@StateObject private var host = GeaWatchHost()
|
|
100
|
+
@Environment(\.scenePhase) private var scenePhase
|
|
101
|
+
@FocusState private var crownFocused: Bool
|
|
102
|
+
|
|
103
|
+
// The canvas covers the whole screen. watchOS's safe area keeps roughly a
|
|
104
|
+
// fifth of the panel clear at the top and bottom, which is too much to give
|
|
105
|
+
// up on a watch; apps that need the clock area free lay themselves out
|
|
106
|
+
// around it, as on the round ESP32 watch panels.
|
|
107
|
+
var body: some View {
|
|
108
|
+
GeometryReader { geometry in
|
|
109
|
+
Group {
|
|
110
|
+
if let frame = host.frame {
|
|
111
|
+
Image(decorative: frame, scale: host.scale)
|
|
112
|
+
.resizable()
|
|
113
|
+
.interpolation(.none)
|
|
114
|
+
} else {
|
|
115
|
+
Color.black
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
.frame(width: geometry.size.width, height: geometry.size.height)
|
|
119
|
+
.contentShape(Rectangle())
|
|
120
|
+
.gesture(
|
|
121
|
+
DragGesture(minimumDistance: 0, coordinateSpace: .local)
|
|
122
|
+
.onChanged { host.drag(at: $0.location) }
|
|
123
|
+
.onEnded { host.lift(at: $0.location) }
|
|
124
|
+
)
|
|
125
|
+
// The Crown only reaches a focused view, and focusable() must come
|
|
126
|
+
// before digitalCrownRotation() or the rotation is never delivered.
|
|
127
|
+
.focusable()
|
|
128
|
+
.focusEffectDisabled()
|
|
129
|
+
.focused($crownFocused)
|
|
130
|
+
.digitalCrownRotation($host.crownValue, from: 0, through: host.crownMax, onChange: { host.crown(to: $0.offset) })
|
|
131
|
+
.onAppear {
|
|
132
|
+
host.start(size: geometry.size)
|
|
133
|
+
host.setActive(scenePhase == .active)
|
|
134
|
+
crownFocused = true
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
.ignoresSafeArea()
|
|
138
|
+
.onChange(of: scenePhase) { _, phase in host.setActive(phase == .active) }
|
|
139
|
+
}
|
|
140
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
#ifndef GEA_WATCHOS_BRIDGE_H
|
|
2
|
+
#define GEA_WATCHOS_BRIDGE_H
|
|
3
|
+
|
|
4
|
+
// The C surface the SwiftUI shell (watchos_app.swift) drives the gea runtime
|
|
5
|
+
// through. It is the Swift bridging header, so it stays plain C: Swift imports
|
|
6
|
+
// it through clang as Objective-C, never as C++.
|
|
7
|
+
|
|
8
|
+
#include <CoreGraphics/CoreGraphics.h>
|
|
9
|
+
|
|
10
|
+
#ifdef __cplusplus
|
|
11
|
+
extern "C" {
|
|
12
|
+
#endif
|
|
13
|
+
|
|
14
|
+
// Phases for gea_watchos_touch.
|
|
15
|
+
typedef enum {
|
|
16
|
+
GeaWatchTouchDown = 0,
|
|
17
|
+
GeaWatchTouchMove = 1,
|
|
18
|
+
GeaWatchTouchUp = 2,
|
|
19
|
+
} GeaWatchTouchPhase;
|
|
20
|
+
|
|
21
|
+
// Mounts the app on a canvas of widthPx x heightPx physical pixels. `scale` is
|
|
22
|
+
// the screen's pixels-per-point, used to map touches from view points.
|
|
23
|
+
// Only the first call mounts; later ones are ignored.
|
|
24
|
+
void gea_watchos_start(int widthPx, int heightPx, double scale);
|
|
25
|
+
|
|
26
|
+
// Runs one gea frame (microtasks, rAF callbacks, style, layout, paint).
|
|
27
|
+
// Returns 1 when the presented framebuffer changed since the previous call.
|
|
28
|
+
int gea_watchos_frame(void);
|
|
29
|
+
|
|
30
|
+
// A snapshot of the presented framebuffer, or NULL before the first frame.
|
|
31
|
+
CGImageRef _Nullable gea_watchos_copy_frame_image(void) CF_RETURNS_RETAINED;
|
|
32
|
+
|
|
33
|
+
// Feeds a touch in view points (origin top-left of the canvas view).
|
|
34
|
+
void gea_watchos_touch(GeaWatchTouchPhase phase, double xPoints, double yPoints);
|
|
35
|
+
|
|
36
|
+
// Feeds a Digital Crown rotation of deltaPoints view points (positive = toward
|
|
37
|
+
// the end of the content). Scrolls the first vertical scroll container.
|
|
38
|
+
void gea_watchos_crown(double deltaPoints);
|
|
39
|
+
|
|
40
|
+
// The offset and range, in view points, of the container the Crown scrolls.
|
|
41
|
+
// Returns 0 when nothing scrolls vertically.
|
|
42
|
+
int gea_watchos_scroll_metrics(double *_Nonnull topPoints, double *_Nonnull maxPoints);
|
|
43
|
+
|
|
44
|
+
#ifdef __cplusplus
|
|
45
|
+
}
|
|
46
|
+
#endif
|
|
47
|
+
|
|
48
|
+
#endif
|