andysu-capacitor 0.0.0-stage → 0.1.98

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.
@@ -0,0 +1,25 @@
1
+ // Capacitor plugin. In an app it is linked by `npx cap sync`; in the AndySU repo it compiles
2
+ // against :api. The host provides the one runtime copy of the API (compileOnly).
3
+ apply plugin: "com.android.library"
4
+ def andysuVersion = project.findProperty("andysuVersion") ?: "0.1.98"
5
+ android {
6
+ namespace "com.andysu.capacitor"
7
+ compileSdk 36
8
+ defaultConfig { minSdk 24 }
9
+ compileOptions {
10
+ sourceCompatibility JavaVersion.VERSION_17
11
+ targetCompatibility JavaVersion.VERSION_17
12
+ }
13
+ }
14
+ dependencies {
15
+ if (findProject(":capacitor-android") != null) {
16
+ implementation project(":capacitor-android")
17
+ } else {
18
+ compileOnly "com.capacitorjs:core:8.6.0"
19
+ }
20
+ if (findProject(":api") != null) {
21
+ compileOnly project(":api")
22
+ } else {
23
+ compileOnly "io.github.dixonsolutions.andysu:api:${andysuVersion}"
24
+ }
25
+ }
@@ -0,0 +1,93 @@
1
+ package com.andysu.capacitor;
2
+
3
+ import com.andysu.api.Host;
4
+ import com.andysu.api.HostApi;
5
+ import com.getcapacitor.JSObject;
6
+ import com.getcapacitor.Plugin;
7
+ import com.getcapacitor.PluginCall;
8
+ import com.getcapacitor.PluginMethod;
9
+ import com.getcapacitor.annotation.CapacitorPlugin;
10
+
11
+ import org.json.JSONException;
12
+
13
+ /** Capacitor bridge to the AndySU host (com.andysu.api.Host). */
14
+ @CapacitorPlugin(name = "AndySU")
15
+ public class AndySUPlugin extends Plugin {
16
+ private static HostApi host() {
17
+ return Host.current();
18
+ }
19
+
20
+ @PluginMethod
21
+ public void info(PluginCall call) {
22
+ HostApi h = host();
23
+ JSObject o = new JSObject();
24
+ o.put("present", h != null);
25
+ if (h != null) {
26
+ o.put("apiLevel", h.apiLevel());
27
+ o.put("version", h.version());
28
+ o.put("isFactory", h.isFactory());
29
+ o.put("slotDir", h.slotDir().getPath());
30
+ }
31
+ call.resolve(o);
32
+ }
33
+
34
+ @PluginMethod
35
+ public void status(PluginCall call) {
36
+ HostApi h = host();
37
+ try {
38
+ call.resolve(new JSObject(h == null ? "{\"state\":\"idle\"}" : h.updates().status()));
39
+ } catch (JSONException e) {
40
+ call.reject(e.getMessage());
41
+ }
42
+ }
43
+
44
+ @PluginMethod
45
+ public void checkNow(PluginCall call) {
46
+ if (host() != null) host().updates().checkNow();
47
+ call.resolve();
48
+ }
49
+
50
+ @PluginMethod
51
+ public void applyNow(PluginCall call) {
52
+ if (host() != null) host().updates().applyNow();
53
+ call.resolve();
54
+ }
55
+
56
+ @PluginMethod
57
+ public void restartNow(PluginCall call) {
58
+ if (host() != null) host().updates().restartNow();
59
+ call.resolve();
60
+ }
61
+
62
+ @PluginMethod
63
+ public void markHealthy(PluginCall call) {
64
+ if (host() != null) host().markHealthy();
65
+ call.resolve();
66
+ }
67
+
68
+ @PluginMethod
69
+ public void setApplyPolicy(PluginCall call) {
70
+ if (host() != null) host().updates().setApplyPolicy(call.getString("policy"));
71
+ call.resolve();
72
+ }
73
+
74
+ @PluginMethod
75
+ public void applyPolicy(PluginCall call) {
76
+ JSObject o = new JSObject();
77
+ o.put("policy", host() == null ? "live" : host().updates().applyPolicy());
78
+ call.resolve(o);
79
+ }
80
+
81
+ @Override
82
+ public void load() {
83
+ HostApi h = host();
84
+ if (h != null) {
85
+ h.updates().setListener(json -> {
86
+ try {
87
+ notifyListeners("status", new JSObject(json));
88
+ } catch (JSONException ignored) {
89
+ }
90
+ });
91
+ }
92
+ }
93
+ }
@@ -0,0 +1,29 @@
1
+ import { PluginListenerHandle } from '@capacitor/core';
2
+ export type ApplyPolicy = 'live' | 'restart' | 'next_start';
3
+ export interface Status {
4
+ state: string;
5
+ release?: string;
6
+ [k: string]: unknown;
7
+ }
8
+ export interface AndySUPlugin {
9
+ info(): Promise<{
10
+ present: boolean;
11
+ apiLevel?: number;
12
+ version?: string;
13
+ isFactory?: boolean;
14
+ slotDir?: string;
15
+ }>;
16
+ status(): Promise<Status>;
17
+ checkNow(): Promise<void>;
18
+ applyNow(): Promise<void>;
19
+ restartNow(): Promise<void>;
20
+ markHealthy(): Promise<void>;
21
+ setApplyPolicy(o: {
22
+ policy: ApplyPolicy | null;
23
+ }): Promise<void>;
24
+ applyPolicy(): Promise<{
25
+ policy: ApplyPolicy;
26
+ }>;
27
+ addListener(event: 'status', cb: (s: Status) => void): Promise<PluginListenerHandle>;
28
+ }
29
+ export declare const AndySU: AndySUPlugin;
package/dist/index.js ADDED
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AndySU = void 0;
4
+ const core_1 = require("@capacitor/core");
5
+ /** On platforms without AndySU every call resolves with neutral values. */
6
+ const web = {
7
+ info: async () => ({ present: false }),
8
+ status: async () => ({ state: 'idle' }),
9
+ checkNow: async () => { },
10
+ applyNow: async () => { },
11
+ restartNow: async () => { },
12
+ markHealthy: async () => { },
13
+ setApplyPolicy: async () => { },
14
+ applyPolicy: async () => ({ policy: 'live' }),
15
+ addListener: async () => ({ remove: async () => { } }),
16
+ };
17
+ exports.AndySU = (0, core_1.registerPlugin)('AndySU', { web });
package/package.json CHANGED
@@ -1,6 +1,35 @@
1
1
  {
2
2
  "name": "andysu-capacitor",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.98",
4
+ "description": "AndySU self-updates for Capacitor and Cordova apps on Android; web assets update hot",
5
+ "license": "Apache-2.0",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/dixonSolutions/AndySU",
9
+ "directory": "bindings/capacitor"
10
+ },
11
+ "main": "dist/index.js",
12
+ "types": "dist/index.d.ts",
13
+ "files": [
14
+ "dist",
15
+ "src",
16
+ "android/build.gradle",
17
+ "android/src",
18
+ "README.md"
19
+ ],
20
+ "capacitor": {
21
+ "android": {
22
+ "src": "android"
23
+ }
24
+ },
25
+ "scripts": {
26
+ "build": "tsc -p tsconfig.json",
27
+ "test": "node test/smoke.js"
28
+ },
29
+ "peerDependencies": {
30
+ "@capacitor/core": ">=5"
31
+ },
32
+ "devDependencies": {
33
+ "typescript": "^5.6.0"
34
+ }
35
+ }
package/src/index.ts ADDED
@@ -0,0 +1,32 @@
1
+ import { registerPlugin, PluginListenerHandle } from '@capacitor/core';
2
+
3
+ export type ApplyPolicy = 'live' | 'restart' | 'next_start';
4
+
5
+ export interface Status { state: string; release?: string; [k: string]: unknown }
6
+
7
+ export interface AndySUPlugin {
8
+ info(): Promise<{ present: boolean; apiLevel?: number; version?: string; isFactory?: boolean; slotDir?: string }>;
9
+ status(): Promise<Status>;
10
+ checkNow(): Promise<void>;
11
+ applyNow(): Promise<void>;
12
+ restartNow(): Promise<void>;
13
+ markHealthy(): Promise<void>;
14
+ setApplyPolicy(o: { policy: ApplyPolicy | null }): Promise<void>;
15
+ applyPolicy(): Promise<{ policy: ApplyPolicy }>;
16
+ addListener(event: 'status', cb: (s: Status) => void): Promise<PluginListenerHandle>;
17
+ }
18
+
19
+ /** On platforms without AndySU every call resolves with neutral values. */
20
+ const web: AndySUPlugin = {
21
+ info: async () => ({ present: false }),
22
+ status: async () => ({ state: 'idle' }),
23
+ checkNow: async () => {},
24
+ applyNow: async () => {},
25
+ restartNow: async () => {},
26
+ markHealthy: async () => {},
27
+ setApplyPolicy: async () => {},
28
+ applyPolicy: async () => ({ policy: 'live' }),
29
+ addListener: async () => ({ remove: async () => {} }),
30
+ };
31
+
32
+ export const AndySU = registerPlugin<AndySUPlugin>('AndySU', { web });
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.