feat(touch_bar): use icon for new note

This commit is contained in:
Elian Doran 2025-03-08 11:51:55 +02:00
parent a170bec3db
commit 3358b405e9
No known key found for this signature in database

View File

@ -3,10 +3,12 @@ import Component from "../components/component.js";
export default class TouchBarWidget extends Component { export default class TouchBarWidget extends Component {
nativeImage: typeof import("electron").nativeImage;
remote: typeof import("@electron/remote"); remote: typeof import("@electron/remote");
constructor() { constructor() {
super(); super();
this.nativeImage = utils.dynamicRequire("electron").nativeImage;
this.remote = utils.dynamicRequire("@electron/remote") as typeof import("@electron/remote"); this.remote = utils.dynamicRequire("@electron/remote") as typeof import("@electron/remote");
this.#setTouchBar(); this.#setTouchBar();
} }
@ -14,22 +16,24 @@ export default class TouchBarWidget extends Component {
#setTouchBar() { #setTouchBar() {
const touchBarData = this.#buildTouchBar(); const touchBarData = this.#buildTouchBar();
this.remote.getCurrentWindow().setTouchBar(touchBarData); this.remote.getCurrentWindow().setTouchBar(touchBarData);
console.log("Setting touch bar", touchBarData);
} }
#buildTouchBar() { #buildTouchBar() {
const { nativeImage } = this;
const { TouchBar } = this.remote;
const { TouchBarButton } = this.remote.TouchBar; const { TouchBarButton } = this.remote.TouchBar;
const items = [ const items = [
new TouchBarButton({ new TouchBarButton({
label: "New note", icon: nativeImage.createFromNamedImage("NSTouchBarAddDetailTemplate", [-1, 0, 1]),
click: () => { click: () => {
console.log("New note pressed."); console.log("New note pressed.");
} }
}) })
]; ];
return new this.remote.TouchBar({ console.log("Update ", items);
return new TouchBar({
items items
}); });
} }