From c2e4af1cfa00b95353e98c78d427ad39bf98f556 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Sat, 8 Mar 2025 22:14:20 +0200 Subject: [PATCH] chore(touch_bar): bring back local config --- src/public/app/widgets/touch_bar.ts | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/public/app/widgets/touch_bar.ts b/src/public/app/widgets/touch_bar.ts index 534de0ded..38235a51d 100644 --- a/src/public/app/widgets/touch_bar.ts +++ b/src/public/app/widgets/touch_bar.ts @@ -3,6 +3,7 @@ import Component from "../components/component.js"; import appContext from "../components/app_context.js"; import NoteContextAwareWidget from "./note_context_aware_widget.js"; import type FNote from "../entities/fnote.js"; +import type { TouchBarButton, TouchBarGroup, TouchBarSegmentedControl, TouchBarSpacer } from "@electron/remote"; async function triggerTextEditorCommand(command: string, args?: object) { const editor = await appContext.tabManager.getActiveContext().getTextEditor(); @@ -35,14 +36,13 @@ export default class TouchBarWidget extends NoteContextAwareWidget { return; } - const result = parentComponent.triggerCommand("buildTouchBar", { + let result = parentComponent.triggerCommand("buildTouchBar", { TouchBar, buildIcon: this.buildIcon.bind(this) }); - if (result) { - this.remote.getCurrentWindow().setTouchBar(result); - } + const touchBar = this.#buildTouchBar(result); + this.remote.getCurrentWindow().setTouchBar(touchBar); }); } @@ -65,24 +65,29 @@ export default class TouchBarWidget extends NoteContextAwareWidget { return newImage; } - #buildTextTouchBar() { + #buildTouchBar(componentSpecificItems?: (TouchBarButton | TouchBarSpacer | TouchBarGroup | TouchBarSegmentedControl)[]) { const { TouchBar } = this.remote; const { TouchBarButton, TouchBarSpacer, TouchBarGroup, TouchBarSegmentedControl, TouchBarOtherItemsProxy } = this.remote.TouchBar; + // Disregard recursive calls or empty results. + if (!componentSpecificItems || "then" in componentSpecificItems) { + componentSpecificItems = []; + } + const items = [ new TouchBarButton({ icon: this.buildIcon("NSTouchBarComposeTemplate"), click: () => this.triggerCommand("createNoteIntoInbox") }), new TouchBarSpacer({ size: "large" }), - // data should go here + ...componentSpecificItems, new TouchBarOtherItemsProxy(), new TouchBarSpacer({ size: "flexible" }), new TouchBarButton({ icon: this.buildIcon("NSTouchBarAddDetailTemplate"), click: () => this.triggerCommand("jumpToNote") }) - ]; + ].flat(); console.log("Update ", items); return new TouchBar({