Move Roam settings out of the Settings app and into the Roam app itself

This commit is contained in:
James Babcock committed 2026-08-30 15:34:33 -07:00
1 parent cd25ec60f1
commit ccd28b7ac9
4 files changed
+97 -19

No files matched your search

+3 -3
View File
@@ -104,7 +104,7 @@ async function roamPost(endpoint: "q" | "pull" | "write", body: object): Promise
const graph = roamGraphNameSetting.get(); const graph = roamGraphNameSetting.get();
const token = roamApiTokenSetting.get(); const token = roamApiTokenSetting.get();
if (!graph || !token) { if (!graph || !token) {
throw new Error("Set the Roam graph name and API token in Settings > Roam."); throw new Error("Set the Roam graph name and API token from the Roam app's long-press menu.");
} }
const path = `/api/graph/${encodeURIComponent(graph)}/${endpoint}`; const path = `/api/graph/${encodeURIComponent(graph)}/${endpoint}`;
const payload = JSON.stringify(body); const payload = JSON.stringify(body);
@@ -166,8 +166,8 @@ async function fetchWithTimeout(url: string, payload: string, token: string): Pr
} }
async function describeHttpError(response: Response): Promise<string> { async function describeHttpError(response: Response): Promise<string> {
if (response.status === 401) return "Roam API rejected the token (check Settings > Roam)."; if (response.status === 401) return "Roam API rejected the token (check Set API token in the menu).";
if (response.status === 404) return "Roam graph not found (check the graph name in Settings > Roam)."; if (response.status === 404) return "Roam graph not found (check Set graph name in the menu).";
if (response.status === 429) return "Roam API rate limit hit; try again shortly."; if (response.status === 429) return "Roam API rate limit hit; try again shortly.";
if (response.status === 503) return "Roam graph is not ready yet; try again shortly."; if (response.status === 503) return "Roam graph is not ready yet; try again shortly.";
let detail = ""; let detail = "";
+93 -6
View File
@@ -4,6 +4,8 @@
* todo or follows a [[page]] link, double-click walks back through visited * todo or follows a [[page]] link, double-click walks back through visited
* pages then yields focus. Edits (check/uncheck, add todo, edit block) go * pages then yields focus. Edits (check/uncheck, add todo, edit block) go
* through the Roam backend API and are also exposed as assistant tools. * through the Roam backend API and are also exposed as assistant tools.
* The graph name and API token are configured here too, from the long-press
* menu, via the phone app's text editor.
*/ */
import "@nativescript/core/globals"; import "@nativescript/core/globals";
import { GrayImage } from "../../graphics/image"; import { GrayImage } from "../../graphics/image";
@@ -12,11 +14,17 @@ import { prepareFrameDraws } from "../../graphics/glyph-wire";
import { getDefaultSmallFont } from "../../graphics/ui-fonts"; import { getDefaultSmallFont } from "../../graphics/ui-fonts";
import { truncateText, wrapText } from "../../graphics/textwrap"; import { truncateText, wrapText } from "../../graphics/textwrap";
import * as frameTimings from "../../native/frame-timings"; import * as frameTimings from "../../native/frame-timings";
import { onSettingsStoreChanged } from "../../native/settings-store";
import type { MenuItem } from "../../ui/menu"; import type { MenuItem } from "../../ui/menu";
import { defaultWindowMenuItems, WindowMenu } from "../../ui/window-menu"; import { defaultWindowMenuItems, WindowMenu } from "../../ui/window-menu";
import type { WorkerAppMessage, WorkerAppReply } from "../../ui/shell/worker-window"; import type { WorkerAppMessage, WorkerAppReply } from "../../ui/shell/worker-window";
import type { ToolResult, ToolSpec } from "../../assistant/tool-registry"; import type { ToolResult, ToolSpec } from "../../assistant/tool-registry";
import { GESTURE_CLICK, type InputEvent } from "../../ui/gestures"; import { GESTURE_CLICK, type InputEvent } from "../../ui/gestures";
import {
roamApiTokenSetting,
roamGraphNameSetting,
type ConfigSettingString,
} from "../../ui/dashboard-settings";
import { DocumentView } from "../../ui/document/document-view"; import { DocumentView } from "../../ui/document/document-view";
import { docNodePageLink, type DocNode } from "../../ui/document/document-model"; import { docNodePageLink, type DocNode } from "../../ui/document/document-model";
import { import {
@@ -133,6 +141,14 @@ let loading = false;
let errorMessage = ""; let errorMessage = "";
let lastFetchMs = 0; let lastFetchMs = 0;
let loadSerial = 0; let loadSerial = 0;
/** Setting being edited on the "type on the phone" screen, when open. */
let editingSetting: ConfigSettingString | null = null;
// Live keystrokes from the phone editor (and edits from other isolates, e.g.
// a settings import): repaint the edit screen / the not-configured hint.
onSettingsStoreChanged((key) => {
if (key.startsWith("integrations.roam.")) render();
});
function post(message: WorkerAppReply): void { function post(message: WorkerAppReply): void {
global.postMessage(message); global.postMessage(message);
@@ -160,6 +176,11 @@ global.onmessage = (event: { data: WorkerAppMessage }) => {
void loadPage(todayRef(), { resetStack: true }); void loadPage(todayRef(), { resetStack: true });
break; break;
case "close-window": case "close-window":
if (editingSetting) {
// Window closed mid-edit: shut the phone editor down.
editingSetting = null;
post({ type: "end-text-setting-edit" });
}
window = null; window = null;
break; break;
case "input": case "input":
@@ -175,8 +196,12 @@ global.onmessage = (event: { data: WorkerAppMessage }) => {
handleInput(window, message.event as InputEvent, message.frameId); handleInput(window, message.event as InputEvent, message.frameId);
break; break;
case "text-input": case "text-input":
// Voice input / typed text becomes a new todo on the shown page. if (editingSetting) {
if (message.text.trim()) { // Voice input as an alternative to the phone keyboard.
editingSetting.set(message.text.trim());
render();
} else if (message.text.trim()) {
// Voice input / typed text becomes a new todo on the shown page.
void addTodoFromText(message.text.trim()); void addTodoFromText(message.text.trim());
} }
break; break;
@@ -332,15 +357,42 @@ function menuItems(win: RoamWindow): MenuItem[] {
}); });
} }
items.push({ items.push({
label: "Roam settings", label: "Set graph name",
onSelect: (ctx) => { onSelect: (ctx) => {
ctx.stack.pop(); ctx.stack.pop();
post({ type: "open-settings", section: "Roam" }); beginSettingEdit(roamGraphNameSetting);
},
});
items.push({
label: "Set API token",
onSelect: (ctx) => {
ctx.stack.pop();
beginSettingEdit(roamApiTokenSetting);
}, },
}); });
return [...items, ...defaultWindowMenuItems(win.windowId, post)]; return [...items, ...defaultWindowMenuItems(win.windowId, post)];
} }
/**
* Enter the setting-edit screen and ask the shell to open the phone app's
* text editor on the setting. The editor writes the setting live; click (or
* double-click) here finishes the edit.
*/
function beginSettingEdit(setting: ConfigSettingString): void {
editingSetting = setting;
post({ type: "start-text-setting-edit", settingId: setting.id });
render();
}
/** Leave the edit screen; if Roam just became usable, load the page. */
function endSettingEdit(): void {
editingSetting = null;
post({ type: "end-text-setting-edit" });
if (isRoamConfigured() && (!currentPage || errorMessage)) {
void loadPage(currentRef ?? todayRef(), { resetStack: !currentRef });
}
}
function handleInput(win: RoamWindow, event: InputEvent, frameId: number): void { function handleInput(win: RoamWindow, event: InputEvent, frameId: number): void {
if (win.menu?.isOpen()) { if (win.menu?.isOpen()) {
win.menu win.menu
@@ -349,6 +401,15 @@ function handleInput(win: RoamWindow, event: InputEvent, frameId: number): void
.then(() => renderAndSubmit(win, frameId)); .then(() => renderAndSubmit(win, frameId));
return; return;
} }
if (editingSetting) {
if (event.type === "click" || event.type === "double-click") {
endSettingEdit();
renderAndSubmit(win, frameId);
} else {
frameTimings.finishFrame(frameId, "discarded: roam edit-screen ignored input");
}
return;
}
if (event.type === "long-press") { if (event.type === "long-press") {
windowMenu(win).open(menuItems(win)); windowMenu(win).open(menuItems(win));
renderAndSubmit(win, frameId); renderAndSubmit(win, frameId);
@@ -451,7 +512,7 @@ async function addTodoFromText(text: string): Promise<void> {
async function handleRoamTool(name: string, args: any): Promise<ToolResult> { async function handleRoamTool(name: string, args: any): Promise<ToolResult> {
if (!isRoamConfigured()) { if (!isRoamConfigured()) {
return { ok: false, error: "Roam is not configured; set the graph name and API token in Settings > Roam." }; return { ok: false, error: "Roam is not configured; set the graph name and API token from the Roam app's long-press menu." };
} }
switch (name) { switch (name) {
case "read_page": { case "read_page": {
@@ -513,9 +574,35 @@ async function handleRoamTool(name: string, args: any): Promise<ToolResult> {
function paint(win: RoamWindow): Plane[] { function paint(win: RoamWindow): Plane[] {
if (win.menu?.isOpen()) return win.menu.paint(); if (win.menu?.isOpen()) return win.menu.paint();
if (editingSetting) return singlePlane(paintSettingEdit(win, editingSetting));
return singlePlane(paintContent(win)); return singlePlane(paintContent(win));
} }
/** The "type on the phone" screen shown while a Roam setting is being edited. */
function paintSettingEdit(win: RoamWindow, setting: ConfigSettingString): GrayImage {
const image = new GrayImage(win.viewportWidth, win.viewportHeight, 0);
const step = smallFont.lineHeight + 2;
image.drawText(smallFont, DOC_MARGIN + 2, 6, setting.glassesEditTitle, 225);
image.drawLine(DOC_MARGIN, HEADER_HEIGHT - 4, win.viewportWidth - DOC_MARGIN, HEADER_HEIGHT - 4, 40);
const messageY = HEADER_HEIGHT + 16;
const lines = wrapText(smallFont, "Type the value in the phone app, or use voice input.", win.viewportWidth - DOC_MARGIN * 2 - 24);
for (let index = 0; index < lines.length; index++) {
image.drawText(smallFont, DOC_MARGIN + 12, messageY + index * step, lines[index]!, 190);
}
// The live value, unmasked so the user can check what they typed.
const value = setting.get();
const valueY = messageY + (lines.length + 1) * step;
image.drawText(
smallFont,
DOC_MARGIN + 12,
valueY,
truncateText(smallFont, value || "(empty)", win.viewportWidth - DOC_MARGIN * 2 - 24),
value ? 225 : 130,
);
image.drawText(smallFont, DOC_MARGIN + 12, win.viewportHeight - smallFont.lineHeight - 12, `${GESTURE_CLICK} done`, 110);
return image;
}
function paintContent(win: RoamWindow): GrayImage { function paintContent(win: RoamWindow): GrayImage {
const image = new GrayImage(win.viewportWidth, win.viewportHeight, 0); const image = new GrayImage(win.viewportWidth, win.viewportHeight, 0);
const title = currentRef?.title ?? "Roam"; const title = currentRef?.title ?? "Roam";
@@ -534,7 +621,7 @@ function paintContent(win: RoamWindow): GrayImage {
image.drawLine(DOC_MARGIN, HEADER_HEIGHT - 4, win.viewportWidth - DOC_MARGIN, HEADER_HEIGHT - 4, 40); image.drawLine(DOC_MARGIN, HEADER_HEIGHT - 4, win.viewportWidth - DOC_MARGIN, HEADER_HEIGHT - 4, 40);
if (!isRoamConfigured()) { if (!isRoamConfigured()) {
drawBodyMessage(image, win, "Set the Roam graph name and API token in Settings > Roam. Long-press for the menu, then pick Roam settings."); drawBodyMessage(image, win, "Set the Roam graph name and API token: long-press for the menu, then pick Set graph name and Set API token.");
} else if (errorMessage) { } else if (errorMessage) {
drawBodyMessage(image, win, `${errorMessage}\n\n${GESTURE_CLICK} retry`); drawBodyMessage(image, win, `${errorMessage}\n\n${GESTURE_CLICK} retry`);
} else if (currentPage && currentPage.children.length === 0 && !loading) { } else if (currentPage && currentPage.children.length === 0 && !loading) {
+1 -1
View File
@@ -57,7 +57,7 @@ async function callAppTool(
args: unknown, args: unknown,
): Promise<ToolResult> { ): Promise<ToolResult> {
if (roamGraphNameSetting.get().length === 0 || roamApiTokenSetting.get().length === 0) { if (roamGraphNameSetting.get().length === 0 || roamApiTokenSetting.get().length === 0) {
return err("Roam is not configured; the user must set the graph name and API token in Settings > Roam."); return err("Roam is not configured; the user must set the graph name and API token from the Roam app's long-press menu.");
} }
return callAppToolWithLaunch(registry, launchApp, "roam", unprefixedName, args); return callAppToolWithLaunch(registry, launchApp, "roam", unprefixedName, args);
} }
-9
View File
@@ -42,8 +42,6 @@ import {
openAiApiKeySetting, openAiApiKeySetting,
previewColorSetting, previewColorSetting,
ringConnectionModeSetting, ringConnectionModeSetting,
roamApiTokenSetting,
roamGraphNameSetting,
sonioxApiKeySetting, sonioxApiKeySetting,
enumSettingMenuItem, enumSettingMenuItem,
firmwareDebugFlagsSetting, firmwareDebugFlagsSetting,
@@ -146,13 +144,6 @@ function settingsSections(): SettingsSection[] {
toggleSettingMenuItem(terminalWakeOnBellSetting), toggleSettingMenuItem(terminalWakeOnBellSetting),
], ],
}, },
{
label: "Roam",
items: [
textSettingMenuItem(roamGraphNameSetting),
textSettingMenuItem(roamApiTokenSetting),
],
},
{ {
label: "Phone display", label: "Phone display",
// The phone app's mirror of the glasses screen and its controls // The phone app's mirror of the glasses screen and its controls