Notes/src/public/app/widgets/touch_bar.ts

47 lines
1.3 KiB
TypeScript
Raw Normal View History

2025-03-08 11:39:04 +02:00
import utils from "../services/utils.js";
import Component from "../components/component.js";
export default class TouchBarWidget extends Component {
2025-03-08 11:51:55 +02:00
nativeImage: typeof import("electron").nativeImage;
2025-03-08 11:39:04 +02:00
remote: typeof import("@electron/remote");
constructor() {
super();
2025-03-08 11:51:55 +02:00
this.nativeImage = utils.dynamicRequire("electron").nativeImage;
2025-03-08 11:39:04 +02:00
this.remote = utils.dynamicRequire("@electron/remote") as typeof import("@electron/remote");
this.#setTouchBar();
}
#setTouchBar() {
const touchBarData = this.#buildTouchBar();
this.remote.getCurrentWindow().setTouchBar(touchBarData);
}
#buildIcon(name: string) {
return this.nativeImage
.createFromNamedImage(name, [-1, 0, 1])
.resize({ height: 20 });
}
2025-03-08 11:39:04 +02:00
#buildTouchBar() {
2025-03-08 11:51:55 +02:00
const { TouchBar } = this.remote;
2025-03-08 11:39:04 +02:00
const { TouchBarButton } = this.remote.TouchBar;
const items = [
new TouchBarButton({
icon: this.#buildIcon("NSTouchBarAddDetailTemplate"),
2025-03-08 11:39:04 +02:00
click: () => {
console.log("New note pressed.");
}
})
];
2025-03-08 11:51:55 +02:00
console.log("Update ", items);
return new TouchBar({
2025-03-08 11:39:04 +02:00
items
});
}
}