tauri-plugin-live-activity 1.0.0 → 1.2.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.
package/README.ko.md CHANGED
@@ -65,7 +65,9 @@ TypeScript 또는 Rust로 적고, 그리는 일은 플러그인이 [liveactivity
65
65
 
66
66
  1.0부터 호출하는 쪽을 깨는 변경은 새 메이저 버전에서만 나옵니다. TypeScript와 Rust API, 명령과 그 권한, 이벤트, 오류
67
67
  코드, capability가 모두 여기에 듭니다. 플러그인은 liveactivity의 계약과 엔진(`activitykit`, `liveupdate`)을 다시
68
- 내보내므로, liveactivity의 새 메이저는 여기서도 새 메이저입니다. 최소 Rust 버전을 올리는 것은 마이너 릴리스입니다.
68
+ 내보내므로, liveactivity의 새 메이저는 여기서도 새 메이저입니다. 최소 Rust 버전을 올리는 것은 마이너 릴리스입니다. 1.1부터는 setup 진입점
69
+ `tauri-plugin-live-activity/setup`(`main`, `version`, `widgetFileError`), `setup`이 받는 인자와 그 종료 코드도 이 약속에
70
+ 듭니다([도구에서 setup 쓰기](https://github.com/1eedaegon/tauri-plugin-live-activity/blob/main/docs/usage.md#setup-from-a-tool)).
69
71
 
70
72
  ## 동작 구조
71
73
 
@@ -112,8 +114,10 @@ npx tauri-plugin-live-activity setup
112
114
  ```
113
115
 
114
116
  `setup`은 플러그인 권한을 허용하고, Android 최소 버전을 API 26으로 올리고, Mac에서는 액티비티를 그리는
115
- 위젯 확장을 Xcode 프로젝트에 추가합니다. `tauri ios init` 뒤에 실행하고, `src-tauri/gen/apple`을 새로
116
- 만들 때마다 다시 실행합니다. `--dry-run`은 바꿀 내용만 보여 줍니다.
117
+ 위젯 확장을 Xcode 프로젝트에 추가합니다. `src-tauri/gen/apple`이 없으면 앱의 `tauri ios init`으로 먼저
118
+ 만듭니다. 언제 다시 실행해도 됩니다: 이미 된 것은 그대로 두고 빠진 것만 합니다. `--dry-run`은 바꿀 내용만 보여
119
+ 주고, 모든 옵션은 [setup이 하는 일](https://github.com/1eedaegon/tauri-plugin-live-activity/blob/main/docs/usage.md#what-setup-does)에
120
+ 있습니다.
117
121
 
118
122
  ## React와 TSX
119
123
 
@@ -433,8 +437,8 @@ tauri-plugin-live-activity는 커뮤니티 플러그인이고, Tauri 공식 플
433
437
  iOS 16.1 이상에서 ActivityKit Live Activity를 시작, 갱신, 종료하고, 잠금 화면과 Dynamic Island에 그립니다.
434
438
 
435
439
  **Xcode에서 Widget Extension을 손으로 넣어야 하나요?** 아니요. `npx tauri-plugin-live-activity setup`이 활동을
436
- 그리는 위젯 확장을 `src-tauri/gen/apple`의 Xcode 프로젝트에 넣습니다. `gen/apple`을 새로 만들 때마다 다시
437
- 실행하세요.
440
+ 그리는 위젯 확장을 `src-tauri/gen/apple`의 Xcode 프로젝트에 넣고, 그 프로젝트가 없으면 앱의 `tauri ios init`으로
441
+ 먼저 만듭니다. 언제 다시 실행해도 빠진 것만 합니다.
438
442
 
439
443
  **Android Live Updates를 지원하나요?** 네. Android 16 (API 36) 이상에서는 시스템과 사용자 설정이 허락하면 승격된
440
444
  Live Update를 요청하고, 그 밖에는 Android 8.0 (API 26)부터 같은 요청이 진행 중 알림으로 보입니다.
package/README.md CHANGED
@@ -66,7 +66,9 @@ the Android `minSdk` to 26. The floor of every feature is in
66
66
  From 1.0 a change that breaks callers comes only in a new major version. That covers the TypeScript and Rust APIs,
67
67
  the commands and their permissions, the events, the error codes and the capabilities. The plugin re-exports
68
68
  liveactivity's contract and its engines (`activitykit`, `liveupdate`), so a new major of liveactivity is a new major
69
- here. A rise of the minimum Rust version is a minor release.
69
+ here. A rise of the minimum Rust version is a minor release. From 1.1 the promise also covers the setup entry
70
+ `tauri-plugin-live-activity/setup` (`main`, `version`, `widgetFileError`), the arguments `setup` takes and its exit
71
+ statuses ([setup from a tool](https://github.com/1eedaegon/tauri-plugin-live-activity/blob/main/docs/usage.md#setup-from-a-tool)).
70
72
 
71
73
  ## How it works
72
74
 
@@ -112,8 +114,11 @@ Then register the plugin in `src-tauri/src/lib.rs`:
112
114
  ```
113
115
 
114
116
  `setup` grants the plugin's permissions, raises the Android minimum to API 26 and, on a Mac, adds the
115
- widget extension that draws the activity to the Xcode project. Run it after `tauri ios init`, and again
116
- whenever `src-tauri/gen/apple` is made from scratch. `--dry-run` shows what it would change.
117
+ widget extension that draws the activity to the Xcode project, which it first makes with the app's
118
+ `tauri ios init` when `src-tauri/gen/apple` is not there. Run it again at any time: it leaves what is set up as it
119
+ is and does what is missing. `--dry-run` shows what it would change, and
120
+ [What setup does](https://github.com/1eedaegon/tauri-plugin-live-activity/blob/main/docs/usage.md#what-setup-does)
121
+ has all its options.
117
122
 
118
123
  ## React and TSX
119
124
 
@@ -444,8 +449,8 @@ is a community plugin; Tauri has no official one. With it a Tauri 2 app starts,
444
449
  Activities on iOS 16.1 and later, drawn on the Lock Screen and in the Dynamic Island.
445
450
 
446
451
  **Do I have to add a Widget Extension in Xcode by hand?** No. `npx tauri-plugin-live-activity setup` adds the widget
447
- extension that draws the activity to the Xcode project in `src-tauri/gen/apple`. Run it again whenever `gen/apple` is
448
- made from scratch.
452
+ extension that draws the activity to the Xcode project in `src-tauri/gen/apple`, and first makes that project with the
453
+ app's `tauri ios init` when it is not there. Run it again at any time: it does only what is missing.
449
454
 
450
455
  **Does it support Android Live Updates?** Yes. On Android 16 (API 36) and later the plugin asks for a promoted Live
451
456
  Update where the system and the person's settings allow one; elsewhere, from Android 8.0 (API 26), the same request
package/cli/api.d.mts ADDED
@@ -0,0 +1,14 @@
1
+ export { main } from './main.mjs';
2
+ export type { CommandIo, ExitStatus } from './main.mjs';
3
+ /** This package's version. The crate of the same version goes with it: `cargo add tauri-plugin-live-activity@=<version>`. */
4
+ export declare const version: string;
5
+ /** The files of `setup --font` and `--asset`, as the command line names them. */
6
+ export interface WidgetFileOptions {
7
+ readonly fonts?: readonly string[] | undefined;
8
+ readonly assets?: readonly string[] | undefined;
9
+ }
10
+ /**
11
+ * The message with which `setup` would refuse one of these files, or undefined when it takes them all. It reads the
12
+ * files from `cwd`, writes nothing and needs no app there, so a tool can ask before it changes anything of the app.
13
+ */
14
+ export declare function widgetFileError(cwd: string, { fonts, assets }?: WidgetFileOptions): string | undefined;
package/cli/api.mjs ADDED
@@ -0,0 +1,22 @@
1
+ // `tauri-plugin-live-activity/setup`: the setup command as a module, for a tool that sets up an app for the plugin.
2
+ // What it exports is part of the package's promise since 1.1 (README, Supported versions).
3
+ import { NPM_VERSION, SetupError } from './setup.mjs';
4
+ import { widgetFiles } from './widget-files.mjs';
5
+ export { main } from './main.mjs';
6
+ /** This package's version. The crate of the same version goes with it: `cargo add tauri-plugin-live-activity@=<version>`. */
7
+ export const version = NPM_VERSION;
8
+ /**
9
+ * The message with which `setup` would refuse one of these files, or undefined when it takes them all. It reads the
10
+ * files from `cwd`, writes nothing and needs no app there, so a tool can ask before it changes anything of the app.
11
+ */
12
+ export function widgetFileError(cwd, { fonts = [], assets = [] } = {}) {
13
+ try {
14
+ widgetFiles(cwd, { fonts, assets });
15
+ return undefined;
16
+ }
17
+ catch (error) {
18
+ if (error instanceof SetupError)
19
+ return error.message;
20
+ throw error;
21
+ }
22
+ }
package/cli/bin.d.mts ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
package/cli/ios.d.mts ADDED
@@ -0,0 +1,12 @@
1
+ import type { SetupContext } from './setup.mjs';
2
+ import type { PlannedStep } from './steps.mjs';
3
+ /**
4
+ * On a Mac, the step that makes src-tauri/gen/apple with the app's Tauri CLI when the app has no Xcode project yet,
5
+ * so that the iOS steps can follow in the same run. Undefined when the project is there, elsewhere than on a Mac, or
6
+ * without a Tauri CLI, where the iOS steps report what is left.
7
+ */
8
+ export declare function iosInitStep({ srcTauri, env, platform }: Pick<SetupContext, 'srcTauri' | 'env' | 'platform'>): PlannedStep | undefined;
9
+ /** The iOS steps. `initPlanned`: a dry run plans `tauri ios init`, so the project is not there yet. */
10
+ export declare function iosSteps(context: SetupContext, { initPlanned }?: {
11
+ initPlanned?: boolean | undefined;
12
+ }): PlannedStep[];
package/cli/ios.mjs CHANGED
@@ -3,10 +3,10 @@
3
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
- import { join, resolve } from 'node:path';
6
+ import { dirname, 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, member, parseJson, readText, step, tail, which, writeFile } from './steps.mjs';
9
+ import { SetupError, isExecutable, member, parseJson, readText, step, tail, which, writeFile } from './steps.mjs';
10
10
  import { assetSteps, bundledFonts, fontSteps } from './widget-files.mjs';
11
11
  import { SMALL_FAMILY_KEY, SPEC_FILE, WIDGET, addInclude, appGroupOf, drawsSmallFamily, readProject, widgetSpec, writtenBySetup, } from './xcodegen.mjs';
12
12
  /** The widget bundle: activitykit's template, under the name 0.2 and 0.3 gave the plugin's. */
@@ -25,7 +25,42 @@ function bundleIdOf(project, config) {
25
25
  }
26
26
  return id;
27
27
  }
28
- export function iosSteps(context) {
28
+ const IOS_INIT = 'tauri ios init --ci';
29
+ /** The app's own Tauri CLI: its @tauri-apps/cli, else cargo's `cargo tauri`, as a program and its first arguments. */
30
+ function tauriCli(srcTauri, env) {
31
+ const local = join(dirname(srcTauri), 'node_modules', '.bin', 'tauri');
32
+ if (isExecutable(local))
33
+ return [local];
34
+ const cargoTauri = which('cargo-tauri', env);
35
+ return cargoTauri ? [cargoTauri, 'tauri'] : undefined;
36
+ }
37
+ /**
38
+ * On a Mac, the step that makes src-tauri/gen/apple with the app's Tauri CLI when the app has no Xcode project yet,
39
+ * so that the iOS steps can follow in the same run. Undefined when the project is there, elsewhere than on a Mac, or
40
+ * without a Tauri CLI, where the iOS steps report what is left.
41
+ */
42
+ export function iosInitStep({ srcTauri, env, platform }) {
43
+ if (platform !== 'darwin')
44
+ return undefined;
45
+ const specPath = join(srcTauri, 'gen', 'apple', 'project.yml');
46
+ if (readText(specPath) !== undefined)
47
+ return undefined;
48
+ const cli = tauriCli(srcTauri, env);
49
+ if (!cli)
50
+ return undefined;
51
+ const [program, ...first] = cli;
52
+ return step('ran', IOS_INIT, 'makes src-tauri/gen/apple', () => {
53
+ // Its own output goes to the terminal as it runs: it may install what iOS builds need, which takes a while.
54
+ const result = spawnSync(program, [...first, 'ios', 'init', '--ci'], { cwd: dirname(srcTauri), env, stdio: ['ignore', 'inherit', 'inherit'] });
55
+ if (result.status === 0 && readText(specPath) !== undefined)
56
+ return undefined;
57
+ const why = result.error ? result.error.message
58
+ : result.status === 0 ? 'it made no src-tauri/gen/apple/project.yml' : `it exited with ${result.status ?? result.signal}; its output is above`;
59
+ return step('todo', IOS_INIT, `${why}. Fix it, then run setup again`);
60
+ });
61
+ }
62
+ /** The iOS steps. `initPlanned`: a dry run plans `tauri ios init`, so the project is not there yet. */
63
+ export function iosSteps(context, { initPlanned = false } = {}) {
29
64
  const { srcTauri, platform, show } = context;
30
65
  if (platform !== 'darwin')
31
66
  return [step('skipped', 'iOS', 'needs a Mac with Xcode')];
@@ -33,6 +68,8 @@ export function iosSteps(context) {
33
68
  const specPath = join(apple, 'project.yml');
34
69
  const yaml = readText(specPath);
35
70
  if (yaml === undefined) {
71
+ if (initPlanned)
72
+ return [step('skipped', 'iOS', 'the widget extension follows `tauri ios init`')];
36
73
  return [step('skipped', 'iOS', 'no src-tauri/gen/apple yet: run `tauri ios init`, then run setup again')];
37
74
  }
38
75
  const project = readProject(yaml);
package/cli/main.d.mts ADDED
@@ -0,0 +1,12 @@
1
+ /** Where the command runs and writes. A member left out or undefined is the process's own. */
2
+ export interface CommandIo {
3
+ readonly cwd?: string | undefined;
4
+ readonly env?: NodeJS.ProcessEnv | undefined;
5
+ readonly platform?: NodeJS.Platform | undefined;
6
+ readonly out?: ((text: string) => void) | undefined;
7
+ readonly err?: ((text: string) => void) | undefined;
8
+ }
9
+ /** 0: done. 1: something is left to do, or setup could not start. 2: the command line is not one it takes. */
10
+ export type ExitStatus = 0 | 1 | 2;
11
+ /** Runs the command and returns its exit status: 0 done, 1 something left to do or an error, 2 usage. */
12
+ export declare function main(argv: readonly string[], { cwd, env, platform, out, err, }?: CommandIo): ExitStatus;
package/cli/main.mjs CHANGED
@@ -1,12 +1,12 @@
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
- const USAGE = `Usage: npx tauri-plugin-live-activity setup [--dry-run] [--ios-only] [--font <file>]... [--asset <file>]... [--app-group[=<id>]] [--small-family]
4
+ const USAGE = `Usage: npx tauri-plugin-live-activity setup [--dry-run] [--ios-only] [--font <file>]... [--asset <file>]... [--app-group[=<id>]] [--small-family] [--no-ios-init]
5
5
 
6
6
  Run it in the folder of a Tauri 2 app after \`cargo add\` and \`npm i\`. It grants the plugin's
7
7
  permissions, sets the Android minimum to API 26 and, on a Mac, adds the Live Activity widget
8
- extension to src-tauri/gen/apple. Run it after \`tauri ios init\`, and again if that folder is
9
- ever made from scratch.
8
+ extension to src-tauri/gen/apple, which it makes first with the app's \`tauri ios init\` when it
9
+ is not there. A later run leaves what is set up as it is and does what is missing.
10
10
 
11
11
  --dry-run show what would change, and write nothing
12
12
  --ios-only do only the iOS part: leave the capabilities and tauri.conf.json alone
@@ -17,8 +17,9 @@ ever made from scratch.
17
17
  named, so writeImage can share images; later runs keep it
18
18
  --small-family draw a layout's small region on a paired Apple Watch and in CarPlay, and there the
19
19
  compact parts of a layout without one; later runs keep it
20
+ --no-ios-init leave an app without src-tauri/gen/apple as it is instead of running \`tauri ios init\`
20
21
  `;
21
- const FLAGS = { '--dry-run': 'dryRun', '--ios-only': 'iosOnly', '--small-family': 'smallFamily' };
22
+ const FLAGS = { '--dry-run': 'dryRun', '--ios-only': 'iosOnly', '--small-family': 'smallFamily', '--no-ios-init': 'noIosInit' };
22
23
  const FILES = { '--font': 'fonts', '--asset': 'assets' };
23
24
  const HELP = new Set(['help', '--help', '-h']);
24
25
  const isFlag = (name) => Object.hasOwn(FLAGS, name);
@@ -0,0 +1,19 @@
1
+ /** The SHA-256 of each template as a release of the plugin wrote it into the widget folder. */
2
+ export declare const RELEASED: {
3
+ 'LiveActivityActionIntent.swift': string[];
4
+ 'LiveActivityCustomRegistry.swift': string[];
5
+ 'LiveActivityWidget.swift': string[];
6
+ };
7
+ /** A file that a release of the plugin wrote into the widget folder. */
8
+ export type ReleasedFile = keyof typeof RELEASED;
9
+ /** Files that only the plugin's own Swift needed. */
10
+ export declare const RETIRED: readonly ReleasedFile[];
11
+ /** The Swift modules of the plugin before 0.4; a widget file that imports one no longer builds. */
12
+ export declare const OLD_MODULES: RegExp;
13
+ /** True when `text` is the file `name` exactly as a release wrote it. */
14
+ export declare function released(name: ReleasedFile, text: string): boolean;
15
+ /**
16
+ * The app's custom views file with activitykit's names: the Objective-C name, the registry, the view and props types,
17
+ * and `import ActivityKitViews`. The app's views stay as they are. Undefined when the file has none of 0.3's names.
18
+ */
19
+ export declare function renameCustomViews(text: string): string | undefined;
@@ -0,0 +1,17 @@
1
+ /**
2
+ * What `setTrueKey` found or did: `present` (already true), `added` (with the new `text`), `false` or `other` (the
3
+ * key has another value, left as it is) or `unreadable`.
4
+ */
5
+ export type TrueKeyResult = {
6
+ readonly status: 'added';
7
+ readonly text: string;
8
+ } | {
9
+ readonly status: 'present' | 'false' | 'other' | 'unreadable';
10
+ };
11
+ /** A new plist whose root dictionary holds `key` = true. */
12
+ export declare function newPlist(key: string): string;
13
+ /**
14
+ * Makes `key` true in the root dictionary of an XML plist. Status: `present` (already true), `added`
15
+ * (with the new `text`), `false` or `other` (the key has another value, left as it is) or `unreadable`.
16
+ */
17
+ export declare function setTrueKey(text: string, key: string): TrueKeyResult;
@@ -0,0 +1,2 @@
1
+ import type { SetupResult } from './setup.mjs';
2
+ export declare function formatReport({ dryRun, version, steps, notes }: SetupResult): string;
@@ -0,0 +1,99 @@
1
+ import type { StepReport } from './steps.mjs';
2
+ import type { WidgetFiles } from './widget-files.mjs';
3
+ export { SetupError } from './steps.mjs';
4
+ export declare const CRATE = "tauri-plugin-live-activity";
5
+ /** The crate whose Swift package the widget extension and the app target link. */
6
+ export declare const ACTIVITYKIT = "activitykit";
7
+ /**
8
+ * `default` reads; the others allow the commands that change activities, and the three that ask the person: with
9
+ * Android's dialog, in its setting for exact alarms, and in its screen of Live Updates.
10
+ */
11
+ export declare const PERMISSIONS: readonly string[];
12
+ /** The version of this npm package. */
13
+ export declare const NPM_VERSION: string;
14
+ /**
15
+ * tauri.conf.json as parsed. The file is the app's: the members that setup reads are named here, and each is checked
16
+ * where it is read.
17
+ */
18
+ export interface TauriConfig {
19
+ readonly identifier?: unknown;
20
+ readonly version?: unknown;
21
+ readonly bundle?: unknown;
22
+ readonly [member: string]: unknown;
23
+ }
24
+ /** The app that setup works on: its src-tauri folder, and its tauri.conf.json as text and as parsed. */
25
+ export interface App {
26
+ readonly srcTauri: string;
27
+ readonly configPath: string;
28
+ readonly configText: string;
29
+ readonly config: TauriConfig;
30
+ }
31
+ /** A crate of the app's dependency graph: its version and the folder of its Cargo.toml. */
32
+ export interface Crate {
33
+ readonly version: string;
34
+ readonly dir: string;
35
+ }
36
+ /** The plugin's crate, and the activitykit crate it depends on. */
37
+ export interface Crates {
38
+ readonly plugin: Crate;
39
+ readonly activitykit: Crate;
40
+ }
41
+ /**
42
+ * What `setup` takes. Each member has a default, which a member left out or undefined takes: the folder, environment
43
+ * and platform of the process, and nothing asked for.
44
+ */
45
+ export interface SetupOptions {
46
+ /** The app's folder or its src-tauri folder. */
47
+ readonly cwd?: string | undefined;
48
+ readonly env?: NodeJS.ProcessEnv | undefined;
49
+ /** Reports the steps and writes nothing. */
50
+ readonly dryRun?: boolean | undefined;
51
+ /** Leaves the capabilities and tauri.conf.json alone. */
52
+ readonly iosOnly?: boolean | undefined;
53
+ readonly platform?: NodeJS.Platform | undefined;
54
+ /** Font files for the widget extension. */
55
+ readonly fonts?: readonly string[] | undefined;
56
+ /** Image files for the widget's asset catalog. */
57
+ readonly assets?: readonly string[] | undefined;
58
+ /** True for `group.<app identifier>`, or the name of the App Group. */
59
+ readonly appGroup?: boolean | string | undefined;
60
+ /** Has the widget draw a layout's small region. */
61
+ readonly smallFamily?: boolean | undefined;
62
+ /** Leaves an app without src-tauri/gen/apple as it is, where setup would run `tauri ios init`. */
63
+ readonly noIosInit?: boolean | undefined;
64
+ }
65
+ /** What every step is given: the app, the crates, and what the person asked for. */
66
+ export interface SetupContext extends App, Crates {
67
+ readonly env: NodeJS.ProcessEnv;
68
+ readonly platform: NodeJS.Platform;
69
+ readonly files: WidgetFiles;
70
+ readonly appGroup: boolean | string | undefined;
71
+ readonly smallFamily: boolean;
72
+ /** A path as the report shows it. */
73
+ readonly show: (path: string) => string;
74
+ }
75
+ /** A line for the person after the steps: `register` is something left to do, `version` a mismatch to know of. */
76
+ export interface Note {
77
+ readonly kind: 'register' | 'version';
78
+ readonly text: string;
79
+ }
80
+ /** What `setup` answers: the steps with their status, and notes for the person who runs it. */
81
+ export interface SetupResult {
82
+ readonly dryRun: boolean;
83
+ /** The version of the plugin's crate. */
84
+ readonly version: string;
85
+ readonly steps: readonly StepReport[];
86
+ readonly notes: readonly Note[];
87
+ }
88
+ /**
89
+ * Sets up the app in `cwd` (its folder or its src-tauri folder) and returns the steps with their
90
+ * status, and notes for the person who runs it. `fonts` and `assets` are files for the widget
91
+ * extension; `appGroup` is true or the name of an App Group; with `smallFamily` the widget draws a layout's small
92
+ * region. Throws SetupError when it cannot start.
93
+ */
94
+ export declare function setup({ cwd, env, dryRun, iosOnly, platform, fonts, assets, appGroup, smallFamily, noIosInit, }?: SetupOptions): SetupResult;
95
+ /**
96
+ * The plugin crate's version and the folder of the activitykit crate it depends on, from `cargo metadata`: the widget
97
+ * extension and the app target link activitykit's Swift package, which lies in that folder.
98
+ */
99
+ export declare function findCrates({ srcTauri }: Pick<App, 'srcTauri'>, env: NodeJS.ProcessEnv): Crates;
package/cli/setup.mjs CHANGED
@@ -3,7 +3,7 @@
3
3
  import { spawnSync } from 'node:child_process';
4
4
  import { existsSync, readFileSync, readdirSync } from 'node:fs';
5
5
  import { dirname, join } from 'node:path';
6
- import { iosSteps } from './ios.mjs';
6
+ import { iosInitStep, iosSteps } from './ios.mjs';
7
7
  import { SetupError, display, errorCode, isList, isRecord, jsonLike, member, parseJson, readText, step, tail, writeFile, } from './steps.mjs';
8
8
  import { widgetFiles } from './widget-files.mjs';
9
9
  export { SetupError } from './steps.mjs';
@@ -23,22 +23,32 @@ export const PERMISSIONS = [
23
23
  // The plugin's Android library needs API 26: Tauri's Jackson runtime fails below it.
24
24
  const MIN_SDK = 26;
25
25
  const NPM_MANIFEST = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8'));
26
- const NPM_VERSION = String(member(NPM_MANIFEST, 'version'));
26
+ /** The version of this npm package. */
27
+ export const NPM_VERSION = String(member(NPM_MANIFEST, 'version'));
27
28
  /**
28
29
  * Sets up the app in `cwd` (its folder or its src-tauri folder) and returns the steps with their
29
30
  * status, and notes for the person who runs it. `fonts` and `assets` are files for the widget
30
31
  * extension; `appGroup` is true or the name of an App Group; with `smallFamily` the widget draws a layout's small
31
32
  * region. Throws SetupError when it cannot start.
32
33
  */
33
- export function setup({ cwd = process.cwd(), env = process.env, dryRun = false, iosOnly = false, platform = process.platform, fonts = [], assets = [], appGroup = undefined, smallFamily = false, } = {}) {
34
+ export function setup({ cwd = process.cwd(), env = process.env, dryRun = false, iosOnly = false, platform = process.platform, fonts = [], assets = [], appGroup = undefined, smallFamily = false, noIosInit = false, } = {}) {
34
35
  const files = widgetFiles(cwd, { fonts, assets });
35
36
  const app = findApp(cwd);
36
37
  const { plugin, activitykit } = findCrates(app, env);
37
38
  const context = { ...app, plugin, activitykit, env, platform, files, appGroup, smallFamily, show: path => display(cwd, path) };
38
- const planned = [...(iosOnly ? [] : [capabilitiesStep(context), ...androidSteps(context)]), ...iosSteps(context)];
39
+ // Without an Xcode project the iOS steps have nothing to read: `tauri ios init` runs first, before they are planned.
40
+ const init = noIosInit ? undefined : iosInitStep(context);
41
+ const initialized = init && !dryRun ? withoutEffect(apply(init)) : init;
42
+ const planned = [
43
+ ...(iosOnly ? [] : [capabilitiesStep(context), ...androidSteps(context)]),
44
+ ...(initialized ? [initialized] : []),
45
+ ...iosSteps(context, { initPlanned: dryRun && init !== undefined }),
46
+ ];
39
47
  const steps = dryRun ? planned : planned.map(apply);
40
48
  return { dryRun, version: plugin.version, steps: steps.map(({ effect, ...rest }) => rest), notes: notes(context) };
41
49
  }
50
+ /** A step whose effect has run, as it is reported. */
51
+ const withoutEffect = ({ effect, ...report }) => report;
42
52
  function apply(planned) {
43
53
  if (!planned.effect)
44
54
  return planned;
@@ -0,0 +1,44 @@
1
+ /** A problem that stops setup, with a message for the person who ran it. */
2
+ export declare class SetupError extends Error {
3
+ name: string;
4
+ }
5
+ /** What a step did, or would do in a dry run. `todo` is left to the person; `unchanged` needed nothing. */
6
+ export type StepStatus = 'created' | 'updated' | 'removed' | 'ran' | 'kept' | 'skipped' | 'todo' | 'unchanged';
7
+ /** A step as setup reports it: its status, the path or thing it is about, and a detail for the person. */
8
+ export interface StepReport {
9
+ readonly status: StepStatus;
10
+ readonly path: string;
11
+ readonly detail: string;
12
+ }
13
+ /** Writes a planned step. It answers the step to report in its place when the plan did not hold. */
14
+ export type Effect = () => StepReport | undefined;
15
+ /** A step as planned, with the effect that writes it when there is something to write. */
16
+ export interface PlannedStep extends StepReport {
17
+ readonly effect?: Effect;
18
+ }
19
+ /** Status: created, updated, removed, ran, kept, skipped, todo or unchanged. */
20
+ export declare function step(status: StepStatus, path: string, detail?: string, effect?: Effect): PlannedStep;
21
+ /** The `code` of an error, as the errors of Node's file system and of a process that could not start carry one. */
22
+ export declare function errorCode(error: unknown): string | undefined;
23
+ /** The text of the file at `path`, or undefined when there is no such file. */
24
+ export declare function readText(path: string | URL): string | undefined;
25
+ /** What `text` holds as JSON, or undefined when it is not JSON. The value is checked where it is read. */
26
+ export declare function parseJson(text: string): unknown;
27
+ /** True for a JSON object: a value with members by name. A list is none. */
28
+ export declare function isRecord(value: unknown): value is Readonly<Record<string, unknown>>;
29
+ /** True for a JSON array. */
30
+ export declare function isList(value: unknown): value is readonly unknown[];
31
+ /** The member at `keys` of parsed JSON: undefined where a value on the way is no object, or has no such member. */
32
+ export declare function member(value: unknown, ...keys: readonly string[]): unknown;
33
+ /** An effect that writes `text` to `path`, creating its folder. */
34
+ export declare function writeFile(path: string, text: string): Effect;
35
+ /** JSON in the indent of the original text, with a final newline when it had one. */
36
+ export declare function jsonLike(original: string, value: unknown): string;
37
+ /** The last lines of a tool's output, on one line. */
38
+ export declare function tail(text?: string): string;
39
+ /** A path for messages: relative inside the folder setup runs in, otherwise absolute with `~` for home. */
40
+ export declare function display(cwd: string, path: string): string;
41
+ /** The executable `name` on the PATH of `env`, or undefined. */
42
+ export declare function which(name: string, env: NodeJS.ProcessEnv): string | undefined;
43
+ /** Whether `path` is a file this process may run. */
44
+ export declare function isExecutable(path: string): boolean;
package/cli/steps.mjs CHANGED
@@ -87,7 +87,8 @@ export function which(name, env) {
87
87
  }
88
88
  return undefined;
89
89
  }
90
- function isExecutable(path) {
90
+ /** Whether `path` is a file this process may run. */
91
+ export function isExecutable(path) {
91
92
  try {
92
93
  accessSync(path, constants.X_OK);
93
94
  return statSync(path).isFile();
@@ -0,0 +1,46 @@
1
+ import type { SetupContext, SetupOptions } from './setup.mjs';
2
+ import type { PlannedStep } from './steps.mjs';
3
+ export declare const FONTS = "Fonts";
4
+ export declare const CATALOG = "Assets.xcassets";
5
+ /** A file named on the command line: where it is, its name in the widget, and its extension in lower case. */
6
+ export interface WidgetFile {
7
+ readonly source: string;
8
+ readonly file: string;
9
+ readonly kind: string;
10
+ }
11
+ /** The scale of a bitmap that is one of several for its asset name. */
12
+ export type ImageScale = '2x' | '3x';
13
+ /** An image for the asset catalog: the asset name a layout's `image()` takes, and the scale of a scaled bitmap. */
14
+ export interface WidgetImage extends WidgetFile {
15
+ readonly name: string;
16
+ readonly scale: ImageScale | undefined;
17
+ }
18
+ /** The fonts and images that a run of setup puts into the widget extension. */
19
+ export interface WidgetFiles {
20
+ readonly fonts: readonly WidgetFile[];
21
+ readonly assets: readonly WidgetImage[];
22
+ }
23
+ /** The names of a font that a style's `fontFamily` takes. */
24
+ export interface FontNames {
25
+ readonly family: string | undefined;
26
+ readonly postScript: string | undefined;
27
+ }
28
+ /** What the steps of this module read of setup's context. */
29
+ type FileContext = Pick<SetupContext, 'files' | 'show'>;
30
+ /**
31
+ * The fonts and images named on the command line, checked before anything is written: each exists, is a
32
+ * file of a kind the widget can use and has a name the bundle and a layout can carry.
33
+ */
34
+ export declare function widgetFiles(cwd: string, { fonts, assets }: Pick<SetupOptions, 'fonts' | 'assets'>): WidgetFiles;
35
+ /** The steps that copy the fonts into the widget's Fonts folder. */
36
+ export declare function fontSteps({ files, show }: FileContext, widget: string): PlannedStep[];
37
+ /** The font files the widget bundles after this run: those in its Fonts folder and those being copied there. */
38
+ export declare function bundledFonts({ files }: Pick<SetupContext, 'files'>, widget: string): string[];
39
+ /** The steps that put the images into the widget's asset catalog, one image set per asset name. */
40
+ export declare function assetSteps({ files, show }: FileContext, widget: string): PlannedStep[];
41
+ /**
42
+ * The family and PostScript names in the name table of a TrueType or OpenType font, for the report: they are
43
+ * what a style's `fontFamily` takes. Undefined for a collection or a file it cannot read.
44
+ */
45
+ export declare function fontNames(bytes: Buffer): FontNames | undefined;
46
+ export {};
@@ -0,0 +1,77 @@
1
+ export declare const SPEC_FILE = "live-activity.yml";
2
+ export declare const WIDGET = "LiveActivityWidget";
3
+ /** The extension's entitlements, next to its folder so that XcodeGen does not take them for a source. */
4
+ export declare const WIDGET_ENTITLEMENTS = "LiveActivityWidget.entitlements";
5
+ /** The Info.plist key of the extension that names the App Group, for activitykit and the widget. */
6
+ export declare const APP_GROUP_KEY = "ActivityKitAppGroup";
7
+ /** The Info.plist key of the extension with which activitykit's widget draws the small family. */
8
+ export declare const SMALL_FAMILY_KEY = "ActivityKitSmallFamily";
9
+ /**
10
+ * The files of the widget folder that the app target compiles too. The custom views file is Swift, so the app target
11
+ * compiles Swift, which Xcode needs to take the App Intents metadata of the linked ActivityKitIntent product.
12
+ */
13
+ export declare const APP_SOURCES: readonly string[];
14
+ /** What setup reads of Tauri's XcodeGen spec. */
15
+ export interface XcodeProject {
16
+ readonly name: string | undefined;
17
+ /** Tauri's app target, `<name>_iOS`, when the spec has it. */
18
+ readonly appTarget: string | undefined;
19
+ /** The path of the app target's entitlements, when the spec names one. */
20
+ readonly entitlements: string | undefined;
21
+ readonly settingGroups: readonly (string | undefined)[];
22
+ /** The first bundle identifier of the spec. */
23
+ readonly bundleId: string | undefined;
24
+ /** A target that already is a widget extension. */
25
+ readonly widget: string | undefined;
26
+ }
27
+ /**
28
+ * What `addInclude` did: `added` (with the new `text`), `present`, or `unsupported` when the list has a form it does
29
+ * not edit.
30
+ */
31
+ export interface IncludeResult {
32
+ readonly status: 'added' | 'present' | 'unsupported';
33
+ readonly text: string;
34
+ }
35
+ /** What the included spec is written from. */
36
+ export interface WidgetSpec {
37
+ readonly pluginVersion: string;
38
+ /** The folder of activitykit's Swift package. */
39
+ readonly packagePath: string;
40
+ readonly appTarget: string;
41
+ /** The bundle identifier of the widget extension. */
42
+ readonly bundleId: string;
43
+ /** The app's version, which the extension's has to match. Without one the extension's Info.plist names none. */
44
+ readonly appVersion?: string;
45
+ readonly buildVersion?: string;
46
+ /** Whether the spec has Tauri's `app` setting group, which the extension then takes too. */
47
+ readonly teamGroup: boolean;
48
+ readonly fonts?: readonly string[];
49
+ readonly appGroup: string | undefined;
50
+ /** The path of the app target's entitlements. */
51
+ readonly appEntitlements: string;
52
+ readonly smallFamily?: boolean;
53
+ }
54
+ /**
55
+ * The project name, Tauri's app target (`<name>_iOS`) when it exists, the path of its entitlements, the
56
+ * setting groups, the first bundle identifier and a target that already is a widget extension.
57
+ */
58
+ export declare function readProject(text: string): XcodeProject;
59
+ /** The App Group of a spec that setup wrote, this version or 0.2 and 0.3, so that a later run keeps it. */
60
+ export declare function appGroupOf(spec?: string): string | undefined;
61
+ /** Whether a spec that setup wrote has the widget draw the small family, so that a later run keeps that. */
62
+ export declare function drawsSmallFamily(spec?: string): boolean;
63
+ /**
64
+ * Adds `file` to the spec's `include` list. Status: `added` (with the new `text`), `present`, or
65
+ * `unsupported` when the list has a form this does not edit.
66
+ */
67
+ export declare function addInclude(text: string, file: string): IncludeResult;
68
+ /** True when the spec is as setup wrote it: its digest line matches the rest of the file. */
69
+ export declare function writtenBySetup(text: string): boolean;
70
+ /**
71
+ * The included spec: activitykit's Swift package, the widget extension target, and in the app target the extension,
72
+ * the button intent and the custom views. `fonts` go to the extension's UIAppFonts. An `appGroup` goes to the
73
+ * entitlements of both targets, the app's at `appEntitlements`, and to the extension's Info.plist, where activitykit
74
+ * and the widget read it. With `smallFamily` the extension's Info.plist says that the widget draws the small family,
75
+ * for a paired Apple Watch and CarPlay. XcodeGen merges the app target's part into the target of project.yml.
76
+ */
77
+ export declare function widgetSpec({ pluginVersion, packagePath, appTarget, bundleId, appVersion, buildVersion, teamGroup, fonts, appGroup, appEntitlements, smallFamily, }: WidgetSpec): string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tauri-plugin-live-activity",
3
- "version": "1.0.0",
3
+ "version": "1.2.0",
4
4
  "description": "Tauri 2 plugin for iOS Live Activities (ActivityKit and Dynamic Island) and Android Live Updates with ongoing notification fallback",
5
5
  "author": "1eedaegon",
6
6
  "type": "module",
@@ -21,10 +21,14 @@
21
21
  "./jsx/jsx-runtime": { "types": "./dist-js/jsx/jsx-runtime.d.ts", "import": "./dist-js/jsx/jsx-runtime.js" },
22
22
  "./jsx/jsx-dev-runtime": { "types": "./dist-js/jsx/jsx-dev-runtime.d.ts", "import": "./dist-js/jsx/jsx-dev-runtime.js" },
23
23
  "./react": { "types": "./dist-js/react/index.d.ts", "import": "./dist-js/react/index.js" },
24
+ "./setup": {
25
+ "types": "./cli/api.d.mts",
26
+ "import": "./cli/api.mjs"
27
+ },
24
28
  "./package.json": "./package.json"
25
29
  },
26
30
  "bin": { "tauri-plugin-live-activity": "cli/bin.mjs" },
27
- "files": ["dist-js", "cli/*.mjs", "cli/templates", "README.md", "README.ko.md", "LICENSE", "LICENSE-APACHE", "LICENSE-MIT"],
31
+ "files": ["dist-js", "cli/*.mjs", "cli/*.d.mts", "cli/templates", "README.md", "README.ko.md", "LICENSE", "LICENSE-APACHE", "LICENSE-MIT"],
28
32
  "publishConfig": { "access": "public", "tag": "next" },
29
33
  "engines": {
30
34
  "node": ">=22.12.0"