1
1
mirror of https://github.com/Eugeny/tabby.git synced 2024-12-23 18:44:20 +03:00

fixed touchbar activity indicators

This commit is contained in:
Eugene Pankov 2021-08-16 00:03:25 +02:00
parent 64955bfcd6
commit f5f88d3d9d
No known key found for this signature in database
GPG Key ID: 5896FCBBDD1CF4F4
3 changed files with 10 additions and 14 deletions

View File

@ -1,7 +1,7 @@
import * as glasstron from 'glasstron' import * as glasstron from 'glasstron'
import { Subject, Observable, debounceTime } from 'rxjs' import { Subject, Observable, debounceTime } from 'rxjs'
import { BrowserWindow, app, ipcMain, Rectangle, Menu, screen, BrowserWindowConstructorOptions, TouchBar } from 'electron' import { BrowserWindow, app, ipcMain, Rectangle, Menu, screen, BrowserWindowConstructorOptions, TouchBar, nativeImage } from 'electron'
import ElectronConfig = require('electron-config') import ElectronConfig = require('electron-config')
import * as os from 'os' import * as os from 'os'
import * as path from 'path' import * as path from 'path'
@ -28,6 +28,8 @@ abstract class GlasstronWindow extends BrowserWindow {
const macOSVibrancyType = process.platform === 'darwin' ? compareVersions.compare(macOSRelease().version, '10.14', '>=') ? 'fullscreen-ui' : 'dark' : null const macOSVibrancyType = process.platform === 'darwin' ? compareVersions.compare(macOSRelease().version, '10.14', '>=') ? 'fullscreen-ui' : 'dark' : null
const activityIcon = nativeImage.createFromPath(`${app.getAppPath()}/assets/activity.png`)
export class Window { export class Window {
ready: Promise<void> ready: Promise<void>
private visible = new Subject<boolean>() private visible = new Subject<boolean>()
@ -367,7 +369,10 @@ export class Window {
}) })
ipcMain.on('window-set-touch-bar', (_event, segments, selectedIndex) => { ipcMain.on('window-set-touch-bar', (_event, segments, selectedIndex) => {
this.touchBarControl.segments = segments this.touchBarControl.segments = segments.map(s => ({
label: s.label,
icon: s.hasActivity ? activityIcon : undefined,
})
this.touchBarControl.selectedIndex = selectedIndex this.touchBarControl.selectedIndex = selectedIndex
}) })

View File

@ -1,5 +1,5 @@
import { Injectable } from '@angular/core' import { Injectable } from '@angular/core'
import { App, IpcRenderer, Shell, Dialog, Clipboard, GlobalShortcut, Screen, Remote, AutoUpdater, TouchBar, BrowserWindow, Menu, MenuItem, NativeImage, PowerSaveBlocker } from 'electron' import { App, IpcRenderer, Shell, Dialog, Clipboard, GlobalShortcut, Screen, Remote, AutoUpdater, TouchBar, BrowserWindow, Menu, MenuItem, PowerSaveBlocker } from 'electron'
import * as remote from '@electron/remote' import * as remote from '@electron/remote'
export interface MessageBoxResponse { export interface MessageBoxResponse {
@ -15,7 +15,6 @@ export class ElectronService {
dialog: Dialog dialog: Dialog
clipboard: Clipboard clipboard: Clipboard
globalShortcut: GlobalShortcut globalShortcut: GlobalShortcut
nativeImage: typeof NativeImage
screen: Screen screen: Screen
remote: Remote remote: Remote
process: any process: any
@ -38,7 +37,6 @@ export class ElectronService {
this.screen = remote.screen this.screen = remote.screen
this.dialog = remote.dialog this.dialog = remote.dialog
this.globalShortcut = remote.globalShortcut this.globalShortcut = remote.globalShortcut
this.nativeImage = remote.nativeImage
this.autoUpdater = remote.autoUpdater this.autoUpdater = remote.autoUpdater
this.powerSaveBlocker = remote.powerSaveBlocker this.powerSaveBlocker = remote.powerSaveBlocker
this.TouchBar = remote.TouchBar this.TouchBar = remote.TouchBar

View File

@ -1,17 +1,13 @@
import { ipcRenderer, NativeImage } from 'electron' import { ipcRenderer } from 'electron'
import { Injectable, NgZone } from '@angular/core' import { Injectable, NgZone } from '@angular/core'
import { AppService, HostAppService, Platform } from 'tabby-core' import { AppService, HostAppService, Platform } from 'tabby-core'
import { ElectronService } from '../services/electron.service'
/** @hidden */ /** @hidden */
@Injectable({ providedIn: 'root' }) @Injectable({ providedIn: 'root' })
export class TouchbarService { export class TouchbarService {
private activityIcon: NativeImage
private constructor ( private constructor (
private app: AppService, private app: AppService,
private hostApp: HostAppService, private hostApp: HostAppService,
private electron: ElectronService,
private zone: NgZone, private zone: NgZone,
) { ) {
if (this.hostApp.platform !== Platform.macOS) { if (this.hostApp.platform !== Platform.macOS) {
@ -20,9 +16,6 @@ export class TouchbarService {
app.tabsChanged$.subscribe(() => this.update()) app.tabsChanged$.subscribe(() => this.update())
app.activeTabChange$.subscribe(() => this.update()) app.activeTabChange$.subscribe(() => this.update())
const activityIconPath = `${electron.app.getAppPath()}/assets/activity.png`
this.activityIcon = this.electron.nativeImage.createFromPath(activityIconPath)
app.tabOpened$.subscribe(tab => { app.tabOpened$.subscribe(tab => {
tab.titleChange$.subscribe(() => this.update()) tab.titleChange$.subscribe(() => this.update())
tab.activity$.subscribe(() => this.update()) tab.activity$.subscribe(() => this.update())
@ -40,7 +33,7 @@ export class TouchbarService {
const tabSegments = this.app.tabs.map(tab => ({ const tabSegments = this.app.tabs.map(tab => ({
label: this.shortenTitle(tab.title), label: this.shortenTitle(tab.title),
icon: this.app.activeTab !== tab && tab.hasActivity ? this.activityIcon : undefined, hasActivity: this.app.activeTab !== tab && tab.hasActivity,
})) }))
ipcRenderer.send('window-set-touch-bar', tabSegments, this.app.activeTab ? this.app.tabs.indexOf(this.app.activeTab) : undefined) ipcRenderer.send('window-set-touch-bar', tabSegments, this.app.activeTab ? this.app.tabs.indexOf(this.app.activeTab) : undefined)