mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 10:26:08 +01:00 
			
		
		
		
	feat(touch_bar): update zoom slider value
This commit is contained in:
		| @@ -260,6 +260,7 @@ export type CommandMappings = { | |||||||
|         TouchBar: typeof import("electron").TouchBar; |         TouchBar: typeof import("electron").TouchBar; | ||||||
|         buildIcon(name: string): NativeImage; |         buildIcon(name: string): NativeImage; | ||||||
|     }; |     }; | ||||||
|  |     refreshTouchBar: CommandData; | ||||||
| }; | }; | ||||||
|  |  | ||||||
| type EventMappings = { | type EventMappings = { | ||||||
|   | |||||||
| @@ -53,6 +53,8 @@ export default class GeoMapWidget extends NoteContextAwareWidget { | |||||||
|                 this.initCallback(L); |                 this.initCallback(L); | ||||||
|             } |             } | ||||||
|  |  | ||||||
|  |             map.addEventListener("zoom", () => this.triggerCommand("refreshTouchBar")); | ||||||
|  |  | ||||||
|             L.tileLayer("https://tile.openstreetmap.org/{z}/{x}/{y}.png", { |             L.tileLayer("https://tile.openstreetmap.org/{z}/{x}/{y}.png", { | ||||||
|                 attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors', |                 attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors', | ||||||
|                 detectRetina: true |                 detectRetina: true | ||||||
| @@ -69,6 +71,7 @@ export default class GeoMapWidget extends NoteContextAwareWidget { | |||||||
|         return [ |         return [ | ||||||
|             new TouchBar.TouchBarSlider({ |             new TouchBar.TouchBarSlider({ | ||||||
|                 label: "Zoom", |                 label: "Zoom", | ||||||
|  |                 value: map.getZoom(), | ||||||
|                 minValue: map.getMinZoom(), |                 minValue: map.getMinZoom(), | ||||||
|                 maxValue: map.getMaxZoom(), |                 maxValue: map.getMaxZoom(), | ||||||
|                 change(newValue) { |                 change(newValue) { | ||||||
|   | |||||||
| @@ -8,6 +8,7 @@ export default class TouchBarWidget extends NoteContextAwareWidget { | |||||||
|  |  | ||||||
|     nativeImage: typeof import("electron").nativeImage; |     nativeImage: typeof import("electron").nativeImage; | ||||||
|     remote: typeof import("@electron/remote"); |     remote: typeof import("@electron/remote"); | ||||||
|  |     lastFocusedComponent?: Component; | ||||||
|  |  | ||||||
|     constructor() { |     constructor() { | ||||||
|         super(); |         super(); | ||||||
| @@ -19,19 +20,8 @@ export default class TouchBarWidget extends NoteContextAwareWidget { | |||||||
|             const target = e.target; |             const target = e.target; | ||||||
|             const parentComponentEl = $(target).closest(".component"); |             const parentComponentEl = $(target).closest(".component"); | ||||||
|             // TODO: Remove typecast once it's no longer necessary. |             // TODO: Remove typecast once it's no longer necessary. | ||||||
|             const parentComponent = appContext.getComponentByEl(parentComponentEl[0]) as Component; |             this.lastFocusedComponent = appContext.getComponentByEl(parentComponentEl[0]) as Component; | ||||||
|             const { TouchBar } = this.remote; |             this.#refreshTouchBar(); | ||||||
|             if (!parentComponent) { |  | ||||||
|                 return; |  | ||||||
|             } |  | ||||||
|  |  | ||||||
|             let result = parentComponent.triggerCommand("buildTouchBar", { |  | ||||||
|                 TouchBar, |  | ||||||
|                 buildIcon: this.buildIcon.bind(this) |  | ||||||
|             }); |  | ||||||
|  |  | ||||||
|             const touchBar = this.#buildTouchBar(result); |  | ||||||
|             this.remote.getCurrentWindow().setTouchBar(touchBar); |  | ||||||
|         }); |         }); | ||||||
|     } |     } | ||||||
|  |  | ||||||
| @@ -54,6 +44,22 @@ export default class TouchBarWidget extends NoteContextAwareWidget { | |||||||
|         return newImage; |         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)[]) { |     #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; | ||||||
| @@ -84,4 +90,8 @@ export default class TouchBarWidget extends NoteContextAwareWidget { | |||||||
|         }); |         }); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     refreshTouchBarEvent() { | ||||||
|  |         this.#refreshTouchBar(); | ||||||
|  |     } | ||||||
|  |  | ||||||
| } | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user