feat(touch_bar): update zoom slider value

This commit is contained in:
Elian Doran
2025-03-08 22:46:14 +02:00
parent 36eac98b4d
commit ece26960c3
3 changed files with 27 additions and 13 deletions

View File

@@ -8,6 +8,7 @@ export default class TouchBarWidget extends NoteContextAwareWidget {
nativeImage: typeof import("electron").nativeImage;
remote: typeof import("@electron/remote");
lastFocusedComponent?: Component;
constructor() {
super();
@@ -19,19 +20,8 @@ export default class TouchBarWidget extends NoteContextAwareWidget {
const target = e.target;
const parentComponentEl = $(target).closest(".component");
// TODO: Remove typecast once it's no longer necessary.
const parentComponent = appContext.getComponentByEl(parentComponentEl[0]) as Component;
const { TouchBar } = this.remote;
if (!parentComponent) {
return;
}
let result = parentComponent.triggerCommand("buildTouchBar", {
TouchBar,
buildIcon: this.buildIcon.bind(this)
});
const touchBar = this.#buildTouchBar(result);
this.remote.getCurrentWindow().setTouchBar(touchBar);
this.lastFocusedComponent = appContext.getComponentByEl(parentComponentEl[0]) as Component;
this.#refreshTouchBar();
});
}
@@ -54,6 +44,22 @@ export default class TouchBarWidget extends NoteContextAwareWidget {
return newImage;
}
#refreshTouchBar() {
const { TouchBar } = this.remote;
const parentComponent = this.lastFocusedComponent;
if (!parentComponent) {
return;
}
let result = parentComponent.triggerCommand("buildTouchBar", {
TouchBar,
buildIcon: this.buildIcon.bind(this)
});
const touchBar = this.#buildTouchBar(result);
this.remote.getCurrentWindow().setTouchBar(touchBar);
}
#buildTouchBar(componentSpecificItems?: (TouchBarButton | TouchBarSpacer | TouchBarGroup | TouchBarSegmentedControl)[]) {
const { TouchBar } = this.remote;
const { TouchBarButton, TouchBarSpacer, TouchBarGroup, TouchBarSegmentedControl, TouchBarOtherItemsProxy } = this.remote.TouchBar;
@@ -84,4 +90,8 @@ export default class TouchBarWidget extends NoteContextAwareWidget {
});
}
refreshTouchBarEvent() {
this.#refreshTouchBar();
}
}