diff --git a/icons/touch-bar-plus.png b/icons/touch-bar-plus.png new file mode 100644 index 00000000..190f719e Binary files /dev/null and b/icons/touch-bar-plus.png differ diff --git a/src/hub/hub.ts b/src/hub/hub.ts index e5b7813e..7ba4689f 100644 --- a/src/hub/hub.ts +++ b/src/hub/hub.ts @@ -2,10 +2,10 @@ import { AdvantageScopeAssets } from "../shared/AdvantageScopeAssets"; import { HubState } from "../shared/HubState"; import { SIM_ADDRESS, USB_ADDRESS } from "../shared/IPAddresses"; import Log from "../shared/log/Log"; -import { getEnabledData, searchFields } from "../shared/log/LogUtil"; +import { getEnabledData } from "../shared/log/LogUtil"; import NamedMessage from "../shared/NamedMessage"; import Preferences from "../shared/Preferences"; -import { htmlEncode } from "../shared/util"; +import { clampValue, htmlEncode, scaleValue } from "../shared/util"; import { HistoricalDataSource, HistoricalDataSourceStatus } from "./dataSources/HistoricalDataSource"; import { LiveDataSource, LiveDataSourceStatus } from "./dataSources/LiveDataSource"; import loadZebra from "./dataSources/LoadZebra"; @@ -368,6 +368,23 @@ UPDATE_BUTTON.addEventListener("click", () => { window.sendMainMessage("prompt-update"); }); +// Update touch bar slider position +setInterval(() => { + if (window.platform === "darwin") { + let range = window.log.getTimestampRange(); + let liveTime = window.selection.getCurrentLiveTime(); + if (liveTime !== null) { + range[1] = liveTime; + } + let selectedTime = window.selection.getSelectedTime(); + if (selectedTime === null) { + selectedTime = range[0]; + } + let timePercent = clampValue(scaleValue(selectedTime, range, [0, 1]), 0, 1); + window.sendMainMessage("update-touch-bar-slider", timePercent); + } +}, 1000 / 60); + function handleMainMessage(message: NamedMessage) { switch (message.name) { case "restore-state": @@ -603,6 +620,15 @@ function handleMainMessage(message: NamedMessage) { setLoading(null); break; + case "update-touch-bar-slider": + let range = window.log.getTimestampRange(); + let liveTime = window.selection.getCurrentLiveTime(); + if (liveTime !== null) { + range[1] = liveTime; + } + window.selection.setSelectedTime(scaleValue(message.data, [0, 1], range)); + break; + default: console.warn("Unknown message from main process", message); break; diff --git a/src/main/main.ts b/src/main/main.ts index 85369945..380d326b 100644 --- a/src/main/main.ts +++ b/src/main/main.ts @@ -5,8 +5,11 @@ import { MenuItem, MessageChannelMain, MessagePortMain, + TouchBar, + TouchBarSlider, app, dialog, + nativeImage, nativeTheme, powerMonitor, shell @@ -56,6 +59,7 @@ let prefsWindow: BrowserWindow | null = null; let licensesWindow: BrowserWindow | null = null; let satelliteWindows: { [id: string]: BrowserWindow[] } = {}; let windowPorts: { [id: number]: MessagePortMain } = {}; +let hubTouchBarSliders: { [id: number]: TouchBarSlider } = {}; let hubStateTracker = new StateTracker(); let updateChecker = new UpdateChecker(); @@ -457,6 +461,13 @@ function handleHubMessage(window: BrowserWindow, message: NamedMessage) { ); break; + case "update-touch-bar-slider": + if (window.id in hubTouchBarSliders) { + let slider = hubTouchBarSliders[window.id]; + slider.value = Math.round(message.data * slider.maxValue); + } + break; + default: console.warn("Unknown message from hub renderer process", message); break; @@ -1328,6 +1339,54 @@ function createHubWindow() { let window = new BrowserWindow(prefs); hubWindows.push(window); + // Add touch bar menu + let resetTouchBar = () => { + let newCreated = false; + let slider = new TouchBar.TouchBarSlider({ + value: window.id in hubTouchBarSliders ? hubTouchBarSliders[window.id].value : 0, + minValue: 0, + maxValue: 10000, + change(newValue) { + sendMessage(window, "update-touch-bar-slider", newValue / slider.maxValue); + } + }); + hubTouchBarSliders[window.id] = slider; + window.setTouchBar( + new TouchBar({ + items: [ + new TouchBar.TouchBarOtherItemsProxy(), + new TouchBar.TouchBarPopover({ + icon: nativeImage.createFromPath(path.join(__dirname, "../icons/touch-bar-plus.png")), + showCloseButton: true, + items: new TouchBar({ + items: [ + new TouchBar.TouchBarScrubber({ + selectedStyle: "background", + continuous: false, + items: getAllTabTypes() + .slice(1) + .map((type) => { + return { + label: getTabIcon(type) + " " + getDefaultTabTitle(type) + }; + }), + select(index) { + if (newCreated) return; + newCreated = true; + sendMessage(window, "new-tab", index + 1); + setTimeout(resetTouchBar, 350); + } + }) + ] + }) + }), + slider + ] + }) + ); + }; + resetTouchBar(); + // Show window when loaded window.once("ready-to-show", window.show);