Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Anything that changes what the dashboard, the admin or a widget can do gets a li

### Changed
- **Clock in the compact bar.** Show an accent-coloured clock icon beside the time, matching the weather icon.
- **The system tiles show useful Mac capacity.** Disk usage uses the APFS data volume and shows available space; memory shows available RAM and swap.
- **Homey is a declared connection now.** The Homey connection type built into Fremkit is gone:
both Homey widgets bring their own, so one API key serves the two of them. An existing Homey
connection is migrated when the server starts — same name, same address, same key — and the
Expand All @@ -25,6 +26,7 @@ Anything that changes what the dashboard, the admin or a widget can do gets a li

### Added
- **Local Docker and AI models.** Registry widgets can show up to 200 local containers and observed Ollama or MLX models. Fremkit refuses remote Docker contexts, distinguishes a missing CLI from a stopped daemon, and keeps the container list when stats fail.
- **The Uptime tile shows time since boot.** The reading comes from macOS and remains unavailable when the system cannot provide it.
- **Borrow the Edge display.** Hide or show the dashboard from the helper menu without quitting it. Hidden state survives display rearrangements, and the mouse fence pauses while the Edge is borrowed. Touch and data collection continue; the dashboard reappears after a helper restart.
- **Claude sessions: go to the session.** Touch a card and its window comes forward — the
exact Orca pane, the Terminal.app or iTerm2 tab, the VS Code window on that folder, or at
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,9 @@ above state lines such as "Server: running" and "Touch: active".
| `clipboard` | Recent clipboard entries, tap to copy back | — | — |
| `clock` | Time, date and other cities | — | ● |
| `cpu` | CPU load and temperature | — | ● |
| `disk` | Disk usage | — | — |
| `memory` | Memory usage | — | ● |
| `disk` | Disk usage and available space | — | — |
| `memory` | Memory usage, available RAM and swap | — | ● |
| `uptime` | Time since the Mac last booted | — | — |
| `network` | Live network throughput, with a sparkline | — | ● |
| `notifications` | Unread badges read from the Dock | — | — |
| `pomodoro` | A work and break timer, driven by touch | — | ● |
Expand Down
15 changes: 11 additions & 4 deletions docs/widgets.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ To write your own, see [writing-widgets.md](writing-widgets.md).
| [clipboard](#clipboard) | Recent clipboard entries, tap to copy back | — | — | 16 × 8 |
| [clock](#clock) | Time, date and other cities | — | 5 cells | 16 × 4 |
| [cpu](#cpu) | CPU load and temperature | — | 4 cells | 8 × 4 |
| [disk](#disk) | Disk usage | — | — | 16 × 4 |
| [memory](#memory) | Memory usage | — | 4 cells | 8 × 4 |
| [disk](#disk) | Disk usage and available space | — | — | 16 × 4 |
| [memory](#memory) | Memory usage, available RAM and swap | — | 4 cells | 8 × 4 |
| [uptime](#uptime) | Time since the Mac last booted | — | — | 8 × 4 |
| [network](#network) | Live network throughput | — | 6 cells | 12 × 4 |
| [notifications](#notifications) | Unread badges read from the Dock | — | — | 16 × 4 |
| [pomodoro](#pomodoro) | A work and break timer | — | 5 cells | 8 × 6 |
Expand Down Expand Up @@ -172,16 +173,22 @@ Minimum size 8 × 4, default 8 × 4. Compact width 4 cells.

## disk

*Disks* — usage of the startup disk and of every volume mounted under `/Volumes`.
*Disks* shows used and available capacity of the Mac disk and volumes under `/Volumes`. On APFS it prefers the data volume to avoid presenting the sealed system volume as the usable disk. The Mac disk uses container size minus reported available space so its numbers add up. System disk readings omit purgeable capacity, so free space may be lower than Finder shows.

Minimum size 8 × 4, default 16 × 4. No settings.

## memory

*Memory* — memory usage.
*Memory* shows used and available RAM plus swap usage when the system reports it.

Minimum size 8 × 4, default 8 × 4. Compact width 4 cells. No settings.

## uptime

*Uptime* shows the time since the Mac last booted in days, hours and minutes. If the system cannot provide a reading, the widget shows it as unavailable.

Minimum size 8 × 4, default 8 × 4. No settings.

## network

*Network* — live throughput of the interface the default route goes out of: the two rates as big
Expand Down
49 changes: 45 additions & 4 deletions server/src/providers/system.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,50 @@
import si from 'systeminformation'
import { uptime } from 'node:os'
import type { Provider } from './types.js'

const round = (n: number) => Math.round(n * 10) / 10

interface DiskReading {
mount: string
size: number
used: number
available?: number
use: number
}

/** APFS shares capacity: the data volume represents the useful Mac disk. */
export function normalizeDisks(disks: DiskReading[]) {
const data = disks.find((disk) => disk.mount === '/System/Volumes/Data')
return disks
.filter((disk) => (data ? disk === data : disk.mount === '/')
|| disk.mount.startsWith('/Volumes/'))
.map((disk) => {
const available = typeof disk.available === 'number'
&& Number.isFinite(disk.available) && disk.available >= 0
? disk.available : null
const isMacDisk = disk === data
const used = isMacDisk && available !== null ? Math.max(0, disk.size - available) : disk.used
return {
mount: isMacDisk ? '/' : disk.mount,
size: disk.size,
used,
available,
use: round(isMacDisk && available !== null && disk.size > 0
? used / disk.size * 100 : disk.use),
}
})
}

/** A denied uptime reading must not suppress CPU, memory or disk metrics. */
function uptimeSeconds(): number | null {
try {
const seconds = uptime()
return Number.isFinite(seconds) && seconds >= 0 ? Math.floor(seconds) : null
} catch {
return null
}
}

export const systemProvider: Provider = {
channel: 'system',
intervalMs: 2000,
Expand All @@ -11,11 +53,10 @@ export const systemProvider: Provider = {
si.currentLoad(), si.mem(), si.fsSize(), si.networkStats(), si.cpuTemperature(),
])
return {
uptimeSeconds: uptimeSeconds(),
cpu: { load: round(load.currentLoad), cores: load.cpus.map((c) => round(c.load)), temp: temp.main > 0 ? round(temp.main) : null },
memory: { total: mem.total, used: mem.active, free: mem.available },
disks: fs
.filter((d) => d.mount === '/' || d.mount.startsWith('/Volumes/'))
.map((d) => ({ mount: d.mount, size: d.size, used: d.used, use: round(d.use) })),
memory: { total: mem.total, used: mem.active, free: mem.available, swapUsed: mem.swapused, swapTotal: mem.swaptotal },
disks: normalizeDisks(fs),
network: net.map((n) => ({ iface: n.iface, rx: Math.max(0, Math.round(n.rx_sec ?? 0)), tx: Math.max(0, Math.round(n.tx_sec ?? 0)) })),
}
},
Expand Down
20 changes: 20 additions & 0 deletions server/test/system-disks.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { describe, expect, it } from 'vitest'
import { normalizeDisks } from '../src/providers/system.js'

describe('Mac disk availability', () => {
it('prefers APFS Data and reconciles used and available bytes', () => {
const disks = normalizeDisks([
{ mount: '/', size: 1000, used: 50, available: 300, use: 10 },
{ mount: '/System/Volumes/Data', size: 1000, used: 650, available: 300, use: 68 },
{ mount: '/Volumes/External', size: 500, used: 10, available: 450, use: 2 },
])
expect(disks).toEqual([
{ mount: '/', size: 1000, used: 700, available: 300, use: 70 },
{ mount: '/Volumes/External', size: 500, used: 10, available: 450, use: 2 },
])
})

it('leaves unreported free space unknown', () => {
expect(normalizeDisks([{ mount: '/', size: 1000, used: 50, use: 5 }])[0].available).toBeNull()
})
})
35 changes: 35 additions & 0 deletions server/test/system-uptime.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { beforeEach, describe, expect, it, vi } from 'vitest'
import { uptime } from 'node:os'
import { systemProvider } from '../src/providers/system.js'

vi.mock('node:os', () => ({ uptime: vi.fn() }))
vi.mock('systeminformation', () => ({ default: {
currentLoad: vi.fn(async () => ({ currentLoad: 12, cpus: [{ load: 12 }] })),
mem: vi.fn(async () => ({ total: 100, active: 50, available: 50, swapused: 0, swaptotal: 0 })),
fsSize: vi.fn(async () => []),
networkStats: vi.fn(async () => []),
cpuTemperature: vi.fn(async () => ({ main: 0 })),
} }))

describe('OS uptime in the system snapshot', () => {
beforeEach(() => vi.mocked(uptime).mockReset())

it.each([0, 90061.9])('publishes system uptime %s seconds rather than process uptime', async (seconds) => {
vi.mocked(uptime).mockReturnValue(seconds)
expect(await systemProvider.poll!()).toMatchObject({
uptimeSeconds: Math.floor(seconds), cpu: { load: 12 }, memory: { total: 100 },
})
})

it.each([-1, NaN, Infinity])('leaves invalid reading %s unknown', async (seconds) => {
vi.mocked(uptime).mockReturnValue(seconds)
expect(await systemProvider.poll!()).toMatchObject({ uptimeSeconds: null, cpu: { load: 12 } })
})

it('keeps other metrics working when uptime access fails', async () => {
vi.mocked(uptime).mockImplementationOnce(() => { throw new Error('Permission denied') })
expect(await systemProvider.poll!()).toMatchObject({
uptimeSeconds: null, cpu: { load: 12 }, disks: [], network: [],
})
})
})
91 changes: 91 additions & 0 deletions server/test/uptime-widget.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import { readFileSync } from 'node:fs'
import { runInNewContext } from 'node:vm'
import { describe, expect, it } from 'vitest'

interface UptimeReading {
uptimeSeconds?: number | null
error?: string
}

function loadWidget(locale = 'fr') {
const html = readFileSync(new URL('../../widgets/uptime/index.html', import.meta.url), 'utf8')
const script = /<script>([\s\S]*?)<\/script>/.exec(html)?.[1]
if (!script) throw new Error('Uptime widget script is missing')

const elements = new Map<string, { textContent: string }>()
const callbacks: {
data?: (reading: UptimeReading) => void
locale?: () => void
} = {}
const channels: string[] = []
const api = {
locale,
t: (value: Record<string, string>) => value[api.locale] ?? value.en,
whenReady: (callback: () => void) => callback(),
subscribe: (channel: string, callback: (reading: UptimeReading) => void) => {
channels.push(channel)
callbacks.data = callback
},
onLocale: (callback: () => void) => { callbacks.locale = callback },
}
const document = {
documentElement: { lang: 'en' },
getElementById: (id: string) => {
if (!elements.has(id)) elements.set(id, { textContent: '' })
return elements.get(id)!
},
}
runInNewContext(script, { Fremkit: api, document })

return {
elements,
channels,
update: (reading: UptimeReading) => callbacks.data?.(reading),
language: (next: string) => {
api.locale = next
callbacks.locale?.()
},
}
}

describe('Uptime widget', () => {
it.each([
[0, '0 min'],
[59, '0 min'],
[3600, '1 h 0 min'],
[90061, '1 j 1 h 1 min'],
[260213, '3 j 0 h 16 min'],
])('formats %s seconds as %s', (seconds, expected) => {
const widget = loadWidget()
widget.update({ uptimeSeconds: seconds })
expect(widget.channels).toEqual(['system'])
expect(widget.elements.get('value')?.textContent).toBe(expected)
})

it('shows loading and missing readings explicitly', () => {
const widget = loadWidget()
expect(widget.elements.get('note')?.textContent).toBe('Chargement…')
widget.update({ uptimeSeconds: null })
expect(widget.elements.get('value')?.textContent).toBe('?')
expect(widget.elements.get('note')?.textContent).toBe('Indisponible')
})

it('marks the last measurement stale on error and recovers', () => {
const widget = loadWidget()
widget.update({ uptimeSeconds: 90061 })
widget.update({ error: 'offline' })
expect(widget.elements.get('value')?.textContent).toBe('1 j 1 h 1 min')
expect(widget.elements.get('note')?.textContent).toBe('Données anciennes')
widget.update({ uptimeSeconds: 60 })
expect(widget.elements.get('value')?.textContent).toBe('1 min')
expect(widget.elements.get('note')?.textContent).toBe('Depuis le dernier démarrage')
})

it('updates the day unit and explanation on language change', () => {
const widget = loadWidget()
widget.update({ uptimeSeconds: 90061 })
widget.language('en')
expect(widget.elements.get('value')?.textContent).toBe('1 d 1 h 1 min')
expect(widget.elements.get('note')?.textContent).toBe('Since the last system boot')
})
})
20 changes: 14 additions & 6 deletions widgets/disk/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
<html lang="en"><head><meta charset="utf-8"><title>Disks</title>
<style>
html,body{margin:0;height:100%;background:transparent;color:var(--text, #e6e8eb);font-family:var(--font, -apple-system,system-ui,sans-serif);overflow:hidden}
.wrap{box-sizing:border-box;height:100%;padding:14px 18px;position:relative;display:flex;flex-direction:column;justify-content:center;gap:6px}
.wrap{box-sizing:border-box;height:100%;padding:14px 18px;position:relative;display:flex;flex-direction:column;justify-content:safe center;overflow-y:auto;gap:5px}
.big{font-size:calc(44px * var(--text-scale, 1));font-weight:600;line-height:1}
.bar{height:8px;border-radius:4px;background:var(--surface-3, #252a32);overflow:hidden}
.bar{height:8px;flex-shrink:0;border-radius:4px;background:var(--surface-3, #252a32);overflow:hidden}
.bar>i{display:block;height:100%;background:var(--accent, #d9b36a);width:0;transition:width .4s}
.row{display:flex;justify-content:space-between;font-size:calc(15px * var(--text-scale, 1))}
.row{display:flex;justify-content:space-between;align-items:baseline;gap:8px;font-size:calc(13px * var(--text-scale, 1))}
.row span:first-child{min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.row .muted{font-size:calc(12px * var(--text-scale, 1));white-space:nowrap}
.muted{color:var(--text-muted, #8b93a0)}
button{font:inherit;border:0;border-radius:10px;background:var(--surface-3, #252a32);color:var(--text, #e6e8eb);padding:10px 14px;font-size:calc(18px * var(--text-scale, 1))}
button:active{background:var(--accent, #d9b36a)}
Expand All @@ -19,7 +21,12 @@
html.accent-fill .bar>i{background:var(--on-surface,#0b0d10)}
</style></head><body><div class="wrap" id="list"></div>
<script>
var L = { gigabytes: { fr: '{n} Go', en: '{n} GB' } }
var L = {
gigabytes: { fr: '{n} Go', en: '{n} GB' },
free: { fr: '{n} libres', en: '{n} free' },
unknown: { fr: 'Libre ?', en: 'Free ?' },
system: { fr: 'Disque du Mac', en: 'Mac disk' }
}
function gb(b) { return Fremkit.t(L.gigabytes, { n: Math.round(b / 1073741824) }) }
Fremkit.whenReady(function () {
var last = null
Expand All @@ -36,8 +43,9 @@
// name is escaped, and the width is a number before it reaches the style attribute.
el.innerHTML = d.disks.map(function (k) {
var use = Math.max(0, Math.min(100, Number(k.use) || 0))
return '<div class="row"><span>' + Fremkit.esc(k.mount) + '</span><span class="muted">'
+ Fremkit.esc(gb(k.used)) + ' / ' + Fremkit.esc(gb(k.size)) + '</span></div>'
var free = k.available == null ? Fremkit.t(L.unknown) : Fremkit.t(L.free, { n: gb(k.available) })
return '<div class="row"><span>' + Fremkit.esc(k.mount==='/'?Fremkit.t(L.system):k.mount) + '</span><span class="muted">'
+ Fremkit.esc(gb(k.used)) + ' / ' + Fremkit.esc(gb(k.size)) + ' · ' + Fremkit.esc(free) + '</span></div>'
+ '<div class="bar"><i style="width:' + use + '%"></i></div>'
}).join('')
}
Expand Down
2 changes: 1 addition & 1 deletion widgets/disk/manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{ "id": "disk",
"name": { "fr": "Disques", "en": "Disks" },
"version": "1.0.0",
"version": "1.0.1",
"description": { "fr": "Utilisation des disques", "en": "Disk usage" },
"category": "system",
"icon": "hard-drive", "minSize": [8, 4], "defaultSize": [16, 4], "subscriptions": ["system"] }
17 changes: 11 additions & 6 deletions widgets/memory/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
<html lang="en"><head><meta charset="utf-8"><title>Memory</title>
<style>
html,body{margin:0;height:100%;background:transparent;color:var(--text, #e6e8eb);font-family:var(--font, -apple-system,system-ui,sans-serif);overflow:hidden}
.wrap{box-sizing:border-box;height:100%;padding:14px 18px;position:relative;display:flex;flex-direction:column;justify-content:center;gap:6px}
.big{font-size:calc(44px * var(--text-scale, 1));font-weight:600;line-height:1}
.bar{height:8px;border-radius:4px;background:var(--surface-3, #252a32);overflow:hidden}
.wrap{box-sizing:border-box;height:100%;padding:8px 12px;position:relative;display:flex;flex-direction:column;justify-content:center;gap:4px}
.big{font-size:calc(34px * var(--text-scale, 1));font-weight:600;line-height:1}
.bar{height:8px;flex-shrink:0;border-radius:4px;background:var(--surface-3, #252a32);overflow:hidden}
.bar>i{display:block;height:100%;background:var(--accent, #d9b36a);width:0;transition:width .4s}
.row{display:flex;justify-content:space-between;font-size:calc(15px * var(--text-scale, 1))}
.row{display:flex;justify-content:space-between;font-size:calc(13px * var(--text-scale, 1))}
.muted{color:var(--text-muted, #8b93a0)}
#free,#swap{font-size:calc(12px * var(--text-scale, 1));line-height:1.2}
button{font:inherit;border:0;border-radius:10px;background:var(--surface-3, #252a32);color:var(--text, #e6e8eb);padding:10px 14px;font-size:calc(18px * var(--text-scale, 1))}
button:active{background:var(--accent, #d9b36a)}
.note{font-size:calc(13px * var(--text-scale, 1));color:var(--text-muted, #8b93a0);letter-spacing:.06em;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
Expand All @@ -33,15 +34,17 @@
/* Right cluster: the bar pushes the iframe against the dots, so its content hugs that edge too. */
html.compact.slot-right .cwrap{align-items:flex-end;text-align:right}
html.compact.slot-right .cbar{align-self:stretch}
</style></head><body><div class="wrap"><div class="big"><span id="pct">--</span>%</div><div class="bar"><i id="bar"></i></div><div class="row muted"><span id="used"></span><span id="total"></span></div></div>
</style></head><body><div class="wrap"><div class="big"><span id="pct">--</span>%</div><div class="bar"><i id="bar"></i></div><div class="row muted"><span id="used"></span><span id="total"></span></div><div class="muted" id="free"></div><div class="muted" id="swap"></div></div>
<div class="cwrap"><div class="cline" id="cline">MEM --</div><div class="cbar"><i id="cbar"></i></div></div>
<script>
var L = {
gigabytes: { fr: '{n} Go', en: '{n} GB' },
free: { fr: '{size} disponibles', en: '{size} available' },
swap: { fr: 'Swap : {used} / {total}', en: 'Swap: {used} / {total}' },
used: { fr: '{size} utilisés', en: '{size} used' },
compact: { fr: 'MÉM {n} %', en: 'MEM {n}%' }
}
function gb(b) { return Fremkit.t(L.gigabytes, { n: (b / 1073741824).toFixed(1) }) }
function gb(b) { return Fremkit.t(L.gigabytes, { n: (b / 1073741824).toLocaleString(Fremkit.locale,{maximumFractionDigits:1}) }) }
Fremkit.whenReady(function () {
var last = null
document.documentElement.lang = Fremkit.locale
Expand All @@ -57,6 +60,8 @@
document.getElementById('bar').style.width = pct + '%'
document.getElementById('used').textContent = Fremkit.t(L.used, { size: gb(d.memory.used) })
document.getElementById('total').textContent = gb(d.memory.total)
document.getElementById('free').textContent = d.memory.free==null?'':Fremkit.t(L.free,{size:gb(d.memory.free)})
document.getElementById('swap').textContent = d.memory.swapUsed==null||d.memory.swapTotal==null?'':Fremkit.t(L.swap,{used:gb(d.memory.swapUsed),total:gb(d.memory.swapTotal)})
document.getElementById('cline').textContent = Fremkit.t(L.compact, { n: pct })
document.getElementById('cbar').style.width = pct + '%'
}
Expand Down
2 changes: 1 addition & 1 deletion widgets/memory/manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{ "id": "memory",
"name": { "fr": "Mémoire", "en": "Memory" },
"version": "1.1.0",
"version": "1.1.1",
"description": { "fr": "Utilisation mémoire", "en": "Memory usage" },
"category": "system",
"icon": "memory-stick", "minSize": [8, 4], "defaultSize": [8, 4], "compact": { "width": 4 }, "subscriptions": ["system"] }
Loading
Loading