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);
|
|
|
|
}
|
|
|
|
|
2025-03-08 11:55:09 +02:00
|
|
|
#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({
|
2025-03-08 11:55:09 +02:00
|
|
|
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
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|