8000 Settings: a switch to turn the idle chatter off by amy95031 · Pull Request #3 · Arthur031221/Blinkling · GitHub
[go: up one dir, main page]

Skip to content
Open
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
45 changes: 45 additions & 0 deletions desktop/character/grumble.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import assert from "node:assert/strict";
import { createGrumbler } from "./grumble.mjs";
import { strings, GRUMBLES } from "../renderer/strings.mjs";
import { LOCALES } from "../shared/i18n.mjs";
import { readFileSync } from "node:fs";

const make = (extra = {}) => createGrumbler({ count: 8, ...extra });

Expand Down Expand Up @@ -45,6 +46,50 @@ test("busy keeps Blink quiet and starts the minute again", () => {
assert.equal(g.tick(150_000, false), null);
});

test("kept busy, as with the switch in Settings off, Blink never says a line", () => {
const g = make({ random: () => 0 });
for (let at = 0; at <= 3_600_000; at += 1000)
assert.equal(g.tick(at, true), null, String(at));
});

test("turned off while a line is on show, the line goes at once and none follows", () => {
const g = make({ random: () => 0 });
assert.equal(g.tick(60_000, false), 0);
for (let at = 61_000; at <= 600_000; at += 1000)
assert.equal(g.tick(at, true), null, String(at));
// Turned on again, the quiet minute starts from that moment.
assert.equal(g.tick(659_000, false), null);
assert.equal(g.tick(660_000, false), 1);
});

test("the switch in Settings reaches the grumbler: stored, sent with the state, read every frame", () => {
const read = (file) => readFileSync(new URL(file, import.meta.url), "utf8");
const shell = read("../main/shell.mjs");
// Main reads the stored choice at start and hears a change from Settings.
assert.match(
shell,
/idleGrumble = settings\.store\.get\(\)\.idleGrumble !== false/,
);
assert.match(
shell,
/idleGrumbleChanged: \(on\) => \{\s*idleGrumble = on;\s*broadcast\(\);/,
);
// It goes to Blink's window in the state every window gets.
const snapshot = shell.slice(
shell.indexOf("const snapshot = () => ({"),
shell.indexOf("function motion("),
);
assert.match(snapshot, /^\s*idleGrumble,$/m);
// Off counts as busy, which is what keeps the grumbler quiet.
const renderer = read("../renderer/index.mjs");
const busy = renderer.slice(
renderer.indexOf("const busy ="),
renderer.indexOf("grumbler.tick(now, busy)"),
);
assert.ok(busy.length > 0, "the grumbler is ticked with busy");
assert.match(busy, /shell\.idleGrumble === false \|\|/);
});

test("a touch takes a shown line away and the quiet starts over", () => {
const g = make({ random: () => 0 });
assert.equal(g.tick(60_000, false), 0);
Expand Down
8 changes: 8 additions & 0 deletions desktop/main/shell.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ const snapshot = () => ({
chatFocused: !!composer && !composer.isDestroyed() && composer.isFocused(),
autoExplain,
costume: costumeWorn(),
idleGrumble,
debugHit: process.env.BLINKLING_DEBUG_HIT === "1",
theme: nativeTheme.shouldUseDarkColors ? "dark" : "light",
locale,
Expand Down Expand Up @@ -1162,6 +1163,8 @@ ipcMain.handle("blinkling:send", async (event, turn) => {
/** The costume switch in Settings: on, Blink wears the chosen model's piece and
* plays a scene when the model or the effort changes. */
let costumeEffects = true;
/** The idle chatter switch in Settings: off, Blink never thinks out loud. */
let idleGrumble = true;
/** The family whose piece Blink wears now, or null. */
const costumeWorn = () =>
costumeEffects
Expand Down Expand Up @@ -1684,13 +1687,18 @@ const settings = installSettings({
costumeEffects = on;
broadcast();
},
idleGrumbleChanged: (on) => {
idleGrumble = on;
broadcast();
},
languageChanged: (chosen) => {
locale = changeSystemLocale({ app, chosen });
broadcast();
},
},
});
costumeEffects = settings.store.get().costumeEffects !== false;
idleGrumble = settings.store.get().idleGrumble !== false;
// The image viewer covers the display Blink is on; while it is up the machine
// knows, so Blink holds still behind it.
const viewer = installViewer({
Expand Down
4 changes: 3 additions & 1 deletion desktop/renderer/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -381,8 +381,10 @@ async function action(id) {
grumbling: grumbling !== null,
});
// Idle for a minute, Blink thinks out loud. Anything that keeps it busy
// or any use of the app starts the quiet again.
// or any use of the app starts the quiet again. With the switch in
// Settings off it never does, and a line on show goes away.
const busy =
shell.idleGrumble === false ||
session.expression !== "idle" ||
shell.chatOpen ||
!!shell.drag ||
Expand Down
15 changes: 15 additions & 0 deletions desktop/settings/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,21 @@ <h2 data-text="costumeEffects"></h2>
</div>
</section>

<section class="settings-row" id="row-grumble">
<div class="settings-text">
<h2 data-text="idleGrumble"></h2>
<p data-text="idleGrumbleHint"></p>
</div>
<div class="settings-control">
<button
type="button"
role="switch"
id="grumble-switch"
class="settings-switch"
></button>
</div>
</section>

<section class="settings-row" id="row-language">
<div class="settings-text">
<h2 data-text="language"></h2>
Expand Down
8 changes: 8 additions & 0 deletions desktop/settings/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const HELP = new Set(["welcome", "guide"]);
* win: {webContents, isDestroyed, isVisible, isFocused, setBounds, showInactive,
* hide, focus}; ipc: {on, handle}; store: settings store; hotkey: {get, set}; quitKey: {get, set};
* pickKey: {get, set} (used on macOS only); host: {welcome, guide,
* costumeEffectsChanged(on), idleGrumbleChanged(on),
* languageChanged(value)}, where languageChanged puts every window into the
* new language in place; `locale` may be a function, read on each use;
* focus: {remember, activate, restore}. */
Expand Down Expand Up @@ -53,6 +54,7 @@ export function createSettingsController({
pickKeys: mac ? [...PICK_KEYS] : null,
startWithClaudeCode: store.get().startWithClaudeCode,
costumeEffects: store.get().costumeEffects,
idleGrumble: store.get().idleGrumble,
language: store.get().language,
languages: LOCALES.map((code) => ({ code, name: LANGUAGE_NAMES[code] })),
});
Expand Down Expand Up @@ -120,6 +122,12 @@ export function createSettingsController({
host.costumeEffectsChanged?.(value);
return { ok: true, state: view() };
}
if (key === "idleGrumble") {
if (typeof value !== "boolean") return refuse();
store.set({ idleGrumble: value });
host.idleGrumbleChanged?.(value);
return { ok: true, state: view() };
}
if (key === "language") {
const before = store.get().language;
store.set({ language: value });
Expand Down
29 changes: 29 additions & 0 deletions desktop/settings/index.test.mjs
10BC8
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ async function setup({
welcome: 0,
guide: 0,
languages: [],
grumbles: [],
restored: 0,
remembered: 0,
};
Expand Down Expand Up @@ -87,6 +88,7 @@ async function setup({
welcome: () => void log.welcome++,
guide: () => void log.guide++,
languageChanged: (value) => void log.languages.push(value),
idleGrumbleChanged: (on) => void log.grumbles.push(on),
},
focus: {
remember: async () => void log.remembered++,
Expand Down Expand Up @@ -256,6 +258,33 @@ test("start with Claude Code is stored for the launcher", async () => {
assert.equal(await startWithClaudeCode(dir), false);
});

test("the idle chatter switch is stored, shown in the state and told to the shell", async () => {
const { ask, log, dir } = await setup();
assert.equal((await ask("blinkling:settings-ready")).idleGrumble, true);
const off = await ask("blinkling:settings-set", {
key: "idleGrumble",
value: false,
});
assert.equal(off.ok, true);
assert.equal(off.state.idleGrumble, false);
assert.equal(
createSettingsStore(join(dir, "settings.json")).get().idleGrumble,
false,
);
const refused = await ask("blinkling:settings-set", {
key: "idleGrumble",
value: "off",
});
assert.equal(refused.ok, false);
assert.equal(refused.state.idleGrumble, false);
const on = await ask("blinkling:settings-set", {
key: "idleGrumble",
value: true,
});
assert.equal(on.state.idleGrumble, true);
assert.deepEqual(log.grumbles, [false, true]);
});

test("unknown settings and wrong types are refused without a throw", async () => {
const { ask } = await setup();
for (const request of [
Expand Down
7 changes: 7 additions & 0 deletions desktop/settings/renderer.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const rows = {
const change = rows.hotkey.change;
const start = $("#start-switch");
const costume = $("#costume-switch");
const idleGrumble = $("#grumble-switch");
const pickRow = $("#row-pick");
const language = $("#language-select");

Expand Down Expand Up @@ -94,6 +95,8 @@ function render() {
start.setAttribute("aria-label", t("startWithClaude"));
costume.setAttribute("aria-checked", String(state.costumeEffects));
costume.setAttribute("aria-label", t("costumeEffects"));
idleGrumble.setAttribute("aria-checked", String(state.idleGrumble));
idleGrumble.setAttribute("aria-label", t("idleGrumble"));
pickRow.hidden = !state.pickKeys;
pickRow
.querySelector("[role=radiogroup]")
Expand Down Expand Up @@ -180,6 +183,10 @@ start.addEventListener("click", async () => {
await apply("startWithClaudeCode", !state.startWithClaudeCode);
render();
});
idleGrumble.addEventListener("click", async () => {
await apply("idleGrumble", !state.idleGrumble);
render();
});
for (const button of pickRow.querySelectorAll("[data-pick]"))
button.addEventListener("click", async () => {
await apply("pickKey", button.dataset.pick);
Expand Down
2 changes: 2 additions & 0 deletions desktop/settings/store.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ import { LOCALES } from "../shared/i18n.mjs";
const DEFAULTS = Object.freeze({
startWithClaudeCode: true,
costumeEffects: true,
idleGrumble: true,
language: "system",
});
const isBoolean = (value) => typeof value === "boolean";
const isLanguage = (value) => value === "system" || LOCALES.includes(value);
const CHECKS = Object.freeze({
startWithClaudeCode: isBoolean,
costumeEffects: isBoolean,
idleGrumble: isBoolean,
language: isLanguage,
});

Expand Down
15 changes: 15 additions & 0 deletions desktop/settings/store.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ test("start with Claude Code is on until the user turns it off", async () => {
startWithClaudeCode: true,
language: "system",
costumeEffects: true,
idleGrumble: true,
});
});

Expand All @@ -28,6 +29,19 @@ test("costume effects are on until turned off, and the choice is kept", async ()
assert.equal(createSettingsStore(file).get().costumeEffects, false);
});

test("the idle chatter is on until turned off, and the choice is kept", async () => {
const dir = await home();
const file = join(dir, "settings.json");
assert.equal(createSettingsStore(file).get().idleGrumble, true);
createSettingsStore(file).set({ idleGrumble: false });
assert.equal(createSettingsStore(file).get().idleGrumble, false);
assert.throws(() => createSettingsStore(file).set({ idleGrumble: "no" }));
assert.equal(createSettingsStore(file).get().idleGrumble, false);
// A file written before the switch existed keeps Blink as it was.
await writeFile(file, '{"schemaVersion":1,"startWithClaudeCode":false}');
assert.equal(createSettingsStore(file).get().idleGrumble, true);
});

test("a change is written where the launcher reads it", async () => {
const dir = await home();
const store = createSettingsStore(join(dir, "settings.json"));
Expand All @@ -42,6 +56,7 @@ test("a change is written where the launcher reads it", async () => {
startWithClaudeCode: true,
language: "system",
costumeEffects: true,
idleGrumble: true,
});
});

Expand Down
25 changes: 25 additions & 0 deletions desktop/settings/strings.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ export const strings = {
costumeEffects: "Costume effects",
costumeEffectsHint:
"Blink wears a piece for the chosen model and plays a short scene when it changes",
idleGrumble: "Idle chatter",
idleGrumbleHint:
"After a quiet minute Blink says a short line from the edge. Off, it stays quiet",
language: "Language",
languageHint:
"Every Blink window changes to the language you choose at once",
Expand Down Expand Up @@ -63,6 +66,8 @@ export const strings = {
costumeEffects: "服裝特效",
costumeEffectsHint:
"依所選模型讓 Blink 穿上一件配件,切換時播放短短的變身動畫",
idleGrumble: "閒置碎念",
idleGrumbleHint: "安靜一分鐘後,Blink 會在邊緣說一句話。關閉後就不再說",
language: "語言",
languageHint: "選擇後所有 Blink 視窗會立刻改用該語言",
languageSystem: "跟隨電腦",
Expand Down Expand Up @@ -101,6 +106,8 @@ export const strings = {
costumeEffects: "服装特效",
costumeEffectsHint:
"按所选模型让 Blink 穿上一件配饰,切换时播放简短的变身动画",
idleGrumble: "空闲碎碎念",
idleGrumbleHint: "安静一分钟后,Blink 会在边缘说一句话。关闭后就不再说",
language: "语言",
languageHint: "选择后所有 Blink 窗口会立刻改用该语言",
languageSystem: "跟随电脑",
Expand Down Expand Up @@ -140,6 +147,9 @@ export const strings = {
costumeEffects: "コスチューム演出",
costumeEffectsHint:
"選んだモデルに合わせて Blink が小物を身につけ、切り替え時に短い変身シーンを流します",
idleGrumble: "ひとりごと",
idleGrumbleHint:
"1 分ほど静かだと Blink が端でひとこと話します。オフにすると話しません",
language: "言語",
languageHint: "選ぶと Blink のすべてのウィンドウがすぐにその言語になります",
languageSystem: "コンピューターに合わせる",
Expand Down Expand Up @@ -182,6 +192,9 @@ export const strings = {
costumeEffects: "의상 효과",
costumeEffectsHint:
"선택한 모델에 맞는 소품을 Blink가 착용하고, 바꿀 때 짧은 변신 장면을 보여 줍니다",
idleGrumble: "혼잣말",
idleGrumbleHint:
"1분쯤 조용하면 Blink가 가장자리에서 한마디 합니다. 끄면 말하지 않습니다",
language: "언어",
languageHint: "선택하면 Blink의 모든 창이 바로 그 언어로 바뀝니다",
languageSystem: "컴퓨터와 같게",
Expand Down Expand Up @@ -223,6 +236,9 @@ export const strings = {
costumeEffects: "Kostümeffekte",
costumeEffectsHint:
"Blink trägt ein Teil zum gewählten Modell und spielt beim Wechsel eine kurze Szene",
idleGrumble: "Selbstgespräche",
idleGrumbleHint:
"Nach einer ruhigen Minute sagt Blink am Rand einen kurzen Satz. Aus bleibt es still",
language: "Sprache",
languageHint: "Alle Blink-Fenster wechseln sofort in die gewählte Sprache",
languageSystem: "Wie der Computer",
Expand Down Expand Up @@ -264,6 +280,9 @@ export const strings = {
costumeEffects: "Efectos de disfraz",
costumeEffectsHint:
"Blink lleva una pieza del modelo elegido y muestra una escena corta al cambiar",
idleGrumble: "Comentarios en reposo",
idleGrumbleHint:
"Tras un minuto de calma, Blink dice una frase corta desde el borde. Apagado, se queda callado",
language: "Idioma",
languageHint:
"Todas las ventanas de Blink cambian al instante al idioma que elijas",
Expand Down Expand Up @@ -309,6 +328,9 @@ export const strings = {
costumeEffects: "Effets de costume",
costumeEffectsHint:
"Blink porte une pièce du modèle choisi et joue une courte scène au changement",
idleGrumble: "Petites phrases au repos",
idleGrumbleHint:
"Après une minute de calme, Blink dit une courte phrase depuis le bord. Désactivé, il reste silencieux",
language: "Langue",
languageHint:
"Toutes les fenêtres de Blink passent aussitôt à la langue choisie",
Expand Down Expand Up @@ -353,6 +375,9 @@ export const strings = {
costumeEffects: "Efeitos de fantasia",
costumeEffectsHint:
"O Blink usa uma peça do modelo escolhido e mostra uma cena curta ao trocar",
idleGrumble: "Comentários em repouso",
idleGrumbleHint:
"Depois de um minuto de calma, o Blink diz uma frase curta na borda. Desligado, ele fica quieto",
language: "Idioma",
languageHint:
"Todas as janelas do Blink mudam na hora para o idioma escolhido",
Expand Down
0