@stacksjs/desktop 0.2.6 → 0.2.8
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/dist/autolaunch.d.ts +20 -0
- package/dist/hotkeys.d.ts +76 -0
- package/dist/index.d.ts +67 -0
- package/dist/index.js +877 -18
- package/dist/index.js.map +9 -4
- package/dist/power.d.ts +79 -0
- package/dist/preferences.d.ts +48 -0
- package/dist/timer.d.ts +128 -0
- package/package.json +1 -1
package/dist/power.d.ts
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import type { Subprocess } from 'bun';
|
|
2
|
+
/**
|
|
3
|
+
* Start preventing the system from sleeping.
|
|
4
|
+
*
|
|
5
|
+
* Spawns a `/usr/bin/caffeinate` process with the specified options.
|
|
6
|
+
* If caffeinate is already active, the previous instance is stopped first.
|
|
7
|
+
*
|
|
8
|
+
* @param options - Caffeinate configuration
|
|
9
|
+
* @returns A CaffeinateInstance for monitoring and controlling the session
|
|
10
|
+
*/
|
|
11
|
+
export declare function caffeinate(options?: CaffeinateOptions): CaffeinateInstance;
|
|
12
|
+
/**
|
|
13
|
+
* Stop caffeinate and allow the system to sleep normally.
|
|
14
|
+
*
|
|
15
|
+
* @param instance - Specific instance to stop. If omitted, stops the current active instance.
|
|
16
|
+
*/
|
|
17
|
+
export declare function decaffeinate(instance?: CaffeinateInstance): void;
|
|
18
|
+
/**
|
|
19
|
+
* Check if caffeinate is currently active.
|
|
20
|
+
*/
|
|
21
|
+
export declare function isCaffeinated(): boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Get the current caffeinate status.
|
|
24
|
+
*/
|
|
25
|
+
export declare function getCaffeinateStatus(): CaffeinateStatus;
|
|
26
|
+
/**
|
|
27
|
+
* Format remaining caffeinate time as a human-readable string.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```typescript
|
|
31
|
+
* formatRemainingTime(instance) // "25:30" or "∞"
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
export declare function formatRemainingTime(instance?: CaffeinateInstance | null): string;
|
|
35
|
+
/**
|
|
36
|
+
* Get a formatted description of the caffeinate duration.
|
|
37
|
+
*/
|
|
38
|
+
export declare function formatDuration(minutes: number): string;
|
|
39
|
+
// ============================================================================
|
|
40
|
+
// Types
|
|
41
|
+
// ============================================================================
|
|
42
|
+
export declare interface CaffeinateOptions {
|
|
43
|
+
duration?: number
|
|
44
|
+
preventDisplaySleep?: boolean
|
|
45
|
+
preventIdleSleep?: boolean
|
|
46
|
+
preventSystemSleep?: boolean
|
|
47
|
+
preventDiskSleep?: boolean
|
|
48
|
+
assertUserActivity?: boolean
|
|
49
|
+
}
|
|
50
|
+
export declare interface CaffeinateInstance {
|
|
51
|
+
readonly pid: number
|
|
52
|
+
readonly startedAt: Date
|
|
53
|
+
readonly endsAt: Date | null
|
|
54
|
+
readonly options: CaffeinateOptions
|
|
55
|
+
readonly isActive: boolean
|
|
56
|
+
readonly remainingMs: number | null
|
|
57
|
+
readonly elapsedMs: number
|
|
58
|
+
stop(): void
|
|
59
|
+
onExpire(handler: () => void): void
|
|
60
|
+
}
|
|
61
|
+
export declare interface CaffeinateStatus {
|
|
62
|
+
active: boolean
|
|
63
|
+
instance: CaffeinateInstance | null
|
|
64
|
+
startedAt: Date | null
|
|
65
|
+
endsAt: Date | null
|
|
66
|
+
durationMinutes: number | null
|
|
67
|
+
}
|
|
68
|
+
declare class CaffeinateInstanceImpl implements CaffeinateInstance {
|
|
69
|
+
constructor(process: Subprocess, options: CaffeinateOptions);
|
|
70
|
+
get pid(): number;
|
|
71
|
+
get startedAt(): Date;
|
|
72
|
+
get endsAt(): Date | null;
|
|
73
|
+
get options(): CaffeinateOptions;
|
|
74
|
+
get isActive(): boolean;
|
|
75
|
+
get remainingMs(): number | null;
|
|
76
|
+
get elapsedMs(): number;
|
|
77
|
+
stop(): void;
|
|
78
|
+
onExpire(handler: () => void): void;
|
|
79
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { watch } from 'node:fs';
|
|
2
|
+
/**
|
|
3
|
+
* Create a preferences store for your application.
|
|
4
|
+
*
|
|
5
|
+
* Preferences are stored as JSON in a platform-appropriate location:
|
|
6
|
+
* - macOS: ~/Library/Application Support/{name}/preferences.json
|
|
7
|
+
* - Windows: %APPDATA%/{name}/preferences.json
|
|
8
|
+
* - Linux: ~/.config/{name}/preferences.json
|
|
9
|
+
*/
|
|
10
|
+
export declare function createPreferences<T extends Record<string, unknown>>(options: PreferencesOptions<T>): Preferences<T>;
|
|
11
|
+
// ============================================================================
|
|
12
|
+
// Types
|
|
13
|
+
// ============================================================================
|
|
14
|
+
export declare interface PreferencesOptions<T extends Record<string, unknown>> {
|
|
15
|
+
name: string
|
|
16
|
+
defaults: T
|
|
17
|
+
path?: string
|
|
18
|
+
watch?: boolean
|
|
19
|
+
}
|
|
20
|
+
export declare interface Preferences<T extends Record<string, unknown>> {
|
|
21
|
+
get<K extends keyof T>(key: K): T[K]
|
|
22
|
+
set<K extends keyof T>(key: K, value: T[K]): void
|
|
23
|
+
getAll(): T
|
|
24
|
+
has(key: keyof T): boolean
|
|
25
|
+
delete(key: keyof T): void
|
|
26
|
+
reset(): void
|
|
27
|
+
onChange<K extends keyof T>(key: K, handler: (value: T[K], oldValue: T[K]) => void): () => void
|
|
28
|
+
onAnyChange(handler: (key: keyof T, value: unknown, oldValue: unknown) => void): () => void
|
|
29
|
+
readonly path: string
|
|
30
|
+
close(): void
|
|
31
|
+
}
|
|
32
|
+
declare type ChangeHandler = (key: string, value: unknown, oldValue: unknown) => void;
|
|
33
|
+
// ============================================================================
|
|
34
|
+
// Implementation
|
|
35
|
+
// ============================================================================
|
|
36
|
+
declare class PreferencesImpl<T extends Record<string, unknown>> implements Preferences<T> {
|
|
37
|
+
constructor(options: PreferencesOptions<T>);
|
|
38
|
+
get path(): string;
|
|
39
|
+
get<K extends keyof T>(key: K): T[K];
|
|
40
|
+
set<K extends keyof T>(key: K, value: T[K]): void;
|
|
41
|
+
getAll(): T;
|
|
42
|
+
has(key: keyof T): boolean;
|
|
43
|
+
delete(key: keyof T): void;
|
|
44
|
+
reset(): void;
|
|
45
|
+
onChange<K extends keyof T>(key: K, handler: (value: T[K], oldValue: T[K]) => void): () => void;
|
|
46
|
+
onAnyChange(handler: ChangeHandler): () => void;
|
|
47
|
+
close(): void;
|
|
48
|
+
}
|
package/dist/timer.d.ts
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Create a countdown timer.
|
|
3
|
+
*/
|
|
4
|
+
export declare function createTimer(options: TimerOptions): Timer;
|
|
5
|
+
/**
|
|
6
|
+
* Create a repeating interval.
|
|
7
|
+
*/
|
|
8
|
+
export declare function createInterval(options: IntervalOptions): Interval;
|
|
9
|
+
/**
|
|
10
|
+
* Create a simple delay/sleep promise.
|
|
11
|
+
*/
|
|
12
|
+
export declare function delay(ms: number): Promise<void>;
|
|
13
|
+
/**
|
|
14
|
+
* Format milliseconds as a human-readable time string.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* formatTime(90000) // "1:30"
|
|
19
|
+
* formatTime(3661000) // "1:01:01"
|
|
20
|
+
* formatTime(45000) // "0:45"
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export declare function formatTime(ms: number): string;
|
|
24
|
+
/**
|
|
25
|
+
* Format milliseconds as a compact string for display.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```typescript
|
|
29
|
+
* formatCompact(90000) // "1m 30s"
|
|
30
|
+
* formatCompact(3600000) // "1h"
|
|
31
|
+
* formatCompact(7230000) // "2h 0m"
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
export declare function formatCompact(ms: number): string;
|
|
35
|
+
/**
|
|
36
|
+
* Timer / Scheduling Utilities
|
|
37
|
+
*
|
|
38
|
+
* Provides a rich timer API for desktop applications — useful for
|
|
39
|
+
* Pomodoro timers, caffeinate countdowns, auto-save intervals, etc.
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```typescript
|
|
43
|
+
* import { createTimer } from '@stacksjs/desktop'
|
|
44
|
+
*
|
|
45
|
+
* const timer = createTimer({
|
|
46
|
+
* duration: 25 * 60 * 1000, // 25 minutes
|
|
47
|
+
* onTick: (remaining) => {
|
|
48
|
+
* console.log(`${Math.ceil(remaining / 1000)}s remaining`)
|
|
49
|
+
* },
|
|
50
|
+
* onComplete: () => {
|
|
51
|
+
* console.log('Timer complete!')
|
|
52
|
+
* },
|
|
53
|
+
* })
|
|
54
|
+
*
|
|
55
|
+
* timer.start()
|
|
56
|
+
*
|
|
57
|
+
* // Later...
|
|
58
|
+
* timer.pause()
|
|
59
|
+
* timer.resume()
|
|
60
|
+
* timer.stop()
|
|
61
|
+
* timer.reset()
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
// ============================================================================
|
|
65
|
+
// Types
|
|
66
|
+
// ============================================================================
|
|
67
|
+
export declare interface TimerOptions {
|
|
68
|
+
duration: number
|
|
69
|
+
onTick?: (remaining: number) => void
|
|
70
|
+
onComplete?: () => void
|
|
71
|
+
tickInterval?: number
|
|
72
|
+
autoStart?: boolean
|
|
73
|
+
}
|
|
74
|
+
export declare interface Timer {
|
|
75
|
+
start(): void
|
|
76
|
+
stop(): void
|
|
77
|
+
pause(): void
|
|
78
|
+
resume(): void
|
|
79
|
+
reset(): void
|
|
80
|
+
readonly isRunning: boolean
|
|
81
|
+
readonly isPaused: boolean
|
|
82
|
+
readonly isComplete: boolean
|
|
83
|
+
readonly remaining: number
|
|
84
|
+
readonly elapsed: number
|
|
85
|
+
readonly duration: number
|
|
86
|
+
readonly progress: number
|
|
87
|
+
onComplete(handler: () => void): () => void
|
|
88
|
+
onTick(handler: (remaining: number) => void): () => void
|
|
89
|
+
}
|
|
90
|
+
export declare interface IntervalOptions {
|
|
91
|
+
interval: number
|
|
92
|
+
handler: () => void
|
|
93
|
+
immediate?: boolean
|
|
94
|
+
}
|
|
95
|
+
export declare interface Interval {
|
|
96
|
+
start(): void
|
|
97
|
+
stop(): void
|
|
98
|
+
readonly isRunning: boolean
|
|
99
|
+
}
|
|
100
|
+
// ============================================================================
|
|
101
|
+
// Timer Implementation
|
|
102
|
+
// ============================================================================
|
|
103
|
+
declare class TimerImpl implements Timer {
|
|
104
|
+
constructor(options: TimerOptions);
|
|
105
|
+
get isRunning(): boolean;
|
|
106
|
+
get isPaused(): boolean;
|
|
107
|
+
get isComplete(): boolean;
|
|
108
|
+
get remaining(): number;
|
|
109
|
+
get elapsed(): number;
|
|
110
|
+
get duration(): number;
|
|
111
|
+
get progress(): number;
|
|
112
|
+
start(): void;
|
|
113
|
+
stop(): void;
|
|
114
|
+
pause(): void;
|
|
115
|
+
resume(): void;
|
|
116
|
+
reset(): void;
|
|
117
|
+
onComplete(handler: () => void): () => void;
|
|
118
|
+
onTick(handler: (remaining: number) => void): () => void;
|
|
119
|
+
}
|
|
120
|
+
// ============================================================================
|
|
121
|
+
// Interval Implementation
|
|
122
|
+
// ============================================================================
|
|
123
|
+
declare class IntervalImpl implements Interval {
|
|
124
|
+
constructor(options: IntervalOptions);
|
|
125
|
+
get isRunning(): boolean;
|
|
126
|
+
start(): void;
|
|
127
|
+
stop(): void;
|
|
128
|
+
}
|
package/package.json
CHANGED