ink-framework-lightos 0.0.0-stage → 0.1.0-alpha.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Vandam Dinh
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,14 @@
1
+ {
2
+ "version": 1,
3
+ "modules": {
4
+ "src/index.ts": [
5
+ "light-sdk"
6
+ ],
7
+ "src/ringtone.ts": [
8
+ "light-sdk-ringtone"
9
+ ],
10
+ "src/push.ts": [
11
+ "light-sdk-push"
12
+ ]
13
+ }
14
+ }
package/package.json CHANGED
@@ -1,6 +1,24 @@
1
1
  {
2
2
  "name": "ink-framework-lightos",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0-alpha.2",
4
+ "exports": {
5
+ ".": "./src/index.ts",
6
+ "./ringtone": "./src/ringtone.ts",
7
+ "./push": "./src/push.ts"
8
+ },
9
+ "peerDependencies": {
10
+ "ink": "npm:ink-framework@0.1.0-alpha.2",
11
+ "react": "19.2.8"
12
+ },
13
+ "license": "MIT",
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "git+https://github.com/No-Scrolling/ink.git",
17
+ "directory": "packages/lightos"
18
+ },
19
+ "files": [
20
+ "src",
21
+ "*.json",
22
+ "*.ts"
23
+ ]
24
+ }
package/src/index.ts ADDED
@@ -0,0 +1,62 @@
1
+ import { callNative, NativeError } from "ink/native";
2
+
3
+ export type Permission = "camera" | "microphone" | "location-approximate" | "location-precise" | "notifications" | "photos" | "videos" | "photos-and-videos" | "audio-files";
4
+ export type PermissionStatus = "granted" | "denied" | "blocked";
5
+ export interface HostPreferences { hapticsEnabled: boolean }
6
+ export interface KeyboardOptions {
7
+ emojis: string | null;
8
+ displayVoice: boolean;
9
+ enableKeyAnimation: boolean;
10
+ swipeEnabled: boolean | null;
11
+ }
12
+ async function permission(operation: string, name: Permission, signal?: AbortSignal): Promise<PermissionStatus> {
13
+ const value = await callNative("permissions", operation, { permission: name }, { timeoutMs: 120_000, signal });
14
+ if (value !== "granted" && value !== "denied" && value !== "blocked") throw new NativeError("protocol", "Invalid permission result");
15
+ return value;
16
+ }
17
+
18
+ export const lightos = {
19
+ async getPreferences(): Promise<HostPreferences> {
20
+ const value: unknown = JSON.parse(await callNative("light-sdk", "preferences", ""));
21
+ if (typeof value !== "object" || value === null || !("hapticsEnabled" in value)
22
+ || typeof value.hapticsEnabled !== "boolean") throw new NativeError("protocol", "Invalid host preferences");
23
+ return { hapticsEnabled: value.hapticsEnabled };
24
+ },
25
+ async getKeyboardOptions(): Promise<KeyboardOptions> {
26
+ const value: unknown = JSON.parse(await callNative("light-sdk", "keyboard-options", ""));
27
+ if (typeof value !== "object" || value === null
28
+ || !("displayVoice" in value) || typeof value.displayVoice !== "boolean"
29
+ || !("enableKeyAnimation" in value) || typeof value.enableKeyAnimation !== "boolean"
30
+ || ("emojisAsString" in value && value.emojisAsString !== null && typeof value.emojisAsString !== "string")
31
+ || ("swipeEnabled" in value && value.swipeEnabled !== null && typeof value.swipeEnabled !== "boolean")) {
32
+ throw new NativeError("protocol", "Invalid host keyboard options");
33
+ }
34
+ return {
35
+ emojis: "emojisAsString" in value && typeof value.emojisAsString === "string" ? value.emojisAsString : null,
36
+ displayVoice: value.displayVoice,
37
+ enableKeyAnimation: value.enableKeyAnimation,
38
+ swipeEnabled: "swipeEnabled" in value && typeof value.swipeEnabled === "boolean" ? value.swipeEnabled : null,
39
+ };
40
+ },
41
+ async getVersion(): Promise<string> {
42
+ const version = await callNative("light-sdk", "version", "");
43
+ if (!version.trim()) throw new NativeError("protocol", "Host returned an empty version");
44
+ return version;
45
+ },
46
+ getPermission(name: Permission, { signal }: { signal?: AbortSignal } = {}) { return permission("status", name, signal); },
47
+ requestPermission(name: Permission, { signal }: { signal?: AbortSignal } = {}) { return permission("request", name, signal); },
48
+ async canScheduleExact(): Promise<boolean> {
49
+ const value = await callNative("notifications", "exact-status", {});
50
+ if (value !== "granted" && value !== "denied") throw new NativeError("protocol", "Invalid exact alarm permission result");
51
+ return value === "granted";
52
+ },
53
+ async requestExactPermission(): Promise<void> {
54
+ await callNative("notifications", "request-exact-permission", {});
55
+ },
56
+ async openDialler({ phoneNumber }: { phoneNumber: string }): Promise<void> {
57
+ if (!phoneNumber.trim() || phoneNumber.length > 64 || /[\u0000-\u001f\u007f-\u009f]/.test(phoneNumber)) {
58
+ throw new TypeError("Phone number must contain 1–64 characters without control characters");
59
+ }
60
+ await callNative("light-sdk", "open-dialler", { phoneNumber });
61
+ },
62
+ };
package/src/push.ts ADDED
@@ -0,0 +1,122 @@
1
+ import { useEffect, useMemo, useRef, useState } from "react";
2
+ import { callNative, NativeError } from "ink/native";
3
+ import { attachNativeController } from "ink/native/controller";
4
+
5
+ export interface PushMessage {
6
+ id: string;
7
+ groupKey: string;
8
+ title: string;
9
+ body: string;
10
+ route: string;
11
+ receivedAt: number;
12
+ }
13
+ export interface PushState {
14
+ status: "idle" | "registering" | "synchronising" | "ready" | "error";
15
+ endpoint: string;
16
+ registeredAt: number;
17
+ openedKey: string;
18
+ messages: readonly PushMessage[];
19
+ error: Error | null;
20
+ }
21
+ export interface PushRegistration {
22
+ url: string;
23
+ bearerToken?: string;
24
+ encryptionKey?: string;
25
+ }
26
+ export interface PushOptions {
27
+ foregroundGroup?: string | null;
28
+ }
29
+ const initial: PushState = { status: "idle", endpoint: "", registeredAt: 0, openedKey: "", messages: [], error: null };
30
+ function fields(value: unknown) {
31
+ if (typeof value !== "object" || value === null) throw new NativeError("protocol", "Invalid push state");
32
+ return {
33
+ text(name: string) {
34
+ const field: unknown = Reflect.get(value, name);
35
+ if (typeof field !== "string") throw new NativeError("protocol", `Invalid push ${name}`);
36
+ return field;
37
+ },
38
+ time(name: string) {
39
+ const field: unknown = Reflect.get(value, name);
40
+ if (typeof field !== "number" || !Number.isSafeInteger(field) || field < 0) throw new NativeError("protocol", `Invalid push ${name}`);
41
+ return field;
42
+ },
43
+ };
44
+ }
45
+ function decodeMessage(value: unknown): PushMessage {
46
+ const item = fields(value);
47
+ return { id: item.text("id"), groupKey: item.text("groupKey"), title: item.text("title"), body: item.text("body"), route: item.text("route"), receivedAt: item.time("receivedAtMs") };
48
+ }
49
+ function decode(value: unknown): PushState {
50
+ const field = fields(value);
51
+ const status = field.text("status");
52
+ if (status !== "idle" && status !== "registering" && status !== "synchronising" && status !== "ready" && status !== "error") throw new NativeError("protocol", "Invalid push status");
53
+ if (typeof value !== "object" || value === null || !("messages" in value) || !Array.isArray(value.messages)) throw new NativeError("protocol", "Invalid push messages");
54
+ let error: Error | null = null;
55
+ if (status === "error") {
56
+ if (!("error" in value) || typeof value.error !== "object" || value.error === null) throw new NativeError("protocol", "Invalid push error");
57
+ const detail = fields(value.error);
58
+ error = new NativeError(detail.text("kind"), detail.text("message"), "retryable" in value.error && value.error.retryable === true);
59
+ }
60
+ return { status, endpoint: field.text("endpoint"), registeredAt: field.time("registeredAtMs"), openedKey: field.text("openedKey"), error,
61
+ messages: value.messages.map(decodeMessage) };
62
+ }
63
+
64
+ export function usePush({ foregroundGroup = null }: PushOptions = {}) {
65
+ const [state, setState] = useState(initial);
66
+ const [ready, setReady] = useState(false);
67
+ const controller = useRef<ReturnType<typeof attachNativeController> | null>(null);
68
+ useEffect(() => {
69
+ setState(initial);
70
+ setReady(false);
71
+ const fail = (error: unknown) => setState({ ...initial, status: "error", error: error instanceof Error ? error : new Error(String(error)) });
72
+ const attachment = attachNativeController("notifications", { kind: "light-push" }, value => {
73
+ try { setState(decode(value)); } catch (error) { fail(error); }
74
+ });
75
+ controller.current = attachment;
76
+ void attachment.ready.then(() => {
77
+ if (controller.current === attachment) setReady(true);
78
+ }, error => { if (controller.current === attachment) fail(error); });
79
+ return () => {
80
+ controller.current = null;
81
+ void attachment.dispose().catch(error => console.error("Could not release push inbox", error));
82
+ };
83
+ }, []);
84
+ useEffect(() => {
85
+ const attachment = controller.current;
86
+ if (!attachment) return;
87
+ let active = true;
88
+ void attachment.call("foreground", { groupKey: foregroundGroup }).catch(error => {
89
+ if (active) setState(current => ({ ...current, status: "error", error: error instanceof Error ? error : new Error(String(error)) }));
90
+ });
91
+ return () => { active = false; };
92
+ }, [foregroundGroup]);
93
+ const commands = useMemo(() => {
94
+ const call = async (operation: string, payload: unknown = {}) => {
95
+ if (!controller.current) throw new NativeError("unavailable", "Push inbox is not attached");
96
+ await controller.current.call(operation, payload);
97
+ };
98
+ return {
99
+ register: (options: PushRegistration) => call("register", options),
100
+ retry: () => call("retry"), unregister: () => call("unregister"),
101
+ dismiss: (groupKey: string) => call("dismiss", { groupKey }), clear: () => call("clear"),
102
+ notifyForeground: (groupKey: string) => call("foreground-message", { groupKey }),
103
+ };
104
+ }, []);
105
+ return { state, ready, ...commands };
106
+ }
107
+
108
+ export interface PushDelivery { messages: readonly PushMessage[]; cancelled: readonly string[] }
109
+ export function decodePushDelivery(value: unknown): PushDelivery {
110
+ if (typeof value !== "object" || value === null || !("messages" in value) || !Array.isArray(value.messages)
111
+ || !("cancelled" in value) || !Array.isArray(value.cancelled)) throw new TypeError("Invalid push delivery");
112
+ return {
113
+ messages: value.messages.map(decodeMessage),
114
+ cancelled: value.cancelled.map((key: unknown) => {
115
+ if (typeof key !== "string") throw new TypeError("Invalid cancelled push group");
116
+ return key;
117
+ }),
118
+ };
119
+ }
120
+ export async function setPushTask(task: { id: string } | null): Promise<void> {
121
+ await callNative("background", "set-push-task", { task: task?.id ?? null });
122
+ }
@@ -0,0 +1,17 @@
1
+ import { callNative, NativeError } from "ink/native";
2
+
3
+ export type RingtoneKind = "ringtone" | "notification" | "alarm";
4
+
5
+ export async function installRingtone(
6
+ source: string,
7
+ kind: RingtoneKind = "ringtone",
8
+ { signal }: { signal?: AbortSignal } = {},
9
+ ): Promise<void> {
10
+ const value: unknown = JSON.parse(await callNative("light-sdk", "install-ringtone", { source, kind }, { signal }));
11
+ if (typeof value !== "object" || value === null || !("status" in value)) throw new NativeError("protocol", "Invalid ringtone result");
12
+ if (value.status === "installed") return;
13
+ if (value.status !== "error" || !("error" in value) || typeof value.error !== "object" || value.error === null
14
+ || !("kind" in value.error) || typeof value.error.kind !== "string"
15
+ || !("message" in value.error) || typeof value.error.message !== "string") throw new NativeError("protocol", "Invalid ringtone error");
16
+ throw new NativeError(value.error.kind, value.error.message, "retryable" in value.error && value.error.retryable === true);
17
+ }
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.