@sirenodeck/sirenodeck 0.2.10 → 0.4.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/dist/main.mjs +1089 -626
- package/dist/{windows-CRWdUgCn.mjs → windows-BCvfQ3PA.mjs} +4 -4
- package/frontend/src/App.tsx +3 -0
- package/frontend/src/components/Deck.tsx +13 -2
- package/package.json +10 -1
- package/src/addon/api.ts +24 -1
- package/src/addon/data-directory.ts +52 -0
- package/src/api/protocol-internal.ts +1 -0
- package/src/builtin-addons/index.ts +0 -1
- package/src/builtin-addons/internal-settings/backend.ts +1 -1
- package/src/builtin-addons/internal-settings/buttons/brightness/common/frontend.tsx +14 -3
- package/src/builtin-addons/internal-settings/buttons/brightness-compact/frontend.tsx +6 -0
- package/src/builtin-addons/internal-settings/index.ts +15 -0
- package/src/builtin-addons/register-builtins.ts +0 -3
- package/src/cli/commands/addon-decks.ts +1 -0
- package/src/cli/commands/addon-setup-config.ts +85 -0
- package/src/cli/commands/addon-setup.ts +134 -0
- package/src/cli/commands/run.ts +53 -11
- package/src/cli/commands/service-manager.ts +3 -5
- package/src/cli/commands/start.ts +14 -81
- package/src/cli/commands/stop.ts +4 -0
- package/src/cli/index.ts +2 -0
- package/src/config/environment.ts +44 -0
- package/src/config/loader.ts +17 -1
- package/src/config/schemas.ts +2 -1
- package/src/config/validation.ts +5 -1
- package/src/deck/addon-handler-bridge.ts +105 -6
- package/src/deck/addon-settings.ts +94 -0
- package/src/deck/deck-config.ts +1 -0
- package/src/deck/inject-config-ui-button.ts +25 -14
- package/src/deck/runtime/runtime.ts +175 -3
- package/src/deck/system-back-injection.ts +2 -0
- package/src/deck/system-buttons/registry.tsx +1 -0
- package/src/deck/system-buttons/types.ts +1 -0
- package/src/system/credentials/native.ts +74 -0
- package/src/system/credentials/store.ts +77 -0
- package/src/system/providers/notification/windows.ts +4 -4
- package/src/themes/default/sirenodeck.json +1 -0
- package/src/themes/light/sirenodeck.json +1 -0
- package/src/themes/manifest.ts +1 -0
- package/src/ui/primitives/Chip.tsx +1 -0
- package/src/ui/primitives/StatusIndicator.tsx +36 -0
- package/src/ui/primitives/index.ts +1 -0
- package/src/ui/surfaces/BinaryToggleSurface.tsx +52 -0
- package/src/ui/surfaces/LoadingSurface.tsx +34 -0
- package/src/ui/surfaces/index.ts +2 -0
- package/src/builtin-addons/brightness/README.md +0 -51
- package/src/builtin-addons/brightness/buttons/brightness/backend.ts +0 -13
- package/src/builtin-addons/brightness/buttons/brightness/config.ts +0 -20
- package/src/builtin-addons/brightness/buttons/brightness/frontend.tsx +0 -50
- package/src/builtin-addons/brightness/domain/macos.ts +0 -46
- package/src/builtin-addons/brightness/index.d.ts +0 -5
- package/src/builtin-addons/brightness/index.ts +0 -20
- package/src/builtin-addons/brightness/poller.ts +0 -27
- package/src/builtin-addons/brightness/sirenodeck.json +0 -6
- /package/src/builtin-addons/{brightness/providers → internal-settings/brightness-providers}/darwin.ts +0 -0
- /package/src/builtin-addons/{brightness/providers → internal-settings/brightness-providers}/index.ts +0 -0
- /package/src/builtin-addons/{brightness/providers → internal-settings/brightness-providers}/linux.ts +0 -0
- /package/src/builtin-addons/{brightness/providers → internal-settings/brightness-providers}/windows.ts +0 -0
|
@@ -16,6 +16,7 @@ const SYSTEM_BUTTON_LAYOUT: Record<
|
|
|
16
16
|
{ source: string; label: string; details?: string }
|
|
17
17
|
> = {
|
|
18
18
|
"core:back": { source: "icon://arrow-left", label: "Back" },
|
|
19
|
+
"core:modal-ok": { source: "icon://check", label: "OK" },
|
|
19
20
|
"core:settings-entry": { source: "icon://settings", label: "Settings" },
|
|
20
21
|
"core:overlay-toggle": { source: "icon://layers", label: "Overlay" },
|
|
21
22
|
"core:temporary-error": {
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { createHash } from "node:crypto"
|
|
2
|
+
import { CredentialStoreError, type CredentialBackend } from "./store"
|
|
3
|
+
|
|
4
|
+
type NativeEntry = {
|
|
5
|
+
getSecret(): Promise<number[] | null>
|
|
6
|
+
setSecret(value: Uint8Array): Promise<void>
|
|
7
|
+
deleteCredential(): Promise<boolean>
|
|
8
|
+
}
|
|
9
|
+
type EntryFactory = (account: string) => Promise<NativeEntry>
|
|
10
|
+
|
|
11
|
+
const accountFor = (addon: string, name: string): string =>
|
|
12
|
+
createHash("sha256")
|
|
13
|
+
.update(JSON.stringify([addon, name]))
|
|
14
|
+
.digest("hex")
|
|
15
|
+
|
|
16
|
+
/** Entries contain no user-provided names in native-store metadata. */
|
|
17
|
+
export const createNativeCredentialBackend = (
|
|
18
|
+
createEntry: EntryFactory = async (account) => {
|
|
19
|
+
const { AsyncEntry } = await import("@napi-rs/keyring")
|
|
20
|
+
return new AsyncEntry("sirenodeck.credentials.v1", account, {
|
|
21
|
+
linux: { store: "secret-service" },
|
|
22
|
+
})
|
|
23
|
+
},
|
|
24
|
+
): CredentialBackend => {
|
|
25
|
+
const entry = async (addon: string, name: string): Promise<NativeEntry> => {
|
|
26
|
+
try {
|
|
27
|
+
return await createEntry(accountFor(addon, name))
|
|
28
|
+
} catch {
|
|
29
|
+
throw new CredentialStoreError("unavailable")
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return {
|
|
33
|
+
availability: async () => {
|
|
34
|
+
try {
|
|
35
|
+
const probe = await createEntry(
|
|
36
|
+
accountFor("sirenodeck", "availability-probe"),
|
|
37
|
+
)
|
|
38
|
+
await probe.getSecret()
|
|
39
|
+
return "available"
|
|
40
|
+
} catch {
|
|
41
|
+
return "unavailable"
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
get: async (addon, name) => {
|
|
45
|
+
const item = await entry(addon, name)
|
|
46
|
+
try {
|
|
47
|
+
const bytes = await item.getSecret()
|
|
48
|
+
return bytes === null
|
|
49
|
+
? undefined
|
|
50
|
+
: new TextDecoder("utf-8", { fatal: true }).decode(
|
|
51
|
+
Uint8Array.from(bytes),
|
|
52
|
+
)
|
|
53
|
+
} catch {
|
|
54
|
+
throw new CredentialStoreError("operation-failed")
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
set: async (addon, name, value) => {
|
|
58
|
+
const item = await entry(addon, name)
|
|
59
|
+
try {
|
|
60
|
+
await item.setSecret(new TextEncoder().encode(value))
|
|
61
|
+
} catch {
|
|
62
|
+
throw new CredentialStoreError("operation-failed")
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
delete: async (addon, name) => {
|
|
66
|
+
const item = await entry(addon, name)
|
|
67
|
+
try {
|
|
68
|
+
await item.deleteCredential()
|
|
69
|
+
} catch {
|
|
70
|
+
throw new CredentialStoreError("operation-failed")
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
}
|
|
74
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/** Windows Credential Manager's generic credential blob limit, in bytes. */
|
|
2
|
+
export const MAX_CREDENTIAL_BYTES = 2560
|
|
3
|
+
|
|
4
|
+
export type CredentialErrorCode =
|
|
5
|
+
| "unavailable"
|
|
6
|
+
| "locked"
|
|
7
|
+
| "too-large"
|
|
8
|
+
| "invalid-name"
|
|
9
|
+
| "operation-failed"
|
|
10
|
+
|
|
11
|
+
/** Error messages must not include credential values or native error details. */
|
|
12
|
+
export class CredentialStoreError extends Error {
|
|
13
|
+
constructor(readonly code: CredentialErrorCode) {
|
|
14
|
+
super(`Credential store: ${code}`)
|
|
15
|
+
this.name = "CredentialStoreError"
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** A backend receives the addon scope from the host, not from addon code. */
|
|
20
|
+
export interface CredentialBackend {
|
|
21
|
+
availability(): Promise<"available" | "locked" | "unavailable">
|
|
22
|
+
get(addon: string, name: string): Promise<string | undefined>
|
|
23
|
+
set(addon: string, name: string, value: string): Promise<void>
|
|
24
|
+
delete(addon: string, name: string): Promise<void>
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface AddonCredentials {
|
|
28
|
+
availability(): Promise<"available" | "locked" | "unavailable">
|
|
29
|
+
get(name: string): Promise<string | undefined>
|
|
30
|
+
set(name: string, value: string): Promise<void>
|
|
31
|
+
delete(name: string): Promise<void>
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const validateName = (name: string): void => {
|
|
35
|
+
if (!/^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/.test(name)) {
|
|
36
|
+
throw new CredentialStoreError("invalid-name")
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Bind an addon identity so callers cannot choose another namespace. */
|
|
41
|
+
export const scopeCredentials = (
|
|
42
|
+
backend: CredentialBackend,
|
|
43
|
+
addon: string,
|
|
44
|
+
): AddonCredentials => {
|
|
45
|
+
return {
|
|
46
|
+
availability: () => backend.availability(),
|
|
47
|
+
get: async (name) => {
|
|
48
|
+
validateName(name)
|
|
49
|
+
return backend.get(addon, name)
|
|
50
|
+
},
|
|
51
|
+
set: async (name, value) => {
|
|
52
|
+
validateName(name)
|
|
53
|
+
if (Buffer.byteLength(value, "utf8") > MAX_CREDENTIAL_BYTES) {
|
|
54
|
+
throw new CredentialStoreError("too-large")
|
|
55
|
+
}
|
|
56
|
+
await backend.set(addon, name, value)
|
|
57
|
+
},
|
|
58
|
+
delete: async (name) => {
|
|
59
|
+
validateName(name)
|
|
60
|
+
await backend.delete(addon, name)
|
|
61
|
+
},
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** Fail closed until a native credential backend is installed and available. */
|
|
66
|
+
export const unavailableCredentialBackend: CredentialBackend = {
|
|
67
|
+
availability: async () => "unavailable",
|
|
68
|
+
get: async () => {
|
|
69
|
+
throw new CredentialStoreError("unavailable")
|
|
70
|
+
},
|
|
71
|
+
set: async () => {
|
|
72
|
+
throw new CredentialStoreError("unavailable")
|
|
73
|
+
},
|
|
74
|
+
delete: async () => {
|
|
75
|
+
throw new CredentialStoreError("unavailable")
|
|
76
|
+
},
|
|
77
|
+
}
|
|
@@ -18,14 +18,14 @@ const shellQuote = (value: string): string =>
|
|
|
18
18
|
// ponytail: raw toast template via PowerShell BurntToast-free path. Sufficient
|
|
19
19
|
// for our "Pomodoro done" use case; richer XML templates are out of scope.
|
|
20
20
|
const buildToastScript = (title: string, body: string): string => {
|
|
21
|
-
const safeTitle =
|
|
22
|
-
const safeBody =
|
|
21
|
+
const safeTitle = Buffer.from(title, "utf8").toString("base64")
|
|
22
|
+
const safeBody = Buffer.from(body, "utf8").toString("base64")
|
|
23
23
|
return [
|
|
24
24
|
"Add-Type -AssemblyName System.Windows.Forms | Out-Null",
|
|
25
25
|
`$balloon = New-Object System.Windows.Forms.NotifyIcon`,
|
|
26
26
|
`$balloon.Icon = [System.Drawing.SystemIcons]::Information`,
|
|
27
|
-
`$balloon.BalloonTipTitle =
|
|
28
|
-
`$balloon.BalloonTipText =
|
|
27
|
+
`$balloon.BalloonTipTitle = [Text.Encoding]::UTF8.GetString([Convert]::FromBase64String('${safeTitle}'))`,
|
|
28
|
+
`$balloon.BalloonTipText = [Text.Encoding]::UTF8.GetString([Convert]::FromBase64String('${safeBody}'))`,
|
|
29
29
|
`$balloon.Visible = $true`,
|
|
30
30
|
`$balloon.ShowBalloonTip(5000)`,
|
|
31
31
|
"Start-Sleep -Milliseconds 5500",
|
package/src/themes/manifest.ts
CHANGED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { ReactElement } from "react"
|
|
2
|
+
import type { ChipTone } from "./Chip"
|
|
3
|
+
|
|
4
|
+
const TONE_CLASS: Record<ChipTone, string> = {
|
|
5
|
+
accent: "bg-accent text-accent",
|
|
6
|
+
danger: "bg-danger text-danger",
|
|
7
|
+
foreground: "bg-foreground text-foreground",
|
|
8
|
+
primary: "bg-primary text-primary",
|
|
9
|
+
success: "bg-success text-success",
|
|
10
|
+
muted: "bg-grey text-grey",
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface StatusIndicatorProps {
|
|
14
|
+
label: string
|
|
15
|
+
tone: ChipTone
|
|
16
|
+
glow?: boolean
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function StatusIndicator({
|
|
20
|
+
label,
|
|
21
|
+
tone,
|
|
22
|
+
glow = false,
|
|
23
|
+
}: StatusIndicatorProps): ReactElement {
|
|
24
|
+
return (
|
|
25
|
+
<span
|
|
26
|
+
role="img"
|
|
27
|
+
aria-label={label}
|
|
28
|
+
className={`inline-block shrink-0 rounded-full ${TONE_CLASS[tone]}`}
|
|
29
|
+
style={{
|
|
30
|
+
width: 40,
|
|
31
|
+
height: 7,
|
|
32
|
+
boxShadow: glow ? "0 0 6px currentColor" : undefined,
|
|
33
|
+
}}
|
|
34
|
+
/>
|
|
35
|
+
)
|
|
36
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { ReactElement } from "react"
|
|
2
|
+
import type { ChipTone } from "../primitives/Chip"
|
|
3
|
+
import { Icon } from "../primitives/Icon"
|
|
4
|
+
import { Label } from "../primitives/Label"
|
|
5
|
+
import { Text } from "../primitives/Text"
|
|
6
|
+
import { StatusIndicator } from "../primitives/StatusIndicator"
|
|
7
|
+
|
|
8
|
+
export interface BinaryToggleSurfaceProps {
|
|
9
|
+
label: string
|
|
10
|
+
labelColor?: string
|
|
11
|
+
source?: string
|
|
12
|
+
variant?: ChipTone
|
|
13
|
+
status: boolean
|
|
14
|
+
details?: string
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function BinaryToggleSurface({
|
|
18
|
+
label,
|
|
19
|
+
labelColor,
|
|
20
|
+
source,
|
|
21
|
+
variant = "accent",
|
|
22
|
+
status,
|
|
23
|
+
details,
|
|
24
|
+
}: BinaryToggleSurfaceProps): ReactElement {
|
|
25
|
+
return (
|
|
26
|
+
<div
|
|
27
|
+
className={`relative isolate grid h-full w-full min-w-0 grid-rows-[minmax(0,1fr)_auto] pb-1 ${
|
|
28
|
+
status
|
|
29
|
+
? ""
|
|
30
|
+
: "before:absolute before:-inset-2 before:-z-10 before:bg-black/40 before:content-['']"
|
|
31
|
+
}`}
|
|
32
|
+
>
|
|
33
|
+
<div className="flex min-h-0 min-w-0 flex-col items-center justify-center gap-1 overflow-hidden">
|
|
34
|
+
{source ? <Icon source={source} size={24} /> : null}
|
|
35
|
+
<Text
|
|
36
|
+
text={label}
|
|
37
|
+
weight="bold"
|
|
38
|
+
fit={{ type: "fit", lines: 2, ellipsis: true }}
|
|
39
|
+
style={labelColor ? { color: labelColor } : undefined}
|
|
40
|
+
/>
|
|
41
|
+
{details ? <Label text={details} variant="small" /> : null}
|
|
42
|
+
</div>
|
|
43
|
+
<div className="flex justify-center self-end">
|
|
44
|
+
<StatusIndicator
|
|
45
|
+
label={status ? "On" : "Off"}
|
|
46
|
+
tone={status ? variant : "danger"}
|
|
47
|
+
glow={status}
|
|
48
|
+
/>
|
|
49
|
+
</div>
|
|
50
|
+
</div>
|
|
51
|
+
)
|
|
52
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { ReactElement } from "react"
|
|
2
|
+
import { Icon } from "../primitives/Icon"
|
|
3
|
+
import { Label } from "../primitives/Label"
|
|
4
|
+
|
|
5
|
+
export function LoadingSurface(): ReactElement {
|
|
6
|
+
return (
|
|
7
|
+
<div
|
|
8
|
+
className="flex h-full w-full min-w-0 flex-col items-center justify-center gap-1 overflow-hidden"
|
|
9
|
+
role="status"
|
|
10
|
+
aria-label="Loading"
|
|
11
|
+
>
|
|
12
|
+
<style>{`
|
|
13
|
+
@keyframes sireno-loading-dot {
|
|
14
|
+
0%, 24.999%, 50%, 100% { opacity: 1; }
|
|
15
|
+
25%, 49.999% { opacity: 0; }
|
|
16
|
+
}
|
|
17
|
+
@media (prefers-reduced-motion: no-preference) {
|
|
18
|
+
.sireno-loading-dot { animation: sireno-loading-dot 4s steps(1, end) infinite; }
|
|
19
|
+
.sireno-loading-dot:nth-child(2) { animation-delay: 1s; }
|
|
20
|
+
.sireno-loading-dot:nth-child(3) { animation-delay: 2s; }
|
|
21
|
+
}
|
|
22
|
+
`}</style>
|
|
23
|
+
<Icon source="icon://hourglass" size={20} />
|
|
24
|
+
<div className="flex items-baseline" aria-hidden="true">
|
|
25
|
+
<Label text="Loading" />
|
|
26
|
+
<span className="font-bold" style={{ whiteSpace: "pre" }}>
|
|
27
|
+
<span className="sireno-loading-dot">.</span>
|
|
28
|
+
<span className="sireno-loading-dot">.</span>
|
|
29
|
+
<span className="sireno-loading-dot">.</span>
|
|
30
|
+
</span>
|
|
31
|
+
</div>
|
|
32
|
+
</div>
|
|
33
|
+
)
|
|
34
|
+
}
|
package/src/ui/surfaces/index.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
export * from "./BarsSurface"
|
|
2
|
+
export * from "./BinaryToggleSurface"
|
|
2
3
|
export * from "./IconLabelProgressSurface"
|
|
3
4
|
export * from "./IconLabelSurface"
|
|
4
5
|
export * from "./LabelValueListSurface"
|
|
6
|
+
export * from "./LoadingSurface"
|
|
5
7
|
export * from "./TemporaryErrorSurface"
|
|
6
8
|
export * from "./ValueChart"
|
|
7
9
|
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
# brightness
|
|
2
|
-
|
|
3
|
-
Single button that adjusts screen brightness. Tap = action (up/down/set). The button shows the current brightness as a bar.
|
|
4
|
-
|
|
5
|
-
Uses the OS provider from `packages/cli/src/system/providers/`:
|
|
6
|
-
|
|
7
|
-
- Linux: `xrandr` / `brightnessctl` (whichever is available)
|
|
8
|
-
- macOS: `osascript`
|
|
9
|
-
- Windows: PowerShell + WMI
|
|
10
|
-
|
|
11
|
-
## Buttons
|
|
12
|
-
|
|
13
|
-
| Type | Description |
|
|
14
|
-
| ----------------------- | ------------------------------------------------ |
|
|
15
|
-
| `brightness:brightness` | Single button: shows + adjusts screen brightness |
|
|
16
|
-
|
|
17
|
-
## Config
|
|
18
|
-
|
|
19
|
-
```yaml
|
|
20
|
-
- position: 5
|
|
21
|
-
type: brightness:brightness
|
|
22
|
-
config:
|
|
23
|
-
action: up # "up" (default), "down", or "set"
|
|
24
|
-
value: 75 # required for "set" (0-100); ignored for up/down
|
|
25
|
-
```
|
|
26
|
-
|
|
27
|
-
### Gesture semantics
|
|
28
|
-
|
|
29
|
-
- **Tap** on a `brightness:brightness` button → executes the configured `action`.
|
|
30
|
-
- **Hold** on a `brightness:brightness` button → toggles between `up` and `down` for fine-grained adjustment.
|
|
31
|
-
|
|
32
|
-
## Example
|
|
33
|
-
|
|
34
|
-
In your `settings` deck (auto-generated by `internal-settings`):
|
|
35
|
-
|
|
36
|
-
```yaml
|
|
37
|
-
decks:
|
|
38
|
-
settings:
|
|
39
|
-
name: Settings
|
|
40
|
-
buttons:
|
|
41
|
-
- position: 0
|
|
42
|
-
type: brightness:brightness
|
|
43
|
-
config: { action: up }
|
|
44
|
-
```
|
|
45
|
-
|
|
46
|
-
Run `xrandr --output eDP-1 --brightness 0.75` (Linux) to verify the action works on your system.
|
|
47
|
-
|
|
48
|
-
## See also
|
|
49
|
-
|
|
50
|
-
- [system-status](../system-status/README.md) — same polling pattern; brightness is just a one-button metric
|
|
51
|
-
- [OS providers](../../../../system/providers/README.md) — brightness provider per OS
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { AddonButtonTypeService } from "@/addon/api"
|
|
2
|
-
|
|
3
|
-
import { buildMacOSCommand, formatCommand, isMacOS } from "../../domain/macos"
|
|
4
|
-
import { configSchema, type ConfigSchema } from "./config"
|
|
5
|
-
|
|
6
|
-
export default {
|
|
7
|
-
configSchema,
|
|
8
|
-
defaultRenderIntervalMs: 2000,
|
|
9
|
-
onTap: ({ config, executor }) => {
|
|
10
|
-
if (!isMacOS(process.platform)) return
|
|
11
|
-
void executor.run(formatCommand(buildMacOSCommand(config))).catch(() => {})
|
|
12
|
-
},
|
|
13
|
-
} satisfies AddonButtonTypeService<ConfigSchema>
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { z } from "zod"
|
|
2
|
-
|
|
3
|
-
export const configSchema = z
|
|
4
|
-
.object({
|
|
5
|
-
action: z
|
|
6
|
-
.enum(["up", "down", "set"])
|
|
7
|
-
.optional()
|
|
8
|
-
.default("up")
|
|
9
|
-
.meta({ title: "Brightness action" }),
|
|
10
|
-
value: z
|
|
11
|
-
.number()
|
|
12
|
-
.int()
|
|
13
|
-
.min(0)
|
|
14
|
-
.max(100)
|
|
15
|
-
.optional()
|
|
16
|
-
.meta({ title: "Brightness (%)" }),
|
|
17
|
-
})
|
|
18
|
-
.strict()
|
|
19
|
-
|
|
20
|
-
export type ConfigSchema = z.infer<typeof configSchema>
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { Text } from "@/ui/index"
|
|
2
|
-
import { useAddonChannel } from "@/api/react"
|
|
3
|
-
import type { AddonFrontendButton } from "@/addon/api"
|
|
4
|
-
|
|
5
|
-
import type { ConfigSchema } from "./config"
|
|
6
|
-
|
|
7
|
-
interface BrightnessState {
|
|
8
|
-
readonly value: number
|
|
9
|
-
readonly max: number
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
const BrightnessButtonFrontend: AddonFrontendButton<ConfigSchema> = ({
|
|
13
|
-
config,
|
|
14
|
-
}) => {
|
|
15
|
-
const { action } = config ?? {}
|
|
16
|
-
const { data } = useAddonChannel<BrightnessState>("brightness:current")
|
|
17
|
-
if (data === undefined) {
|
|
18
|
-
return (
|
|
19
|
-
<Text
|
|
20
|
-
size="xs"
|
|
21
|
-
tone="muted"
|
|
22
|
-
typography="mono"
|
|
23
|
-
className="flex h-full w-full items-center justify-center"
|
|
24
|
-
text="—"
|
|
25
|
-
/>
|
|
26
|
-
)
|
|
27
|
-
}
|
|
28
|
-
const pct = Math.max(0, Math.min(100, (data.value / (data.max || 100)) * 100))
|
|
29
|
-
return (
|
|
30
|
-
<span className="flex h-full w-full flex-col items-stretch justify-center gap-1 p-2">
|
|
31
|
-
<span className="flex items-baseline justify-between">
|
|
32
|
-
<Text size="xs" tone="muted" fit="ellipsis" text="Brightness" />
|
|
33
|
-
<Text size="xs" tone="fg" text={`${pct.toFixed(0)}%`} />
|
|
34
|
-
</span>
|
|
35
|
-
<span className="block h-1.5 w-full overflow-hidden rounded bg-bar">
|
|
36
|
-
<span className="block h-full bg-accent" style={{ width: `${pct}%` }} />
|
|
37
|
-
</span>
|
|
38
|
-
<Text
|
|
39
|
-
size="xs"
|
|
40
|
-
tone="muted"
|
|
41
|
-
className="text-center"
|
|
42
|
-
typography="aux"
|
|
43
|
-
text={`Tap: ${action ?? "up"}`}
|
|
44
|
-
/>
|
|
45
|
-
</span>
|
|
46
|
-
)
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export default BrightnessButtonFrontend
|
|
50
|
-
export { BrightnessButtonFrontend }
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import type { ConfigSchema as BrightnessButtonConfig } from "../buttons/brightness/config"
|
|
2
|
-
|
|
3
|
-
const escape = (s: string): string => `'${s.replaceAll("'", "'\\''")}'`
|
|
4
|
-
|
|
5
|
-
export const isMacOS = (platform: NodeJS.Platform): boolean =>
|
|
6
|
-
platform === "darwin"
|
|
7
|
-
|
|
8
|
-
export const setBrightnessMacOS = async (
|
|
9
|
-
config: BrightnessButtonConfig,
|
|
10
|
-
exec: (
|
|
11
|
-
cmd: string,
|
|
12
|
-
args: string[],
|
|
13
|
-
) => Promise<{ exitCode: number; stderr: string }>,
|
|
14
|
-
): Promise<void> => {
|
|
15
|
-
if (config.action === "set" && config.value !== undefined) {
|
|
16
|
-
const script = `tell application "System Events" to set brightness of (first item of (get displays)) to ${config.value / 100}`
|
|
17
|
-
await exec("osascript", ["-e", script])
|
|
18
|
-
return
|
|
19
|
-
}
|
|
20
|
-
if (config.action === "down") {
|
|
21
|
-
await exec("osascript", [
|
|
22
|
-
"-e",
|
|
23
|
-
`tell application "System Events" to key code 145`,
|
|
24
|
-
])
|
|
25
|
-
return
|
|
26
|
-
}
|
|
27
|
-
await exec("osascript", [
|
|
28
|
-
"-e",
|
|
29
|
-
`tell application "System Events" to key code 144`,
|
|
30
|
-
])
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export const buildMacOSCommand = (
|
|
34
|
-
config: BrightnessButtonConfig,
|
|
35
|
-
): readonly string[] => {
|
|
36
|
-
if (config.action === "set" && config.value !== undefined) {
|
|
37
|
-
return ["osascript", "-e", `set brightness to ${config.value / 100}`]
|
|
38
|
-
}
|
|
39
|
-
if (config.action === "down") {
|
|
40
|
-
return ["osascript", "-e", `key code 145`]
|
|
41
|
-
}
|
|
42
|
-
return ["osascript", "-e", `key code 144`]
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export const formatCommand = (cmd: readonly string[]): string =>
|
|
46
|
-
cmd.map(escape).join(" ")
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import type { AddonManifestV1 } from "@/addon/api"
|
|
2
|
-
|
|
3
|
-
import brightnessBackend from "./buttons/brightness/backend"
|
|
4
|
-
import brightnessFrontend from "./buttons/brightness/frontend"
|
|
5
|
-
|
|
6
|
-
export const manifest: AddonManifestV1 = {
|
|
7
|
-
apiVersion: 1,
|
|
8
|
-
name: "brightness",
|
|
9
|
-
buttonTypes: {
|
|
10
|
-
"brightness:brightness": {
|
|
11
|
-
frontend: brightnessFrontend,
|
|
12
|
-
service: { ...brightnessBackend, gestureHandlers: ["tap"] as const },
|
|
13
|
-
},
|
|
14
|
-
},
|
|
15
|
-
publishIntervalMs: 2000,
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export const brightnessAddon = manifest
|
|
19
|
-
export default manifest
|
|
20
|
-
export { brightnessBackend, brightnessFrontend }
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import type { AddonPoller } from "@/addon/api-types"
|
|
2
|
-
|
|
3
|
-
import type { BrightnessProvider } from "./providers"
|
|
4
|
-
|
|
5
|
-
export interface BrightnessPollerDeps {
|
|
6
|
-
readonly brightnessProvider: BrightnessProvider | null
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export const createPoller = (deps: BrightnessPollerDeps): AddonPoller => ({
|
|
10
|
-
channels: [
|
|
11
|
-
{
|
|
12
|
-
channel: "brightness:current",
|
|
13
|
-
intervalMs: 2_000,
|
|
14
|
-
poll: async () => {
|
|
15
|
-
if (deps.brightnessProvider === null) {
|
|
16
|
-
return { value: 0, max: 100 }
|
|
17
|
-
}
|
|
18
|
-
try {
|
|
19
|
-
const reading = await deps.brightnessProvider.getCurrent()
|
|
20
|
-
return { value: reading.value, max: reading.max }
|
|
21
|
-
} catch {
|
|
22
|
-
return { value: 0, max: 100 }
|
|
23
|
-
}
|
|
24
|
-
},
|
|
25
|
-
},
|
|
26
|
-
],
|
|
27
|
-
})
|
|
File without changes
|
/package/src/builtin-addons/{brightness/providers → internal-settings/brightness-providers}/index.ts
RENAMED
|
File without changes
|
/package/src/builtin-addons/{brightness/providers → internal-settings/brightness-providers}/linux.ts
RENAMED
|
File without changes
|
|
File without changes
|