tauri-plugin-live-activity 0.10.1 → 0.10.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/README.ko.md +2 -2
- package/README.md +2 -2
- package/cli/bin.mjs +0 -1
- package/cli/ios.mjs +173 -157
- package/cli/main.mjs +48 -43
- package/cli/migration.mjs +26 -31
- package/cli/plist.mjs +51 -49
- package/cli/report.mjs +28 -22
- package/cli/setup.mjs +140 -110
- package/cli/steps.mjs +66 -50
- package/cli/widget-files.mjs +109 -97
- package/cli/xcodegen.mjs +144 -146
- package/package.json +14 -12
package/README.ko.md
CHANGED
|
@@ -27,7 +27,7 @@ Tauri 2 앱이 하고 있는 일을 iPhone 잠금 화면과 Dynamic Island에, A
|
|
|
27
27
|
<table>
|
|
28
28
|
<tr><th>iOS: 잠금 화면의 간식 배달과 낮잠 타이머</th><th>iOS: 갱신으로 바뀌는 바인딩된 스타일</th><th>Android: 같은 요청이 잠금 화면의 알림으로</th></tr>
|
|
29
29
|
<tr>
|
|
30
|
-
<td><img src="https://raw.githubusercontent.com/1eedaegon/tauri-plugin-live-activity/main/docs/images/ios-demo.gif" width="250" alt="데모가 Mochi의
|
|
30
|
+
<td><img src="https://raw.githubusercontent.com/1eedaegon/tauri-plugin-live-activity/main/docs/images/ios-demo.gif" width="250" alt="데모가 Mochi의 간식을 출발시키면 잠금 화면에 진행률 막대가 있는 카드가 뜨고(처음에는 시스템의 허용 질문과 함께), 이어서 낮잠을 시작하면 그 카드의 타이머가 줄어듭니다"></td>
|
|
31
31
|
<td><img src="https://raw.githubusercontent.com/1eedaegon/tauri-plugin-live-activity/main/docs/images/ios-styles.gif" width="250" alt="데모가 새 값을 보내면 잠금 화면 카드의 상태가 빨갛고 굵게 바뀝니다"></td>
|
|
32
32
|
<td><img src="https://raw.githubusercontent.com/1eedaegon/tauri-plugin-live-activity/main/docs/images/android-snack.gif" width="250" alt="데모가 Mochi의 간식 배달을 시작하고, 폰을 잠그면 잠금 화면에 알림이 보이며 갱신마다 진행률 막대가 움직이고, 밀어서 풀면 배달이 끝납니다"></td>
|
|
33
33
|
</tr>
|
|
@@ -38,7 +38,7 @@ Tauri 2 앱이 하고 있는 일을 iPhone 잠금 화면과 Dynamic Island에, A
|
|
|
38
38
|
`UNSUPPORTED_PLATFORM`을 돌려줍니다. 플러그인은 [liveactivity](https://github.com/1eedaegon/liveactivity-rs)
|
|
39
39
|
크레이트의 어댑터이고, 이 크레이트가 iOS는 [activitykit](https://github.com/1eedaegon/activitykit-rs), Android는
|
|
40
40
|
[liveupdate](https://github.com/1eedaegon/liveupdate-rs) 위에서 돌립니다. 그래서 플러그인 자체의 Swift 코드가 없고
|
|
41
|
-
Kotlin은 권한 명령과 liveupdate의 Android 어댑터 호출만 맡습니다.
|
|
41
|
+
Kotlin은 권한 명령과 liveupdate의 Android 어댑터 호출만 맡습니다.
|
|
42
42
|
|
|
43
43
|
## 설치
|
|
44
44
|
|
package/README.md
CHANGED
|
@@ -27,7 +27,7 @@ The demo running, recorded on the iPhone 17 Pro simulator and an Android 16 emul
|
|
|
27
27
|
<table>
|
|
28
28
|
<tr><th>iOS: a snack delivery and a nap timer on the Lock Screen</th><th>iOS: a bound style changes with an update</th><th>Android: the same request as a notification on the lock screen</th></tr>
|
|
29
29
|
<tr>
|
|
30
|
-
<td><img src="https://raw.githubusercontent.com/1eedaegon/tauri-plugin-live-activity/main/docs/images/ios-demo.gif" width="250" alt="The demo
|
|
30
|
+
<td><img src="https://raw.githubusercontent.com/1eedaegon/tauri-plugin-live-activity/main/docs/images/ios-demo.gif" width="250" alt="The demo sends Mochi's snack on its way and the Lock Screen shows its card with a progress bar, under the system's question at first; then a nap starts, and its card counts down"></td>
|
|
31
31
|
<td><img src="https://raw.githubusercontent.com/1eedaegon/tauri-plugin-live-activity/main/docs/images/ios-styles.gif" width="250" alt="The demo sends new values and the Lock Screen card's status turns red and bold"></td>
|
|
32
32
|
<td><img src="https://raw.githubusercontent.com/1eedaegon/tauri-plugin-live-activity/main/docs/images/android-snack.gif" width="250" alt="The demo starts Mochi's snack delivery; the phone is locked and its lock screen shows the notification, whose progress bar moves with each update; a swipe unlocks and the delivery ends"></td>
|
|
33
33
|
</tr>
|
|
@@ -38,7 +38,7 @@ which follows a cat named Mochi. iOS 16.2+ and Android 8+; on desktop the activi
|
|
|
38
38
|
`UNSUPPORTED_PLATFORM`. The plugin is an adapter of the [liveactivity](https://github.com/1eedaegon/liveactivity-rs)
|
|
39
39
|
crate, which runs iOS on [activitykit](https://github.com/1eedaegon/activitykit-rs) and Android on
|
|
40
40
|
[liveupdate](https://github.com/1eedaegon/liveupdate-rs): the plugin has no Swift of its own, and its Kotlin answers
|
|
41
|
-
the permission commands and carries liveupdate's Android adapter.
|
|
41
|
+
the permission commands and carries liveupdate's Android adapter.
|
|
42
42
|
|
|
43
43
|
## Install
|
|
44
44
|
|
package/cli/bin.mjs
CHANGED
package/cli/ios.mjs
CHANGED
|
@@ -1,17 +1,14 @@
|
|
|
1
1
|
// The iOS part of setup: Info.ios.plist, the widget files in gen/apple with the fonts and images it bundles, the
|
|
2
2
|
// XcodeGen spec that adds the widget extension on activitykit's Swift package, the App Group, and the regenerated
|
|
3
|
-
// Xcode project. An app that 0.2 or 0.3 set up loses the plugin's old Swift files on the way (migration.
|
|
3
|
+
// Xcode project. An app that 0.2 or 0.3 set up loses the plugin's old Swift files on the way (migration.mts).
|
|
4
4
|
import { spawnSync } from 'node:child_process';
|
|
5
5
|
import { readdirSync, rmSync } from 'node:fs';
|
|
6
6
|
import { join, resolve } from 'node:path';
|
|
7
7
|
import { OLD_MODULES, RETIRED, released, renameCustomViews } from './migration.mjs';
|
|
8
8
|
import { newPlist, setTrueKey } from './plist.mjs';
|
|
9
|
-
import { SetupError, parseJson, readText, step, tail, which, writeFile } from './steps.mjs';
|
|
9
|
+
import { SetupError, member, parseJson, readText, step, tail, which, writeFile } from './steps.mjs';
|
|
10
10
|
import { assetSteps, bundledFonts, fontSteps } from './widget-files.mjs';
|
|
11
|
-
import {
|
|
12
|
-
SMALL_FAMILY_KEY, SPEC_FILE, WIDGET, addInclude, appGroupOf, drawsSmallFamily, readProject, widgetSpec, writtenBySetup,
|
|
13
|
-
} from './xcodegen.mjs';
|
|
14
|
-
|
|
11
|
+
import { SMALL_FAMILY_KEY, SPEC_FILE, WIDGET, addInclude, appGroupOf, drawsSmallFamily, readProject, widgetSpec, writtenBySetup, } from './xcodegen.mjs';
|
|
15
12
|
/** The widget bundle: activitykit's template, under the name 0.2 and 0.3 gave the plugin's. */
|
|
16
13
|
const WIDGET_FILE = 'LiveActivityWidget.swift';
|
|
17
14
|
const WIDGET_TEMPLATE = join('templates', 'ios', 'Widget.swift');
|
|
@@ -20,195 +17,214 @@ const CUSTOM_VIEWS = 'LiveActivityCustomViews.swift';
|
|
|
20
17
|
const CUSTOM_VIEWS_TEMPLATE = new URL('./templates/LiveActivityCustomViews.swift', import.meta.url);
|
|
21
18
|
const GROUP = /^group\.[A-Za-z0-9-]+(\.[A-Za-z0-9-]+)*$/;
|
|
22
19
|
const PLIST_KEY = 'NSSupportsLiveActivities';
|
|
23
|
-
|
|
20
|
+
/** The app's bundle identifier: the first of project.yml, or the identifier of tauri.conf.json. */
|
|
21
|
+
function bundleIdOf(project, config) {
|
|
22
|
+
const id = project.bundleId ?? config.identifier;
|
|
23
|
+
if (typeof id !== 'string' || id === '') {
|
|
24
|
+
throw new SetupError("The app has no identifier in tauri.conf.json and no PRODUCT_BUNDLE_IDENTIFIER in project.yml: the widget extension's is made from it.");
|
|
25
|
+
}
|
|
26
|
+
return id;
|
|
27
|
+
}
|
|
24
28
|
export function iosSteps(context) {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
29
|
+
const { srcTauri, platform, show } = context;
|
|
30
|
+
if (platform !== 'darwin')
|
|
31
|
+
return [step('skipped', 'iOS', 'needs a Mac with Xcode')];
|
|
32
|
+
const apple = join(srcTauri, 'gen', 'apple');
|
|
33
|
+
const specPath = join(apple, 'project.yml');
|
|
34
|
+
const yaml = readText(specPath);
|
|
35
|
+
if (yaml === undefined) {
|
|
36
|
+
return [step('skipped', 'iOS', 'no src-tauri/gen/apple yet: run `tauri ios init`, then run setup again')];
|
|
37
|
+
}
|
|
38
|
+
const project = readProject(yaml);
|
|
39
|
+
const plist = infoPlistStep(context);
|
|
40
|
+
if (project.widget) {
|
|
41
|
+
const detail = `already has a widget extension, ${project.widget}; add the plugin's widget to it by hand (docs/ios-integration.md)`;
|
|
42
|
+
const { files, appGroup, smallFamily } = context;
|
|
43
|
+
const given = [files.fonts.length && '--font', files.assets.length && '--asset', appGroup && '--app-group', smallFamily && '--small-family'].filter(Boolean);
|
|
44
|
+
const left = given.length === 0 ? [] : [step('todo', show(specPath), `${given.join(', ')} not applied: that widget is yours to give fonts, images, an App Group and the small family (docs/ios-integration.md)`)];
|
|
45
|
+
return [plist, step('skipped', show(specPath), detail), ...left];
|
|
46
|
+
}
|
|
47
|
+
if (!hasAppTarget(project)) {
|
|
48
|
+
const detail = `no target named ${project.name ?? '<name>'}_iOS, so setup did not add the widget; see docs/usage.md`;
|
|
49
|
+
return [plist, step('todo', show(specPath), detail)];
|
|
50
|
+
}
|
|
51
|
+
const widget = join(apple, WIDGET);
|
|
52
|
+
const appGroup = appGroupFor(context, apple, project);
|
|
53
|
+
// A spec that setup wrote with the small family keeps it on later runs, as it keeps its App Group.
|
|
54
|
+
const smallFamily = context.smallFamily || drawsSmallFamily(readText(join(apple, SPEC_FILE)));
|
|
55
|
+
const include = includeStep(context, specPath, yaml);
|
|
56
|
+
// XcodeGen lists the files of a folder when it generates, so a new or removed widget file also needs a run.
|
|
57
|
+
const projectSteps = [
|
|
58
|
+
widgetStep(context, widget), ...retiredSteps(context, widget, readText(join(apple, SPEC_FILE))), customViewsStep(context, widget),
|
|
59
|
+
...fontSteps(context, widget), ...assetSteps(context, widget),
|
|
60
|
+
specStep(context, apple, project, { fonts: bundledFonts(context, widget), appGroup, smallFamily }), include,
|
|
61
|
+
];
|
|
62
|
+
return [plist, ...projectSteps, xcodegenStep(context, apple, specPath, projectSteps, include)];
|
|
58
63
|
}
|
|
59
|
-
|
|
64
|
+
const hasAppTarget = (project) => Boolean(project.appTarget);
|
|
60
65
|
/**
|
|
61
66
|
* The App Group of `--app-group`: the group it names, or `group.<app identifier>`. A spec that setup wrote
|
|
62
67
|
* with a group keeps it on later runs.
|
|
63
68
|
*/
|
|
64
69
|
function appGroupFor({ appGroup, config }, apple, project) {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
70
|
+
const kept = appGroupOf(readText(join(apple, SPEC_FILE)));
|
|
71
|
+
const group = typeof appGroup === 'string' ? appGroup : kept ?? (appGroup ? `group.${bundleIdOf(project, config)}` : undefined);
|
|
72
|
+
if (group !== undefined && !GROUP.test(group)) {
|
|
73
|
+
throw new SetupError(`The App Group ${JSON.stringify(group)} must be "group." followed by letters, digits, '-' and '.'.`);
|
|
74
|
+
}
|
|
75
|
+
return group;
|
|
71
76
|
}
|
|
72
|
-
|
|
73
77
|
/**
|
|
74
78
|
* LiveActivityCustomViews.swift belongs to the app: created once, then never written again, except that a file of 0.3
|
|
75
79
|
* takes activitykit's names, its views kept.
|
|
76
80
|
*/
|
|
77
81
|
function customViewsStep({ show }, widget) {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
82
|
+
const path = join(widget, CUSTOM_VIEWS);
|
|
83
|
+
const current = readText(path);
|
|
84
|
+
if (current !== undefined) {
|
|
85
|
+
const renamed = renameCustomViews(current);
|
|
86
|
+
if (renamed === undefined)
|
|
87
|
+
return step('unchanged', show(path));
|
|
88
|
+
return step('updated', show(path), "activitykit's names for the registry and its types; your views are kept", writeFile(path, renamed));
|
|
89
|
+
}
|
|
90
|
+
const stub = readText(CUSTOM_VIEWS_TEMPLATE);
|
|
91
|
+
if (stub === undefined) {
|
|
92
|
+
throw new SetupError('This copy of tauri-plugin-live-activity has no cli/templates/LiveActivityCustomViews.swift. Install the package again.');
|
|
93
|
+
}
|
|
94
|
+
return step('created', show(path), 'yours, for custom views; setup never changes it again', writeFile(path, stub));
|
|
87
95
|
}
|
|
88
|
-
|
|
89
96
|
/** Tauri merges src-tauri/Info.ios.plist into the app's Info.plist when it builds. */
|
|
90
97
|
function infoPlistStep({ srcTauri, show }) {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
98
|
+
const path = join(srcTauri, 'Info.ios.plist');
|
|
99
|
+
const text = readText(path);
|
|
100
|
+
if (text === undefined)
|
|
101
|
+
return step('created', show(path), `${PLIST_KEY} = true`, writeFile(path, newPlist(PLIST_KEY)));
|
|
102
|
+
const result = setTrueKey(text, PLIST_KEY);
|
|
103
|
+
if (result.status === 'present')
|
|
104
|
+
return step('unchanged', show(path));
|
|
105
|
+
if (result.status === 'added')
|
|
106
|
+
return step('updated', show(path), `${PLIST_KEY} = true`, writeFile(path, result.text));
|
|
107
|
+
if (result.status === 'unreadable') {
|
|
108
|
+
return step('todo', show(path), `add ${PLIST_KEY} = YES to it; setup reads XML plists only`);
|
|
109
|
+
}
|
|
110
|
+
return step('kept', show(path), `it sets ${PLIST_KEY} to something other than true; Live Activities need true`);
|
|
101
111
|
}
|
|
102
|
-
|
|
103
112
|
/** The widget bundle from activitykit's template; one that 0.2 or 0.3 wrote is replaced, one of the app's kept. */
|
|
104
113
|
function widgetStep({ activitykit, show }, widget) {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
114
|
+
const wanted = readText(join(activitykit.dir, WIDGET_TEMPLATE));
|
|
115
|
+
if (wanted === undefined)
|
|
116
|
+
throw new SetupError(`The activitykit crate at ${activitykit.dir} has no ${WIDGET_TEMPLATE}.`);
|
|
117
|
+
const path = join(widget, WIDGET_FILE);
|
|
118
|
+
const current = readText(path);
|
|
119
|
+
if (current === undefined)
|
|
120
|
+
return step('created', show(path), '', writeFile(path, wanted));
|
|
121
|
+
if (current === wanted)
|
|
122
|
+
return step('unchanged', show(path));
|
|
123
|
+
if (released(WIDGET_FILE, current)) {
|
|
124
|
+
return step('updated', show(path), "activitykit's widget, in place of the one tauri-plugin-live-activity 0.3 wrote", writeFile(path, wanted));
|
|
125
|
+
}
|
|
126
|
+
if (OLD_MODULES.test(current)) {
|
|
127
|
+
return step('todo', show(path), "imports the Swift modules of tauri-plugin-live-activity 0.3, which 0.4 no longer has: draw with ActivityKitWidget's ActivityKitLayoutWidget(), or delete the file and run setup again");
|
|
128
|
+
}
|
|
129
|
+
return step('kept', show(path), "differs from activitykit's template; to take the template, delete it and run setup again");
|
|
118
130
|
}
|
|
119
|
-
|
|
120
131
|
/**
|
|
121
132
|
* The button intent and the custom views registry of 0.2 and 0.3, which activitykit's products replace. A spec changed
|
|
122
133
|
* by hand, which setup keeps, may still name one: XcodeGen would fail without it, so it stays as a step to do.
|
|
123
134
|
*/
|
|
124
135
|
function retiredSteps({ show }, widget, spec) {
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
136
|
+
const kept = spec !== undefined && !writtenBySetup(spec);
|
|
137
|
+
return RETIRED.flatMap(name => {
|
|
138
|
+
const path = join(widget, name);
|
|
139
|
+
const current = readText(path);
|
|
140
|
+
if (current === undefined)
|
|
141
|
+
return [];
|
|
142
|
+
if (kept && spec.includes(name)) {
|
|
143
|
+
return [step('todo', show(path), `${SPEC_FILE}, which you changed, still names it: take it out of the spec, then delete it; activitykit's Swift package replaces it`)];
|
|
144
|
+
}
|
|
145
|
+
if (released(name, current)) {
|
|
146
|
+
return [step('removed', show(path), "activitykit's Swift package replaces it", () => { rmSync(path); })];
|
|
147
|
+
}
|
|
148
|
+
return [step('todo', show(path), "changed by hand; activitykit's Swift package replaces it, so move your changes and delete it")];
|
|
149
|
+
});
|
|
138
150
|
}
|
|
139
|
-
|
|
140
151
|
function specStep({ plugin, activitykit, config, srcTauri, show }, apple, project, { fonts, appGroup, smallFamily }) {
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
}
|
|
159
|
-
if (current === wanted) return step('unchanged', show(path));
|
|
160
|
-
if (!writtenBySetup(current)) {
|
|
161
|
-
// The spec is the app's now: the key that --small-family asks for goes in by hand, as the rest of it did.
|
|
162
|
-
if (smallFamily && !drawsSmallFamily(current)) {
|
|
163
|
-
return step('todo', show(path), `it was changed by hand, so --small-family was not applied: add \`${SMALL_FAMILY_KEY}: true\` to the info properties of ${WIDGET}, or delete the file and run setup again`);
|
|
152
|
+
const path = join(apple, SPEC_FILE);
|
|
153
|
+
const wanted = widgetSpec({
|
|
154
|
+
fonts,
|
|
155
|
+
appGroup,
|
|
156
|
+
smallFamily,
|
|
157
|
+
// XcodeGen writes the entitlements file from the spec, so the App Group goes into the spec, at the app's path.
|
|
158
|
+
appEntitlements: project.entitlements ?? `${project.appTarget}/${project.appTarget}.entitlements`,
|
|
159
|
+
pluginVersion: plugin.version,
|
|
160
|
+
packagePath: join(activitykit.dir, 'swift'),
|
|
161
|
+
appTarget: project.appTarget,
|
|
162
|
+
bundleId: `${bundleIdOf(project, config)}.widget`,
|
|
163
|
+
...appVersions(config, srcTauri),
|
|
164
|
+
teamGroup: project.settingGroups.includes('app'),
|
|
165
|
+
});
|
|
166
|
+
const current = readText(path);
|
|
167
|
+
if (current === undefined) {
|
|
168
|
+
return step('created', show(path), "the widget extension on activitykit's Swift package, and the button intent and custom views in the app", writeFile(path, wanted));
|
|
164
169
|
}
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
170
|
+
if (current === wanted)
|
|
171
|
+
return step('unchanged', show(path));
|
|
172
|
+
if (!writtenBySetup(current)) {
|
|
173
|
+
// The spec is the app's now: the key that --small-family asks for goes in by hand, as the rest of it did.
|
|
174
|
+
if (smallFamily && !drawsSmallFamily(current)) {
|
|
175
|
+
return step('todo', show(path), `it was changed by hand, so --small-family was not applied: add \`${SMALL_FAMILY_KEY}: true\` to the info properties of ${WIDGET}, or delete the file and run setup again`);
|
|
176
|
+
}
|
|
177
|
+
return step('kept', show(path), 'it was changed by hand; delete it and run setup again to have it written anew');
|
|
178
|
+
}
|
|
179
|
+
return step('updated', show(path), 'for the current plugin, activitykit and app version', writeFile(path, wanted));
|
|
168
180
|
}
|
|
169
|
-
|
|
170
181
|
/** The `version` of Cargo.toml's [package] section. */
|
|
171
182
|
function cargoVersion(text = '') {
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
183
|
+
let inPackage = false;
|
|
184
|
+
for (const line of text.split('\n')) {
|
|
185
|
+
if (/^\s*\[/.test(line))
|
|
186
|
+
inPackage = /^\s*\[package\]\s*$/.test(line);
|
|
187
|
+
else if (inPackage && /^\s*version\s*=/.test(line))
|
|
188
|
+
return /"([^"]+)"/.exec(line)?.[1];
|
|
189
|
+
}
|
|
190
|
+
return undefined;
|
|
178
191
|
}
|
|
179
|
-
|
|
180
192
|
/** The app's version where Tauri reads it, so that the extension's version matches the app's. */
|
|
181
193
|
function appVersions(config, srcTauri) {
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
194
|
+
const named = config.version;
|
|
195
|
+
const version = typeof named === 'string' && named.endsWith('.json')
|
|
196
|
+
? member(parseJson(readText(resolve(srcTauri, named)) ?? ''), 'version')
|
|
197
|
+
: named ?? cargoVersion(readText(join(srcTauri, 'Cargo.toml')));
|
|
198
|
+
const short = /^\d+(\.\d+){0,2}/.exec(String(version ?? ''))?.[0];
|
|
199
|
+
return short ? { appVersion: short, buildVersion: String(member(config.bundle, 'iOS', 'bundleVersion') ?? short) } : {};
|
|
187
200
|
}
|
|
188
|
-
|
|
189
201
|
function includeStep({ show }, specPath, yaml) {
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
202
|
+
const result = addInclude(yaml, SPEC_FILE);
|
|
203
|
+
if (result.status === 'present')
|
|
204
|
+
return step('unchanged', show(specPath));
|
|
205
|
+
if (result.status === 'added')
|
|
206
|
+
return step('updated', show(specPath), `includes ${SPEC_FILE}`, writeFile(specPath, result.text));
|
|
207
|
+
return step('todo', show(specPath), `add ${SPEC_FILE} to its include list`);
|
|
194
208
|
}
|
|
195
|
-
|
|
196
209
|
function generatedWithWidget(apple) {
|
|
197
|
-
|
|
198
|
-
|
|
210
|
+
return readdirSync(apple).filter(name => name.endsWith('.xcodeproj'))
|
|
211
|
+
.some(name => readText(join(apple, name, 'project.pbxproj'))?.includes(WIDGET));
|
|
199
212
|
}
|
|
200
|
-
|
|
201
213
|
function xcodegenStep({ env, show }, apple, specPath, projectSteps, include) {
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
+
const command = `xcodegen generate --spec ${show(specPath)}`;
|
|
215
|
+
if (include.status === 'todo')
|
|
216
|
+
return step('skipped', 'Xcode project', 'waits for the include in project.yml');
|
|
217
|
+
const changed = projectSteps.some(item => ['created', 'updated', 'removed'].includes(item.status));
|
|
218
|
+
if (!changed && generatedWithWidget(apple))
|
|
219
|
+
return step('unchanged', 'Xcode project');
|
|
220
|
+
const xcodegen = which('xcodegen', env);
|
|
221
|
+
if (!xcodegen)
|
|
222
|
+
return step('todo', 'Xcode project', `XcodeGen is not on PATH. Install it (brew install xcodegen), then run: ${command}`);
|
|
223
|
+
return step('ran', command, '', () => {
|
|
224
|
+
const result = spawnSync(xcodegen, ['generate', '--spec', specPath], { cwd: apple, env, encoding: 'utf8' });
|
|
225
|
+
if (result.status === 0)
|
|
226
|
+
return undefined;
|
|
227
|
+
const output = tail(result.stderr || result.stdout || result.error?.message);
|
|
228
|
+
return step('todo', 'Xcode project', `xcodegen failed: ${output}. Fix it, then run: ${command}`);
|
|
229
|
+
});
|
|
214
230
|
}
|
package/cli/main.mjs
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
// The command line of `npx tauri-plugin-live-activity`.
|
|
2
2
|
import { formatReport } from './report.mjs';
|
|
3
3
|
import { SetupError, setup } from './setup.mjs';
|
|
4
|
-
|
|
5
4
|
const USAGE = `Usage: npx tauri-plugin-live-activity setup [--dry-run] [--ios-only] [--font <file>]... [--asset <file>]... [--app-group[=<id>]] [--small-family]
|
|
6
5
|
|
|
7
6
|
Run it in the folder of a Tauri 2 app after \`cargo add\` and \`npm i\`. It grants the plugin's
|
|
@@ -19,53 +18,59 @@ ever made from scratch.
|
|
|
19
18
|
--small-family draw a layout's small region on a paired Apple Watch and in CarPlay, and there the
|
|
20
19
|
compact parts of a layout without one; later runs keep it
|
|
21
20
|
`;
|
|
22
|
-
|
|
23
21
|
const FLAGS = { '--dry-run': 'dryRun', '--ios-only': 'iosOnly', '--small-family': 'smallFamily' };
|
|
24
22
|
const FILES = { '--font': 'fonts', '--asset': 'assets' };
|
|
25
23
|
const HELP = new Set(['help', '--help', '-h']);
|
|
26
|
-
|
|
24
|
+
const isFlag = (name) => Object.hasOwn(FLAGS, name);
|
|
25
|
+
const takesFile = (name) => Object.hasOwn(FILES, name);
|
|
27
26
|
/** The options of `setup`, or the argument it does not take and why. */
|
|
28
27
|
function parseOptions(args) {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
28
|
+
const options = { fonts: [], assets: [] };
|
|
29
|
+
const left = [...args];
|
|
30
|
+
for (let arg = left.shift(); arg !== undefined; arg = left.shift()) {
|
|
31
|
+
const equals = arg.indexOf('=');
|
|
32
|
+
const name = equals === -1 ? arg : arg.slice(0, equals);
|
|
33
|
+
const inline = equals === -1 ? undefined : arg.slice(equals + 1);
|
|
34
|
+
if (isFlag(arg))
|
|
35
|
+
options[FLAGS[arg]] = true;
|
|
36
|
+
else if (name === '--app-group')
|
|
37
|
+
options.appGroup = inline ?? true;
|
|
38
|
+
else if (takesFile(name)) {
|
|
39
|
+
const file = inline ?? left.shift();
|
|
40
|
+
if (!file)
|
|
41
|
+
return { error: `${name} needs a file.` };
|
|
42
|
+
options[FILES[name]].push(file);
|
|
43
|
+
}
|
|
44
|
+
else
|
|
45
|
+
return { error: `Unknown option ${arg}.` };
|
|
46
|
+
}
|
|
47
|
+
return { options };
|
|
41
48
|
}
|
|
42
|
-
|
|
43
49
|
/** Runs the command and returns its exit status: 0 done, 1 something left to do or an error, 2 usage. */
|
|
44
|
-
export function main(argv, {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
}
|
|
50
|
+
export function main(argv, { cwd = process.cwd(), env = process.env, platform = process.platform, out = text => process.stdout.write(text), err = text => process.stderr.write(text), } = {}) {
|
|
51
|
+
const [command, ...rest] = argv;
|
|
52
|
+
if (command === undefined || HELP.has(command) || (command === 'setup' && rest.some(arg => HELP.has(arg)))) {
|
|
53
|
+
out(USAGE);
|
|
54
|
+
return 0;
|
|
55
|
+
}
|
|
56
|
+
if (command !== 'setup') {
|
|
57
|
+
err(`Unknown command ${command}.\n\n${USAGE}`);
|
|
58
|
+
return 2;
|
|
59
|
+
}
|
|
60
|
+
const parsed = parseOptions(rest);
|
|
61
|
+
if ('error' in parsed) {
|
|
62
|
+
err(`${parsed.error}\n\n${USAGE}`);
|
|
63
|
+
return 2;
|
|
64
|
+
}
|
|
65
|
+
try {
|
|
66
|
+
const result = setup({ cwd, env, platform, ...parsed.options });
|
|
67
|
+
out(formatReport(result));
|
|
68
|
+
return result.steps.some(item => item.status === 'todo') ? 1 : 0;
|
|
69
|
+
}
|
|
70
|
+
catch (error) {
|
|
71
|
+
if (!(error instanceof SetupError))
|
|
72
|
+
throw error;
|
|
73
|
+
err(`${error.message}\n`);
|
|
74
|
+
return 1;
|
|
75
|
+
}
|
|
71
76
|
}
|