2020-06-03 19:41:23 +03:00
|
|
|
import * as glasstron from 'glasstron'
|
2020-06-05 11:08:20 +03:00
|
|
|
|
2018-08-31 16:41:28 +03:00
|
|
|
import { Subject, Observable } from 'rxjs'
|
2018-12-29 15:27:45 +03:00
|
|
|
import { debounceTime } from 'rxjs/operators'
|
2020-12-24 16:03:14 +03:00
|
|
|
import { BrowserWindow, app, ipcMain, Rectangle, Menu, screen, BrowserWindowConstructorOptions } from 'electron'
|
2018-08-31 16:41:28 +03:00
|
|
|
import ElectronConfig = require('electron-config')
|
2018-10-05 21:12:06 +03:00
|
|
|
import * as os from 'os'
|
2019-11-26 17:51:31 +03:00
|
|
|
import * as path from 'path'
|
2021-01-02 15:08:00 +03:00
|
|
|
import macOSRelease from 'macos-release'
|
|
|
|
import * as compareVersions from 'compare-versions'
|
2018-10-06 21:50:06 +03:00
|
|
|
|
2020-05-02 18:23:35 +03:00
|
|
|
import { parseArgs } from './cli'
|
2018-10-06 21:50:06 +03:00
|
|
|
import { loadConfig } from './config'
|
2018-08-31 16:41:28 +03:00
|
|
|
|
2020-12-24 16:03:14 +03:00
|
|
|
let DwmEnableBlurBehindWindow: any = null
|
2018-10-05 21:12:06 +03:00
|
|
|
if (process.platform === 'win32') {
|
2019-05-06 15:09:30 +03:00
|
|
|
DwmEnableBlurBehindWindow = require('windows-blurbehind').DwmEnableBlurBehindWindow
|
2018-10-05 21:12:06 +03:00
|
|
|
}
|
2018-08-31 16:41:28 +03:00
|
|
|
|
2018-11-11 15:24:27 +03:00
|
|
|
export interface WindowOptions {
|
|
|
|
hidden?: boolean
|
|
|
|
}
|
|
|
|
|
2020-12-27 15:03:38 +03:00
|
|
|
abstract class GlasstronWindow extends BrowserWindow {
|
|
|
|
blurType: string
|
|
|
|
abstract setBlur (_: boolean)
|
|
|
|
}
|
|
|
|
|
2021-01-09 19:29:34 +03:00
|
|
|
const macOSVibrancyType = process.platform === 'darwin' ? compareVersions.compare(macOSRelease().version, '10.14', '>=') ? 'fullscreen-ui' : 'dark' : null
|
2021-01-02 15:08:00 +03:00
|
|
|
|
2018-08-31 16:41:28 +03:00
|
|
|
export class Window {
|
|
|
|
ready: Promise<void>
|
|
|
|
private visible = new Subject<boolean>()
|
2020-04-19 12:47:31 +03:00
|
|
|
private closed = new Subject<void>()
|
2021-01-02 22:10:00 +03:00
|
|
|
private window?: GlasstronWindow
|
2018-08-31 16:41:28 +03:00
|
|
|
private windowConfig: ElectronConfig
|
2021-01-02 22:10:00 +03:00
|
|
|
private windowBounds?: Rectangle
|
2018-11-22 19:51:12 +03:00
|
|
|
private closing = false
|
2021-01-28 23:46:31 +03:00
|
|
|
private lastVibrancy: { enabled: boolean, type?: string } | null = null
|
2020-02-05 16:02:58 +03:00
|
|
|
private disableVibrancyWhileDragging = false
|
2020-04-19 12:47:31 +03:00
|
|
|
private configStore: any
|
2018-08-31 16:41:28 +03:00
|
|
|
|
|
|
|
get visible$ (): Observable<boolean> { return this.visible }
|
2020-04-19 12:47:31 +03:00
|
|
|
get closed$ (): Observable<void> { return this.closed }
|
2018-08-31 16:41:28 +03:00
|
|
|
|
2018-11-11 15:24:27 +03:00
|
|
|
constructor (options?: WindowOptions) {
|
2020-04-19 12:47:31 +03:00
|
|
|
this.configStore = loadConfig()
|
2018-08-31 16:41:28 +03:00
|
|
|
|
2021-01-02 21:09:34 +03:00
|
|
|
options = options ?? {}
|
2018-11-11 15:24:27 +03:00
|
|
|
|
2018-08-31 16:41:28 +03:00
|
|
|
this.windowConfig = new ElectronConfig({ name: 'window' })
|
2018-09-13 02:25:08 +03:00
|
|
|
this.windowBounds = this.windowConfig.get('windowBoundaries')
|
2018-08-31 16:41:28 +03:00
|
|
|
|
2020-12-24 16:03:14 +03:00
|
|
|
const maximized = this.windowConfig.get('maximized')
|
|
|
|
const bwOptions: BrowserWindowConstructorOptions = {
|
2018-08-31 16:41:28 +03:00
|
|
|
width: 800,
|
|
|
|
height: 600,
|
|
|
|
title: 'Terminus',
|
|
|
|
minWidth: 400,
|
2020-12-24 16:03:14 +03:00
|
|
|
minHeight: 300,
|
2019-02-20 03:57:38 +03:00
|
|
|
webPreferences: {
|
|
|
|
nodeIntegration: true,
|
2019-11-26 17:51:31 +03:00
|
|
|
preload: path.join(__dirname, 'sentry.js'),
|
2020-02-05 15:22:35 +03:00
|
|
|
backgroundThrottling: false,
|
2020-12-23 23:45:47 +03:00
|
|
|
enableRemoteModule: true,
|
2021-01-09 17:38:55 +03:00
|
|
|
contextIsolation: false,
|
2019-02-20 03:57:38 +03:00
|
|
|
},
|
2021-01-24 21:06:41 +03:00
|
|
|
maximizable: true,
|
2018-08-31 16:41:28 +03:00
|
|
|
frame: false,
|
|
|
|
show: false,
|
2019-10-26 22:11:27 +03:00
|
|
|
backgroundColor: '#00000000',
|
2018-08-31 16:41:28 +03:00
|
|
|
}
|
|
|
|
|
2019-07-04 13:04:24 +03:00
|
|
|
if (this.windowBounds) {
|
|
|
|
Object.assign(bwOptions, this.windowBounds)
|
2020-02-05 15:16:31 +03:00
|
|
|
const closestDisplay = screen.getDisplayNearestPoint( { x: this.windowBounds.x, y: this.windowBounds.y } )
|
2019-06-28 05:46:47 +03:00
|
|
|
|
2020-02-05 15:16:31 +03:00
|
|
|
const [left1, top1, right1, bottom1] = [this.windowBounds.x, this.windowBounds.y, this.windowBounds.x + this.windowBounds.width, this.windowBounds.y + this.windowBounds.height]
|
|
|
|
const [left2, top2, right2, bottom2] = [closestDisplay.bounds.x, closestDisplay.bounds.y, closestDisplay.bounds.x + closestDisplay.bounds.width, closestDisplay.bounds.y + closestDisplay.bounds.height]
|
2019-06-28 05:46:47 +03:00
|
|
|
|
2019-07-04 13:04:24 +03:00
|
|
|
if ((left2 > right1 || right2 < left1 || top2 > bottom1 || bottom2 < top1) && !maximized) {
|
2020-02-05 15:16:31 +03:00
|
|
|
bwOptions.x = closestDisplay.bounds.width / 2 - bwOptions.width / 2
|
|
|
|
bwOptions.y = closestDisplay.bounds.height / 2 - bwOptions.height / 2
|
2019-07-04 13:04:24 +03:00
|
|
|
}
|
2019-06-28 05:46:47 +03:00
|
|
|
}
|
|
|
|
|
2020-04-19 12:47:31 +03:00
|
|
|
if ((this.configStore.appearance || {}).frame === 'native') {
|
2018-11-11 15:24:27 +03:00
|
|
|
bwOptions.frame = true
|
2018-08-31 16:41:28 +03:00
|
|
|
} else {
|
|
|
|
if (process.platform === 'darwin') {
|
2021-03-03 00:41:17 +03:00
|
|
|
bwOptions.titleBarStyle = 'hidden'
|
2018-08-31 16:41:28 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-09 19:29:37 +03:00
|
|
|
if (process.platform === 'darwin') {
|
2021-01-09 19:02:01 +03:00
|
|
|
this.window = new BrowserWindow(bwOptions) as GlasstronWindow
|
2021-01-09 19:29:37 +03:00
|
|
|
} else {
|
|
|
|
this.window = new glasstron.BrowserWindow(bwOptions)
|
2021-01-02 15:08:00 +03:00
|
|
|
}
|
2020-06-03 19:41:23 +03:00
|
|
|
|
2018-08-31 16:41:28 +03:00
|
|
|
this.window.once('ready-to-show', () => {
|
|
|
|
if (process.platform === 'darwin') {
|
2021-01-02 15:08:00 +03:00
|
|
|
this.window.setVibrancy(macOSVibrancyType)
|
2020-04-19 12:47:31 +03:00
|
|
|
} else if (process.platform === 'win32' && (this.configStore.appearance || {}).vibrancy) {
|
2018-08-31 16:41:28 +03:00
|
|
|
this.setVibrancy(true)
|
|
|
|
}
|
2018-11-11 15:24:27 +03:00
|
|
|
|
|
|
|
if (!options.hidden) {
|
|
|
|
if (maximized) {
|
|
|
|
this.window.maximize()
|
|
|
|
} else {
|
|
|
|
this.window.show()
|
|
|
|
}
|
|
|
|
this.window.focus()
|
2020-05-26 18:04:39 +03:00
|
|
|
this.window.moveTop()
|
2018-09-13 02:25:08 +03:00
|
|
|
}
|
2018-08-31 16:41:28 +03:00
|
|
|
})
|
2019-06-28 05:46:47 +03:00
|
|
|
|
2020-04-20 20:21:48 +03:00
|
|
|
this.window.on('blur', () => {
|
2021-05-13 18:40:02 +03:00
|
|
|
if (this.configStore.appearance.dock !== 'off' && this.configStore.appearance?.dockHideOnBlur) {
|
2020-04-20 20:01:10 +03:00
|
|
|
this.hide()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2021-05-24 18:48:12 +03:00
|
|
|
this.window.loadURL(`file://${app.getAppPath()}/dist/index.html`, { extraHeaders: 'pragma: no-cache\n' })
|
2018-08-31 16:41:28 +03:00
|
|
|
|
2021-05-13 19:36:45 +03:00
|
|
|
this.window.webContents.setVisualZoomLevelLimits(1, 1)
|
|
|
|
this.window.webContents.setZoomFactor(1)
|
|
|
|
|
2018-08-31 16:41:28 +03:00
|
|
|
if (process.platform !== 'darwin') {
|
|
|
|
this.window.setMenu(null)
|
|
|
|
}
|
|
|
|
|
|
|
|
this.setupWindowManagement()
|
|
|
|
|
|
|
|
this.ready = new Promise(resolve => {
|
|
|
|
const listener = event => {
|
|
|
|
if (event.sender === this.window.webContents) {
|
2019-09-09 17:23:47 +03:00
|
|
|
ipcMain.removeListener('app:ready', listener as any)
|
2018-08-31 16:41:28 +03:00
|
|
|
resolve()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ipcMain.on('app:ready', listener)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-12-27 15:03:38 +03:00
|
|
|
setVibrancy (enabled: boolean, type?: string, userRequested?: boolean): void {
|
|
|
|
if (userRequested ?? true) {
|
|
|
|
this.lastVibrancy = { enabled, type }
|
|
|
|
}
|
2018-10-05 21:12:06 +03:00
|
|
|
if (process.platform === 'win32') {
|
|
|
|
if (parseFloat(os.release()) >= 10) {
|
2020-12-27 15:03:38 +03:00
|
|
|
this.window.blurType = enabled ? type === 'fluent' ? 'acrylic' : 'blurbehind' : null
|
2021-01-09 17:38:55 +03:00
|
|
|
try {
|
|
|
|
this.window.setBlur(enabled)
|
|
|
|
} catch (error) {
|
|
|
|
console.error('Failed to set window blur', error)
|
|
|
|
}
|
2018-10-05 21:12:06 +03:00
|
|
|
} else {
|
|
|
|
DwmEnableBlurBehindWindow(this.window, enabled)
|
|
|
|
}
|
2021-01-09 19:29:37 +03:00
|
|
|
} else if (process.platform === 'linux') {
|
|
|
|
this.window.setBackgroundColor(enabled ? '#00000000' : '#131d27')
|
|
|
|
this.window.setBlur(enabled)
|
2020-02-05 16:02:58 +03:00
|
|
|
} else {
|
2021-01-02 15:08:00 +03:00
|
|
|
this.window.setVibrancy(enabled ? macOSVibrancyType : null)
|
2018-08-31 16:41:28 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-01 18:10:45 +03:00
|
|
|
show (): void {
|
2018-08-31 16:41:28 +03:00
|
|
|
this.window.show()
|
2020-05-26 18:04:39 +03:00
|
|
|
this.window.moveTop()
|
2018-08-31 16:41:28 +03:00
|
|
|
}
|
|
|
|
|
2020-03-01 18:10:45 +03:00
|
|
|
focus (): void {
|
2018-08-31 16:41:28 +03:00
|
|
|
this.window.focus()
|
|
|
|
}
|
|
|
|
|
2020-12-24 16:03:14 +03:00
|
|
|
send (event: string, ...args: any[]): void {
|
2018-10-26 17:17:20 +03:00
|
|
|
if (!this.window) {
|
|
|
|
return
|
|
|
|
}
|
2018-08-31 16:41:28 +03:00
|
|
|
this.window.webContents.send(event, ...args)
|
2020-04-19 12:47:31 +03:00
|
|
|
if (event === 'host:config-change') {
|
|
|
|
this.configStore = args[0]
|
|
|
|
}
|
2018-08-31 16:41:28 +03:00
|
|
|
}
|
|
|
|
|
2020-03-01 19:07:11 +03:00
|
|
|
isDestroyed (): boolean {
|
2020-02-05 15:16:31 +03:00
|
|
|
return !this.window || this.window.isDestroyed()
|
2019-07-17 06:36:24 +03:00
|
|
|
}
|
|
|
|
|
2020-04-19 12:47:31 +03:00
|
|
|
isFocused (): boolean {
|
|
|
|
return this.window.isFocused()
|
|
|
|
}
|
|
|
|
|
2021-01-24 21:27:36 +03:00
|
|
|
isVisible (): boolean {
|
|
|
|
return this.window.isVisible()
|
|
|
|
}
|
|
|
|
|
2020-04-20 12:25:20 +03:00
|
|
|
hide (): void {
|
2020-04-19 12:47:31 +03:00
|
|
|
if (process.platform === 'darwin') {
|
|
|
|
// Lose focus
|
|
|
|
Menu.sendActionToFirstResponder('hide:')
|
|
|
|
}
|
|
|
|
this.window.blur()
|
|
|
|
if (process.platform !== 'darwin') {
|
|
|
|
this.window.hide()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-20 12:25:20 +03:00
|
|
|
present (): void {
|
2020-04-19 12:47:31 +03:00
|
|
|
if (!this.window.isVisible()) {
|
|
|
|
// unfocused, invisible
|
|
|
|
this.window.show()
|
|
|
|
this.window.focus()
|
|
|
|
} else {
|
|
|
|
if (!this.configStore.appearance?.dock || this.configStore.appearance?.dock === 'off') {
|
|
|
|
// not docked, visible
|
|
|
|
setTimeout(() => {
|
|
|
|
this.window.show()
|
|
|
|
this.window.focus()
|
|
|
|
})
|
|
|
|
} else {
|
2020-04-20 20:19:41 +03:00
|
|
|
if (this.configStore.appearance?.dockAlwaysOnTop) {
|
2020-04-20 19:38:02 +03:00
|
|
|
// docked, visible, on top
|
|
|
|
this.window.hide()
|
|
|
|
} else {
|
|
|
|
// docked, visible, not on top
|
|
|
|
this.window.focus()
|
|
|
|
}
|
2020-04-19 12:47:31 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-24 21:06:41 +03:00
|
|
|
passCliArguments (argv: string[], cwd: string, secondInstance: boolean): void {
|
|
|
|
this.send('cli', parseArgs(argv, cwd), cwd, secondInstance)
|
2020-05-02 18:23:35 +03:00
|
|
|
}
|
|
|
|
|
2018-08-31 16:41:28 +03:00
|
|
|
private setupWindowManagement () {
|
|
|
|
this.window.on('show', () => {
|
|
|
|
this.visible.next(true)
|
2019-11-26 17:51:31 +03:00
|
|
|
this.send('host:window-shown')
|
2018-08-31 16:41:28 +03:00
|
|
|
})
|
|
|
|
|
|
|
|
this.window.on('hide', () => {
|
|
|
|
this.visible.next(false)
|
|
|
|
})
|
|
|
|
|
2020-12-24 16:03:14 +03:00
|
|
|
const moveSubscription = new Observable<void>(observer => {
|
2018-12-29 15:27:45 +03:00
|
|
|
this.window.on('move', () => observer.next())
|
|
|
|
}).pipe(debounceTime(250)).subscribe(() => {
|
2019-11-26 17:51:31 +03:00
|
|
|
this.send('host:window-moved')
|
2018-12-29 15:27:45 +03:00
|
|
|
})
|
|
|
|
|
|
|
|
this.window.on('closed', () => {
|
|
|
|
moveSubscription.unsubscribe()
|
|
|
|
})
|
|
|
|
|
2019-11-26 17:51:31 +03:00
|
|
|
this.window.on('enter-full-screen', () => this.send('host:window-enter-full-screen'))
|
|
|
|
this.window.on('leave-full-screen', () => this.send('host:window-leave-full-screen'))
|
2018-08-31 16:41:28 +03:00
|
|
|
|
2018-11-22 19:51:12 +03:00
|
|
|
this.window.on('close', event => {
|
|
|
|
if (!this.closing) {
|
|
|
|
event.preventDefault()
|
2019-11-26 17:51:31 +03:00
|
|
|
this.send('host:window-close-request')
|
2018-11-22 19:51:12 +03:00
|
|
|
return
|
|
|
|
}
|
2018-09-13 02:25:08 +03:00
|
|
|
this.windowConfig.set('windowBoundaries', this.windowBounds)
|
|
|
|
this.windowConfig.set('maximized', this.window.isMaximized())
|
2018-08-31 16:41:28 +03:00
|
|
|
})
|
|
|
|
|
|
|
|
this.window.on('closed', () => {
|
|
|
|
this.destroy()
|
|
|
|
})
|
|
|
|
|
2018-09-13 02:25:08 +03:00
|
|
|
this.window.on('resize', () => {
|
2018-09-20 12:46:24 +03:00
|
|
|
if (!this.window.isMaximized()) {
|
2018-09-13 02:25:08 +03:00
|
|
|
this.windowBounds = this.window.getBounds()
|
2018-09-20 12:46:24 +03:00
|
|
|
}
|
2018-09-13 02:25:08 +03:00
|
|
|
})
|
|
|
|
|
|
|
|
this.window.on('move', () => {
|
2018-09-20 12:46:24 +03:00
|
|
|
if (!this.window.isMaximized()) {
|
2018-09-13 02:25:08 +03:00
|
|
|
this.windowBounds = this.window.getBounds()
|
2018-09-20 12:46:24 +03:00
|
|
|
}
|
2018-09-13 02:25:08 +03:00
|
|
|
})
|
|
|
|
|
2020-01-01 01:20:07 +03:00
|
|
|
this.window.on('focus', () => {
|
|
|
|
this.send('host:window-focused')
|
|
|
|
})
|
|
|
|
|
2021-05-16 19:59:25 +03:00
|
|
|
ipcMain.on('ready', event => {
|
|
|
|
if (!this.window || event.sender !== this.window.webContents) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
this.window.webContents.send('start', {
|
|
|
|
config: this.configStore,
|
2021-05-16 20:40:54 +03:00
|
|
|
executable: app.getPath('exe'),
|
2021-05-24 18:48:12 +03:00
|
|
|
windowID: this.window.id,
|
|
|
|
isFirstWindow: this.window.id === 1,
|
2021-05-16 19:59:25 +03:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2018-10-26 17:17:20 +03:00
|
|
|
ipcMain.on('window-focus', event => {
|
2019-02-10 00:38:45 +03:00
|
|
|
if (!this.window || event.sender !== this.window.webContents) {
|
2018-10-26 17:17:20 +03:00
|
|
|
return
|
|
|
|
}
|
2018-08-31 16:41:28 +03:00
|
|
|
this.window.focus()
|
|
|
|
})
|
|
|
|
|
2018-10-26 17:17:20 +03:00
|
|
|
ipcMain.on('window-maximize', event => {
|
2019-02-10 00:38:45 +03:00
|
|
|
if (!this.window || event.sender !== this.window.webContents) {
|
2018-10-26 17:17:20 +03:00
|
|
|
return
|
|
|
|
}
|
2018-08-31 16:41:28 +03:00
|
|
|
this.window.maximize()
|
|
|
|
})
|
|
|
|
|
2018-10-26 17:17:20 +03:00
|
|
|
ipcMain.on('window-unmaximize', event => {
|
2019-02-10 00:38:45 +03:00
|
|
|
if (!this.window || event.sender !== this.window.webContents) {
|
2018-10-26 17:17:20 +03:00
|
|
|
return
|
|
|
|
}
|
2018-08-31 16:41:28 +03:00
|
|
|
this.window.unmaximize()
|
|
|
|
})
|
|
|
|
|
2018-10-26 17:17:20 +03:00
|
|
|
ipcMain.on('window-toggle-maximize', event => {
|
2019-02-10 00:38:45 +03:00
|
|
|
if (!this.window || event.sender !== this.window.webContents) {
|
2018-10-26 17:17:20 +03:00
|
|
|
return
|
|
|
|
}
|
2018-08-31 16:41:28 +03:00
|
|
|
if (this.window.isMaximized()) {
|
|
|
|
this.window.unmaximize()
|
|
|
|
} else {
|
|
|
|
this.window.maximize()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2018-10-26 17:17:20 +03:00
|
|
|
ipcMain.on('window-minimize', event => {
|
2019-02-10 00:38:45 +03:00
|
|
|
if (!this.window || event.sender !== this.window.webContents) {
|
2018-10-26 17:17:20 +03:00
|
|
|
return
|
|
|
|
}
|
2018-08-31 16:41:28 +03:00
|
|
|
this.window.minimize()
|
|
|
|
})
|
|
|
|
|
2018-10-26 17:17:20 +03:00
|
|
|
ipcMain.on('window-set-bounds', (event, bounds) => {
|
2019-02-10 00:38:45 +03:00
|
|
|
if (!this.window || event.sender !== this.window.webContents) {
|
2018-10-26 17:17:20 +03:00
|
|
|
return
|
|
|
|
}
|
2018-08-31 16:41:28 +03:00
|
|
|
this.window.setBounds(bounds)
|
|
|
|
})
|
|
|
|
|
2018-10-26 17:17:20 +03:00
|
|
|
ipcMain.on('window-set-always-on-top', (event, flag) => {
|
2019-02-10 00:38:45 +03:00
|
|
|
if (!this.window || event.sender !== this.window.webContents) {
|
2018-10-26 17:17:20 +03:00
|
|
|
return
|
|
|
|
}
|
2018-08-31 16:41:28 +03:00
|
|
|
this.window.setAlwaysOnTop(flag)
|
|
|
|
})
|
|
|
|
|
2018-10-26 17:17:20 +03:00
|
|
|
ipcMain.on('window-set-vibrancy', (event, enabled, type) => {
|
2019-02-10 00:38:45 +03:00
|
|
|
if (!this.window || event.sender !== this.window.webContents) {
|
2018-10-26 17:17:20 +03:00
|
|
|
return
|
|
|
|
}
|
2018-10-13 14:30:12 +03:00
|
|
|
this.setVibrancy(enabled, type)
|
2018-08-31 16:41:28 +03:00
|
|
|
})
|
2018-09-20 12:42:51 +03:00
|
|
|
|
2018-10-26 17:17:20 +03:00
|
|
|
ipcMain.on('window-set-title', (event, title) => {
|
2019-02-10 00:38:45 +03:00
|
|
|
if (!this.window || event.sender !== this.window.webContents) {
|
2018-10-26 17:17:20 +03:00
|
|
|
return
|
|
|
|
}
|
2018-09-20 12:42:51 +03:00
|
|
|
this.window.setTitle(title)
|
|
|
|
})
|
2018-10-13 14:35:16 +03:00
|
|
|
|
2018-10-31 19:37:34 +03:00
|
|
|
ipcMain.on('window-bring-to-front', event => {
|
2019-02-10 00:38:45 +03:00
|
|
|
if (!this.window || event.sender !== this.window.webContents) {
|
2018-10-31 19:37:34 +03:00
|
|
|
return
|
|
|
|
}
|
|
|
|
if (this.window.isMinimized()) {
|
|
|
|
this.window.restore()
|
|
|
|
}
|
|
|
|
this.window.show()
|
|
|
|
this.window.moveTop()
|
|
|
|
})
|
|
|
|
|
2018-12-29 14:41:32 +03:00
|
|
|
ipcMain.on('window-close', event => {
|
2019-02-10 00:38:45 +03:00
|
|
|
if (!this.window || event.sender !== this.window.webContents) {
|
2018-12-29 14:41:32 +03:00
|
|
|
return
|
|
|
|
}
|
2018-11-22 19:51:12 +03:00
|
|
|
this.closing = true
|
|
|
|
this.window.close()
|
|
|
|
})
|
|
|
|
|
2018-10-13 14:35:16 +03:00
|
|
|
this.window.webContents.on('new-window', event => event.preventDefault())
|
2020-02-05 16:02:58 +03:00
|
|
|
|
|
|
|
ipcMain.on('window-set-disable-vibrancy-while-dragging', (_event, value) => {
|
|
|
|
this.disableVibrancyWhileDragging = value
|
|
|
|
})
|
|
|
|
|
2020-12-27 15:03:38 +03:00
|
|
|
let moveEndedTimeout: number|null = null
|
|
|
|
const onBoundsChange = () => {
|
2020-02-05 16:02:58 +03:00
|
|
|
if (!this.lastVibrancy?.enabled || !this.disableVibrancyWhileDragging) {
|
|
|
|
return
|
|
|
|
}
|
2020-12-27 15:03:38 +03:00
|
|
|
this.setVibrancy(false, undefined, false)
|
|
|
|
if (moveEndedTimeout) {
|
|
|
|
clearTimeout(moveEndedTimeout)
|
2020-02-05 16:02:58 +03:00
|
|
|
}
|
2020-12-27 15:03:38 +03:00
|
|
|
moveEndedTimeout = setTimeout(() => {
|
|
|
|
this.setVibrancy(this.lastVibrancy.enabled, this.lastVibrancy.type)
|
|
|
|
}, 50)
|
|
|
|
}
|
|
|
|
this.window.on('move', onBoundsChange)
|
|
|
|
this.window.on('resize', onBoundsChange)
|
2018-08-31 16:41:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
private destroy () {
|
|
|
|
this.window = null
|
2020-04-19 12:47:31 +03:00
|
|
|
this.closed.next()
|
2018-08-31 16:41:28 +03:00
|
|
|
this.visible.complete()
|
2020-04-19 12:47:31 +03:00
|
|
|
this.closed.complete()
|
2018-08-31 16:41:28 +03:00
|
|
|
}
|
|
|
|
}
|