chore(touch_bar): bring back local config

This commit is contained in:
Elian Doran 2025-03-08 22:14:20 +02:00
parent db8d47183d
commit c2e4af1cfa
No known key found for this signature in database

View File

@ -3,6 +3,7 @@ import Component from "../components/component.js";
import appContext from "../components/app_context.js"; import appContext from "../components/app_context.js";
import NoteContextAwareWidget from "./note_context_aware_widget.js"; import NoteContextAwareWidget from "./note_context_aware_widget.js";
import type FNote from "../entities/fnote.js"; import type FNote from "../entities/fnote.js";
import type { TouchBarButton, TouchBarGroup, TouchBarSegmentedControl, TouchBarSpacer } from "@electron/remote";
async function triggerTextEditorCommand(command: string, args?: object) { async function triggerTextEditorCommand(command: string, args?: object) {
const editor = await appContext.tabManager.getActiveContext().getTextEditor(); const editor = await appContext.tabManager.getActiveContext().getTextEditor();
@ -35,14 +36,13 @@ export default class TouchBarWidget extends NoteContextAwareWidget {
return; return;
} }
const result = parentComponent.triggerCommand("buildTouchBar", { let result = parentComponent.triggerCommand("buildTouchBar", {
TouchBar, TouchBar,
buildIcon: this.buildIcon.bind(this) buildIcon: this.buildIcon.bind(this)
}); });
if (result) { const touchBar = this.#buildTouchBar(result);
this.remote.getCurrentWindow().setTouchBar(result); this.remote.getCurrentWindow().setTouchBar(touchBar);
}
}); });
} }
@ -65,24 +65,29 @@ export default class TouchBarWidget extends NoteContextAwareWidget {
return newImage; return newImage;
} }
#buildTextTouchBar() { #buildTouchBar(componentSpecificItems?: (TouchBarButton | TouchBarSpacer | TouchBarGroup | TouchBarSegmentedControl)[]) {
const { TouchBar } = this.remote; const { TouchBar } = this.remote;
const { TouchBarButton, TouchBarSpacer, TouchBarGroup, TouchBarSegmentedControl, TouchBarOtherItemsProxy } = this.remote.TouchBar; const { TouchBarButton, TouchBarSpacer, TouchBarGroup, TouchBarSegmentedControl, TouchBarOtherItemsProxy } = this.remote.TouchBar;
// Disregard recursive calls or empty results.
if (!componentSpecificItems || "then" in componentSpecificItems) {
componentSpecificItems = [];
}
const items = [ const items = [
new TouchBarButton({ new TouchBarButton({
icon: this.buildIcon("NSTouchBarComposeTemplate"), icon: this.buildIcon("NSTouchBarComposeTemplate"),
click: () => this.triggerCommand("createNoteIntoInbox") click: () => this.triggerCommand("createNoteIntoInbox")
}), }),
new TouchBarSpacer({ size: "large" }), new TouchBarSpacer({ size: "large" }),
// data should go here ...componentSpecificItems,
new TouchBarOtherItemsProxy(), new TouchBarOtherItemsProxy(),
new TouchBarSpacer({ size: "flexible" }), new TouchBarSpacer({ size: "flexible" }),
new TouchBarButton({ new TouchBarButton({
icon: this.buildIcon("NSTouchBarAddDetailTemplate"), icon: this.buildIcon("NSTouchBarAddDetailTemplate"),
click: () => this.triggerCommand("jumpToNote") click: () => this.triggerCommand("jumpToNote")
}) })
]; ].flat();
console.log("Update ", items); console.log("Update ", items);
return new TouchBar({ return new TouchBar({