mirror of
https://github.com/Eugeny/tabby.git
synced 2025-07-22 11:28:00 +00:00
avoid unnecessary config writes
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import { app, ipcMain, Menu, Tray, shell, screen, globalShortcut, MenuItemConstructorOptions } from 'electron'
|
import { app, ipcMain, Menu, Tray, shell, screen, globalShortcut, MenuItemConstructorOptions, WebContents } from 'electron'
|
||||||
import promiseIpc from 'electron-promise-ipc'
|
import promiseIpc from 'electron-promise-ipc'
|
||||||
import * as remote from '@electron/remote/main'
|
import * as remote from '@electron/remote/main'
|
||||||
import { exec } from 'mz/child_process'
|
import { exec } from 'mz/child_process'
|
||||||
@@ -31,13 +31,9 @@ export class Application {
|
|||||||
this.useBuiltinGraphics()
|
this.useBuiltinGraphics()
|
||||||
this.ptyManager.init(this)
|
this.ptyManager.init(this)
|
||||||
|
|
||||||
ipcMain.on('app:config-change', (_event, config) => {
|
ipcMain.on('app:save-config', async (event, config) => {
|
||||||
this.broadcast('host:config-change', config)
|
await saveConfig(config)
|
||||||
this.configStore = config
|
this.broadcastExcept('host:config-change', event.sender, config)
|
||||||
})
|
|
||||||
|
|
||||||
ipcMain.on('app:save-config', (_event, data) => {
|
|
||||||
saveConfig(data)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
ipcMain.on('app:register-global-hotkey', (_event, specs) => {
|
ipcMain.on('app:register-global-hotkey', (_event, specs) => {
|
||||||
@@ -171,6 +167,14 @@ export class Application {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
broadcastExcept (event: string, except: WebContents, ...args: any[]): void {
|
||||||
|
for (const window of this.windows) {
|
||||||
|
if (window.webContents.id === except.id) {
|
||||||
|
window.send(event, ...args)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async send (event: string, ...args: any[]): Promise<void> {
|
async send (event: string, ...args: any[]): Promise<void> {
|
||||||
if (!this.hasWindows()) {
|
if (!this.hasWindows()) {
|
||||||
await this.newWindow()
|
await this.newWindow()
|
||||||
|
@@ -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, nativeImage } from 'electron'
|
import { BrowserWindow, app, ipcMain, Rectangle, Menu, screen, BrowserWindowConstructorOptions, TouchBar, nativeImage, WebContents } from 'electron'
|
||||||
import ElectronConfig = require('electron-config')
|
import ElectronConfig = require('electron-config')
|
||||||
import { enable as enableRemote } from '@electron/remote/main'
|
import { enable as enableRemote } from '@electron/remote/main'
|
||||||
import * as os from 'os'
|
import * as os from 'os'
|
||||||
@@ -33,6 +33,7 @@ const activityIcon = nativeImage.createFromPath(`${app.getAppPath()}/assets/acti
|
|||||||
export class Window {
|
export class Window {
|
||||||
ready: Promise<void>
|
ready: Promise<void>
|
||||||
isMainWindow = false
|
isMainWindow = false
|
||||||
|
webContents: WebContents
|
||||||
private visible = new Subject<boolean>()
|
private visible = new Subject<boolean>()
|
||||||
private closed = new Subject<void>()
|
private closed = new Subject<void>()
|
||||||
private window?: GlasstronWindow
|
private window?: GlasstronWindow
|
||||||
@@ -102,6 +103,8 @@ export class Window {
|
|||||||
this.window = new glasstron.BrowserWindow(bwOptions)
|
this.window = new glasstron.BrowserWindow(bwOptions)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.webContents = this.window.webContents
|
||||||
|
|
||||||
this.window.once('ready-to-show', () => {
|
this.window.once('ready-to-show', () => {
|
||||||
if (process.platform === 'darwin') {
|
if (process.platform === 'darwin') {
|
||||||
this.window.setVibrancy(macOSVibrancyType)
|
this.window.setVibrancy(macOSVibrancyType)
|
||||||
|
@@ -38,12 +38,6 @@ export abstract class HostAppService {
|
|||||||
|
|
||||||
abstract newWindow (): void
|
abstract newWindow (): void
|
||||||
|
|
||||||
/**
|
|
||||||
* Notifies other windows of config file changes
|
|
||||||
*/
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
||||||
broadcastConfigChange (_configStore: Record<string, any>): void { }
|
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
||||||
emitReady (): void { }
|
emitReady (): void { }
|
||||||
|
|
||||||
|
@@ -205,7 +205,6 @@ export class ConfigService {
|
|||||||
cleanStore = await this.maybeEncryptConfig(cleanStore)
|
cleanStore = await this.maybeEncryptConfig(cleanStore)
|
||||||
await this.platform.saveConfig(yaml.dump(cleanStore))
|
await this.platform.saveConfig(yaml.dump(cleanStore))
|
||||||
this.emitChange()
|
this.emitChange()
|
||||||
this.hostApp.broadcastConfigChange(JSON.parse(JSON.stringify(this.store)))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -58,13 +58,6 @@ export class ElectronHostAppService extends HostAppService {
|
|||||||
this.electron.ipcRenderer.send('app:new-window')
|
this.electron.ipcRenderer.send('app:new-window')
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Notifies other windows of config file changes
|
|
||||||
*/
|
|
||||||
broadcastConfigChange (configStore: Record<string, any>): void {
|
|
||||||
this.electron.ipcRenderer.send('app:config-change', configStore)
|
|
||||||
}
|
|
||||||
|
|
||||||
saveConfig (data: string): void {
|
saveConfig (data: string): void {
|
||||||
this.electron.ipcRenderer.send('app:save-config', data)
|
this.electron.ipcRenderer.send('app:save-config', data)
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user