moved touchbar handling into main process

This commit is contained in:
Eugene Pankov
2021-08-07 19:34:37 +02:00
parent 25fdba7104
commit 9fbf9136fc
2 changed files with 33 additions and 47 deletions

View File

@@ -1,7 +1,7 @@
import * as glasstron from 'glasstron'
import { Subject, Observable, debounceTime } from 'rxjs'
import { BrowserWindow, app, ipcMain, Rectangle, Menu, screen, BrowserWindowConstructorOptions } from 'electron'
import { BrowserWindow, app, ipcMain, Rectangle, Menu, screen, BrowserWindowConstructorOptions, TouchBar } from 'electron'
import ElectronConfig = require('electron-config')
import * as os from 'os'
import * as path from 'path'
@@ -39,6 +39,7 @@ export class Window {
private lastVibrancy: { enabled: boolean, type?: string } | null = null
private disableVibrancyWhileDragging = false
private configStore: any
private touchBarControl: any
get visible$ (): Observable<boolean> { return this.visible }
get closed$ (): Observable<void> { return this.closed }
@@ -127,7 +128,15 @@ export class Window {
this.window.webContents.setVisualZoomLevelLimits(1, 1)
this.window.webContents.setZoomFactor(1)
if (process.platform !== 'darwin') {
if (process.platform === 'darwin') {
this.touchBarControl = new TouchBar.TouchBarSegmentedControl({
segments: [],
change: index => this.send('touchbar-selection', index),
})
this.window.setTouchBar(new TouchBar({
items: [this.touchBarControl],
}))
} else {
this.window.setMenu(null)
}
@@ -357,6 +366,11 @@ export class Window {
this.window.close()
})
ipcMain.on('window-set-touch-bar', (_event, segments, selectedIndex) => {
this.touchBarControl.segments = segments
this.touchBarControl.selectedIndex = selectedIndex
})
this.window.webContents.on('new-window', event => event.preventDefault())
ipcMain.on('window-set-disable-vibrancy-while-dragging', (_event, value) => {