2020-06-03 16:41:23 +00:00
|
|
|
import * as glasstron from 'glasstron'
|
2020-06-05 08:08:20 +00:00
|
|
|
|
2021-07-06 07:40:54 +00:00
|
|
|
import { Subject, Observable, debounceTime } from 'rxjs'
|
2022-07-29 22:03:56 +00:00
|
|
|
import { BrowserWindow, app, ipcMain, Rectangle, Menu, screen, BrowserWindowConstructorOptions, TouchBar, nativeImage, WebContents } from 'electron'
|
2018-08-31 13:41:28 +00:00
|
|
|
import ElectronConfig = require('electron-config')
|
2021-12-22 21:23:02 +00:00
|
|
|
import { enable as enableRemote } from '@electron/remote/main'
|
2018-10-05 18:12:06 +00:00
|
|
|
import * as os from 'os'
|
2019-11-26 14:51:31 +00:00
|
|
|
import * as path from 'path'
|
2021-01-02 12:08:00 +00:00
|
|
|
import macOSRelease from 'macos-release'
|
2021-12-06 18:13:26 +00:00
|
|
|
import { compare as compareVersions } from 'compare-versions'
|
2018-10-06 18:50:06 +00:00
|
|
|
|
2021-06-18 23:36:25 +00:00
|
|
|
import type { Application } from './app'
|
2020-05-02 15:23:35 +00:00
|
|
|
import { parseArgs } from './cli'
|
2018-08-31 13:41:28 +00:00
|
|
|
|
2020-12-24 13:03:14 +00:00
|
|
|
let DwmEnableBlurBehindWindow: any = null
|
2018-10-05 18:12:06 +00:00
|
|
|
if (process.platform === 'win32') {
|
2021-12-12 12:14:24 +00:00
|
|
|
DwmEnableBlurBehindWindow = require('@tabby-gang/windows-blurbehind').DwmEnableBlurBehindWindow
|
2018-10-05 18:12:06 +00:00
|
|
|
}
|
2018-08-31 13:41:28 +00:00
|
|
|
|
2018-11-11 12:24:27 +00:00
|
|
|
export interface WindowOptions {
|
|
|
|
hidden?: boolean
|
|
|
|
}
|
|
|
|
|
2020-12-27 12:03:38 +00:00
|
|
|
abstract class GlasstronWindow extends BrowserWindow {
|
|
|
|
blurType: string
|
|
|
|
abstract setBlur (_: boolean)
|
|
|
|
}
|
|
|
|
|
2023-11-10 09:16:06 +00:00
|
|
|
const macOSVibrancyType: any = process.platform === 'darwin' ? compareVersions(macOSRelease().version || '0.0', '10.14', '>=') ? 'under-window' : 'dark' : null
|
2021-01-02 12:08:00 +00:00
|
|
|
|
2021-08-15 22:03:25 +00:00
|
|
|
const activityIcon = nativeImage.createFromPath(`${app.getAppPath()}/assets/activity.png`)
|
|
|
|
|
2018-08-31 13:41:28 +00:00
|
|
|
export class Window {
|
|
|
|
ready: Promise<void>
|
2021-12-15 22:21:56 +00:00
|
|
|
isMainWindow = false
|
2022-07-29 22:03:56 +00:00
|
|
|
webContents: WebContents
|
2018-08-31 13:41:28 +00:00
|
|
|
private visible = new Subject<boolean>()
|
2020-04-19 09:47:31 +00:00
|
|
|
private closed = new Subject<void>()
|
2021-01-02 19:10:00 +00:00
|
|
|
private window?: GlasstronWindow
|
2018-08-31 13:41:28 +00:00
|
|
|
private windowConfig: ElectronConfig
|
2021-01-02 19:10:00 +00:00
|
|
|
private windowBounds?: Rectangle
|
2018-11-22 16:51:12 +00:00
|
|
|
private closing = false
|
2021-01-28 20:46:31 +00:00
|
|
|
private lastVibrancy: { enabled: boolean, type?: string } | null = null
|
2020-02-05 13:02:58 +00:00
|
|
|
private disableVibrancyWhileDragging = false
|
2021-08-07 17:34:37 +00:00
|
|
|
private touchBarControl: any
|
2021-12-12 13:24:55 +00:00
|
|
|
private isFluentVibrancy = false
|
2021-12-21 23:04:01 +00:00
|
|
|
private dockHidden = false
|
2018-08-31 13:41:28 +00:00
|
|
|
|
|
|
|
get visible$ (): Observable<boolean> { return this.visible }
|
2020-04-19 09:47:31 +00:00
|
|
|
get closed$ (): Observable<void> { return this.closed }
|
2018-08-31 13:41:28 +00:00
|
|
|
|
2022-05-28 10:35:32 +00:00
|
|
|
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
|
|
|
constructor (private application: Application, private configStore: any, options?: WindowOptions) {
|
2021-01-02 18:09:34 +00:00
|
|
|
options = options ?? {}
|
2018-11-11 12:24:27 +00:00
|
|
|
|
2018-08-31 13:41:28 +00:00
|
|
|
this.windowConfig = new ElectronConfig({ name: 'window' })
|
2018-09-12 23:25:08 +00:00
|
|
|
this.windowBounds = this.windowConfig.get('windowBoundaries')
|
2018-08-31 13:41:28 +00:00
|
|
|
|
2020-12-24 13:03:14 +00:00
|
|
|
const maximized = this.windowConfig.get('maximized')
|
|
|
|
const bwOptions: BrowserWindowConstructorOptions = {
|
2018-08-31 13:41:28 +00:00
|
|
|
width: 800,
|
|
|
|
height: 600,
|
2021-06-29 21:57:04 +00:00
|
|
|
title: 'Tabby',
|
2018-08-31 13:41:28 +00:00
|
|
|
minWidth: 400,
|
2020-12-24 13:03:14 +00:00
|
|
|
minHeight: 300,
|
2019-02-20 00:57:38 +00:00
|
|
|
webPreferences: {
|
|
|
|
nodeIntegration: true,
|
2019-11-26 14:51:31 +00:00
|
|
|
preload: path.join(__dirname, 'sentry.js'),
|
2020-02-05 12:22:35 +00:00
|
|
|
backgroundThrottling: false,
|
2021-01-09 14:38:55 +00:00
|
|
|
contextIsolation: false,
|
2019-02-20 00:57:38 +00:00
|
|
|
},
|
2021-01-24 18:06:41 +00:00
|
|
|
maximizable: true,
|
2018-08-31 13:41:28 +00:00
|
|
|
frame: false,
|
|
|
|
show: false,
|
2019-10-26 19:11:27 +00:00
|
|
|
backgroundColor: '#00000000',
|
2022-05-22 02:51:11 +00:00
|
|
|
acceptFirstMouse: true,
|
2018-08-31 13:41:28 +00:00
|
|
|
}
|
|
|
|
|
2019-07-04 10:04:24 +00:00
|
|
|
if (this.windowBounds) {
|
|
|
|
Object.assign(bwOptions, this.windowBounds)
|
2020-02-05 12:16:31 +00:00
|
|
|
const closestDisplay = screen.getDisplayNearestPoint( { x: this.windowBounds.x, y: this.windowBounds.y } )
|
2019-06-28 02:46:47 +00:00
|
|
|
|
2020-02-05 12:16:31 +00: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 02:46:47 +00:00
|
|
|
|
2019-07-04 10:04:24 +00:00
|
|
|
if ((left2 > right1 || right2 < left1 || top2 > bottom1 || bottom2 < top1) && !maximized) {
|
2020-02-05 12:16:31 +00:00
|
|
|
bwOptions.x = closestDisplay.bounds.width / 2 - bwOptions.width / 2
|
|
|
|
bwOptions.y = closestDisplay.bounds.height / 2 - bwOptions.height / 2
|
2019-07-04 10:04:24 +00:00
|
|
|
}
|
2019-06-28 02:46:47 +00:00
|
|
|
}
|
|
|
|
|
2022-12-05 13:52:23 +00:00
|
|
|
if (this.configStore.appearance?.frame === 'native') {
|
2018-11-11 12:24:27 +00:00
|
|
|
bwOptions.frame = true
|
2018-08-31 13:41:28 +00:00
|
|
|
} else {
|
2023-07-16 18:57:19 +00:00
|
|
|
bwOptions.titleBarStyle = 'hidden'
|
|
|
|
if (process.platform === 'win32') {
|
2023-07-14 06:53:33 +00:00
|
|
|
bwOptions.titleBarOverlay = {
|
|
|
|
color: '#00000000',
|
|
|
|
}
|
2018-08-31 13:41:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-09 16:29:37 +00:00
|
|
|
if (process.platform === 'darwin') {
|
2021-01-09 16:02:01 +00:00
|
|
|
this.window = new BrowserWindow(bwOptions) as GlasstronWindow
|
2021-01-09 16:29:37 +00:00
|
|
|
} else {
|
|
|
|
this.window = new glasstron.BrowserWindow(bwOptions)
|
2021-01-02 12:08:00 +00:00
|
|
|
}
|
2020-06-03 16:41:23 +00:00
|
|
|
|
2022-07-29 22:03:56 +00:00
|
|
|
this.webContents = this.window.webContents
|
|
|
|
|
2018-08-31 13:41:28 +00:00
|
|
|
this.window.once('ready-to-show', () => {
|
|
|
|
if (process.platform === 'darwin') {
|
2021-01-02 12:08:00 +00:00
|
|
|
this.window.setVibrancy(macOSVibrancyType)
|
2022-12-05 13:52:23 +00:00
|
|
|
} else if (process.platform === 'win32' && this.configStore.appearance?.vibrancy) {
|
2018-08-31 13:41:28 +00:00
|
|
|
this.setVibrancy(true)
|
|
|
|
}
|
2018-11-11 12:24:27 +00:00
|
|
|
|
|
|
|
if (!options.hidden) {
|
|
|
|
if (maximized) {
|
|
|
|
this.window.maximize()
|
|
|
|
} else {
|
|
|
|
this.window.show()
|
|
|
|
}
|
|
|
|
this.window.focus()
|
2020-05-26 15:04:39 +00:00
|
|
|
this.window.moveTop()
|
2021-09-24 21:41:19 +00:00
|
|
|
application.focus()
|
2018-09-12 23:25:08 +00:00
|
|
|
}
|
2018-08-31 13:41:28 +00:00
|
|
|
})
|
2019-06-28 02:46:47 +00:00
|
|
|
|
2020-04-20 17:21:48 +00:00
|
|
|
this.window.on('blur', () => {
|
2023-04-16 12:08:27 +00:00
|
|
|
if (
|
|
|
|
(this.configStore.appearance?.dock ?? 'off') !== 'off' &&
|
|
|
|
this.configStore.appearance?.dockHideOnBlur &&
|
|
|
|
!BrowserWindow.getFocusedWindow()
|
|
|
|
) {
|
2020-04-20 17:01:10 +00:00
|
|
|
this.hide()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2021-12-22 21:23:02 +00:00
|
|
|
enableRemote(this.window.webContents)
|
|
|
|
|
2021-05-24 15:48:12 +00:00
|
|
|
this.window.loadURL(`file://${app.getAppPath()}/dist/index.html`, { extraHeaders: 'pragma: no-cache\n' })
|
2018-08-31 13:41:28 +00:00
|
|
|
|
2021-05-13 16:36:45 +00:00
|
|
|
this.window.webContents.setVisualZoomLevelLimits(1, 1)
|
|
|
|
this.window.webContents.setZoomFactor(1)
|
2022-02-11 10:02:29 +00:00
|
|
|
this.window.webContents.session.setPermissionCheckHandler(() => true)
|
|
|
|
this.window.webContents.session.setDevicePermissionHandler(() => true)
|
2021-05-13 16:36:45 +00:00
|
|
|
|
2021-08-07 17:34:37 +00:00
|
|
|
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 {
|
2018-08-31 13:41:28 +00:00
|
|
|
this.window.setMenu(null)
|
|
|
|
}
|
|
|
|
|
|
|
|
this.setupWindowManagement()
|
|
|
|
|
|
|
|
this.ready = new Promise(resolve => {
|
|
|
|
const listener = event => {
|
|
|
|
if (event.sender === this.window.webContents) {
|
2019-09-09 14:23:47 +00:00
|
|
|
ipcMain.removeListener('app:ready', listener as any)
|
2018-08-31 13:41:28 +00:00
|
|
|
resolve()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ipcMain.on('app:ready', listener)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-12-15 22:30:33 +00:00
|
|
|
makeMain (): void {
|
2021-12-15 22:21:56 +00:00
|
|
|
this.isMainWindow = true
|
|
|
|
this.window.webContents.send('host:became-main-window')
|
|
|
|
}
|
|
|
|
|
2020-12-27 12:03:38 +00:00
|
|
|
setVibrancy (enabled: boolean, type?: string, userRequested?: boolean): void {
|
|
|
|
if (userRequested ?? true) {
|
|
|
|
this.lastVibrancy = { enabled, type }
|
|
|
|
}
|
2018-10-05 18:12:06 +00:00
|
|
|
if (process.platform === 'win32') {
|
|
|
|
if (parseFloat(os.release()) >= 10) {
|
2020-12-27 12:03:38 +00:00
|
|
|
this.window.blurType = enabled ? type === 'fluent' ? 'acrylic' : 'blurbehind' : null
|
2021-01-09 14:38:55 +00:00
|
|
|
try {
|
|
|
|
this.window.setBlur(enabled)
|
2021-12-12 13:24:55 +00:00
|
|
|
this.isFluentVibrancy = enabled && type === 'fluent'
|
2021-01-09 14:38:55 +00:00
|
|
|
} catch (error) {
|
|
|
|
console.error('Failed to set window blur', error)
|
|
|
|
}
|
2018-10-05 18:12:06 +00:00
|
|
|
} else {
|
2022-03-26 20:19:22 +00:00
|
|
|
DwmEnableBlurBehindWindow(this.window.getNativeWindowHandle(), enabled)
|
2018-10-05 18:12:06 +00:00
|
|
|
}
|
2021-01-09 16:29:37 +00:00
|
|
|
} else if (process.platform === 'linux') {
|
|
|
|
this.window.setBackgroundColor(enabled ? '#00000000' : '#131d27')
|
|
|
|
this.window.setBlur(enabled)
|
2020-02-05 13:02:58 +00:00
|
|
|
} else {
|
2021-01-02 12:08:00 +00:00
|
|
|
this.window.setVibrancy(enabled ? macOSVibrancyType : null)
|
2018-08-31 13:41:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-01 15:10:45 +00:00
|
|
|
focus (): void {
|
2018-08-31 13:41:28 +00:00
|
|
|
this.window.focus()
|
|
|
|
}
|
|
|
|
|
2020-12-24 13:03:14 +00:00
|
|
|
send (event: string, ...args: any[]): void {
|
2018-10-26 14:17:20 +00:00
|
|
|
if (!this.window) {
|
|
|
|
return
|
|
|
|
}
|
2018-08-31 13:41:28 +00:00
|
|
|
this.window.webContents.send(event, ...args)
|
2020-04-19 09:47:31 +00:00
|
|
|
if (event === 'host:config-change') {
|
|
|
|
this.configStore = args[0]
|
2021-12-15 22:21:56 +00:00
|
|
|
this.enableDockedWindowStyles(this.isDockedOnTop())
|
2020-04-19 09:47:31 +00:00
|
|
|
}
|
2018-08-31 13:41:28 +00:00
|
|
|
}
|
|
|
|
|
2020-03-01 16:07:11 +00:00
|
|
|
isDestroyed (): boolean {
|
2020-02-05 12:16:31 +00:00
|
|
|
return !this.window || this.window.isDestroyed()
|
2019-07-17 03:36:24 +00:00
|
|
|
}
|
|
|
|
|
2020-04-19 09:47:31 +00:00
|
|
|
isFocused (): boolean {
|
|
|
|
return this.window.isFocused()
|
|
|
|
}
|
|
|
|
|
2021-01-24 18:27:36 +00:00
|
|
|
isVisible (): boolean {
|
|
|
|
return this.window.isVisible()
|
|
|
|
}
|
|
|
|
|
2021-12-15 22:21:56 +00:00
|
|
|
isDockedOnTop (): boolean {
|
|
|
|
return this.isMainWindow && this.configStore.appearance?.dock && this.configStore.appearance?.dock !== 'off' && (this.configStore.appearance?.dockAlwaysOnTop ?? true)
|
|
|
|
}
|
|
|
|
|
|
|
|
async hide (): Promise<void> {
|
2020-04-19 09:47:31 +00:00
|
|
|
if (process.platform === 'darwin') {
|
|
|
|
// Lose focus
|
|
|
|
Menu.sendActionToFirstResponder('hide:')
|
2021-12-15 22:21:56 +00:00
|
|
|
if (this.isDockedOnTop()) {
|
|
|
|
await this.enableDockedWindowStyles(false)
|
|
|
|
}
|
2020-04-19 09:47:31 +00:00
|
|
|
}
|
|
|
|
this.window.blur()
|
2021-12-15 22:21:56 +00:00
|
|
|
this.window.hide()
|
2020-04-19 09:47:31 +00:00
|
|
|
}
|
|
|
|
|
2021-12-15 22:21:56 +00:00
|
|
|
async show (): Promise<void> {
|
|
|
|
await this.enableDockedWindowStyles(this.isDockedOnTop())
|
|
|
|
this.window.show()
|
|
|
|
this.window.focus()
|
|
|
|
}
|
|
|
|
|
|
|
|
async present (): Promise<void> {
|
|
|
|
await this.show()
|
|
|
|
this.window.moveTop()
|
2020-04-19 09:47:31 +00:00
|
|
|
}
|
|
|
|
|
2021-01-24 18:06:41 +00:00
|
|
|
passCliArguments (argv: string[], cwd: string, secondInstance: boolean): void {
|
|
|
|
this.send('cli', parseArgs(argv, cwd), cwd, secondInstance)
|
2020-05-02 15:23:35 +00:00
|
|
|
}
|
|
|
|
|
2021-12-15 22:21:56 +00:00
|
|
|
private async enableDockedWindowStyles (enabled: boolean) {
|
|
|
|
if (process.platform === 'darwin') {
|
|
|
|
if (enabled) {
|
2021-12-21 23:04:01 +00:00
|
|
|
if (!this.dockHidden) {
|
|
|
|
app.dock.hide()
|
|
|
|
this.dockHidden = true
|
|
|
|
}
|
2021-12-15 22:21:56 +00:00
|
|
|
this.window.setAlwaysOnTop(true, 'screen-saver', 1)
|
2021-12-21 23:04:01 +00:00
|
|
|
if (!this.window.isVisibleOnAllWorkspaces()) {
|
|
|
|
this.window.setVisibleOnAllWorkspaces(true, { visibleOnFullScreen: true })
|
|
|
|
}
|
|
|
|
if (this.window.fullScreenable) {
|
|
|
|
this.window.setFullScreenable(false)
|
|
|
|
}
|
2021-12-15 22:21:56 +00:00
|
|
|
} else {
|
2021-12-21 23:04:01 +00:00
|
|
|
if (this.dockHidden) {
|
|
|
|
await app.dock.show()
|
|
|
|
this.dockHidden = false
|
|
|
|
}
|
|
|
|
if (this.window.isAlwaysOnTop()) {
|
|
|
|
this.window.setAlwaysOnTop(false)
|
|
|
|
}
|
|
|
|
if (this.window.isVisibleOnAllWorkspaces()) {
|
|
|
|
this.window.setVisibleOnAllWorkspaces(false)
|
|
|
|
}
|
|
|
|
if (!this.window.fullScreenable) {
|
|
|
|
this.window.setFullScreenable(true)
|
|
|
|
}
|
2021-12-15 22:21:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-31 13:41:28 +00:00
|
|
|
private setupWindowManagement () {
|
|
|
|
this.window.on('show', () => {
|
|
|
|
this.visible.next(true)
|
2019-11-26 14:51:31 +00:00
|
|
|
this.send('host:window-shown')
|
2018-08-31 13:41:28 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
this.window.on('hide', () => {
|
|
|
|
this.visible.next(false)
|
|
|
|
})
|
|
|
|
|
2020-12-24 13:03:14 +00:00
|
|
|
const moveSubscription = new Observable<void>(observer => {
|
2018-12-29 12:27:45 +00:00
|
|
|
this.window.on('move', () => observer.next())
|
|
|
|
}).pipe(debounceTime(250)).subscribe(() => {
|
2019-11-26 14:51:31 +00:00
|
|
|
this.send('host:window-moved')
|
2018-12-29 12:27:45 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
this.window.on('closed', () => {
|
|
|
|
moveSubscription.unsubscribe()
|
|
|
|
})
|
|
|
|
|
2019-11-26 14:51:31 +00: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 13:41:28 +00:00
|
|
|
|
2022-01-22 13:16:46 +00:00
|
|
|
this.window.on('maximize', () => this.send('host:window-maximized'))
|
|
|
|
this.window.on('unmaximize', () => this.send('host:window-unmaximized'))
|
|
|
|
|
2018-11-22 16:51:12 +00:00
|
|
|
this.window.on('close', event => {
|
|
|
|
if (!this.closing) {
|
|
|
|
event.preventDefault()
|
2019-11-26 14:51:31 +00:00
|
|
|
this.send('host:window-close-request')
|
2018-11-22 16:51:12 +00:00
|
|
|
return
|
|
|
|
}
|
2018-09-12 23:25:08 +00:00
|
|
|
this.windowConfig.set('windowBoundaries', this.windowBounds)
|
|
|
|
this.windowConfig.set('maximized', this.window.isMaximized())
|
2018-08-31 13:41:28 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
this.window.on('closed', () => {
|
|
|
|
this.destroy()
|
|
|
|
})
|
|
|
|
|
2018-09-12 23:25:08 +00:00
|
|
|
this.window.on('resize', () => {
|
2018-09-20 09:46:24 +00:00
|
|
|
if (!this.window.isMaximized()) {
|
2018-09-12 23:25:08 +00:00
|
|
|
this.windowBounds = this.window.getBounds()
|
2018-09-20 09:46:24 +00:00
|
|
|
}
|
2018-09-12 23:25:08 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
this.window.on('move', () => {
|
2018-09-20 09:46:24 +00:00
|
|
|
if (!this.window.isMaximized()) {
|
2018-09-12 23:25:08 +00:00
|
|
|
this.windowBounds = this.window.getBounds()
|
2018-09-20 09:46:24 +00:00
|
|
|
}
|
2018-09-12 23:25:08 +00:00
|
|
|
})
|
|
|
|
|
2019-12-31 22:20:07 +00:00
|
|
|
this.window.on('focus', () => {
|
|
|
|
this.send('host:window-focused')
|
|
|
|
})
|
|
|
|
|
2021-05-16 16:59:25 +00: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 17:40:54 +00:00
|
|
|
executable: app.getPath('exe'),
|
2021-05-24 15:48:12 +00:00
|
|
|
windowID: this.window.id,
|
2021-12-15 22:21:56 +00:00
|
|
|
isMainWindow: this.isMainWindow,
|
2021-06-18 23:36:25 +00:00
|
|
|
userPluginsPath: this.application.userPluginsPath,
|
2021-05-16 16:59:25 +00:00
|
|
|
})
|
|
|
|
})
|
2018-08-31 13:41:28 +00:00
|
|
|
|
2018-10-26 14:17:20 +00:00
|
|
|
ipcMain.on('window-minimize', event => {
|
2019-02-09 21:38:45 +00:00
|
|
|
if (!this.window || event.sender !== this.window.webContents) {
|
2018-10-26 14:17:20 +00:00
|
|
|
return
|
|
|
|
}
|
2018-08-31 13:41:28 +00:00
|
|
|
this.window.minimize()
|
|
|
|
})
|
|
|
|
|
2018-10-26 14:17:20 +00:00
|
|
|
ipcMain.on('window-set-bounds', (event, bounds) => {
|
2019-02-09 21:38:45 +00:00
|
|
|
if (!this.window || event.sender !== this.window.webContents) {
|
2018-10-26 14:17:20 +00:00
|
|
|
return
|
|
|
|
}
|
2018-08-31 13:41:28 +00:00
|
|
|
this.window.setBounds(bounds)
|
|
|
|
})
|
|
|
|
|
2018-10-26 14:17:20 +00:00
|
|
|
ipcMain.on('window-set-always-on-top', (event, flag) => {
|
2019-02-09 21:38:45 +00:00
|
|
|
if (!this.window || event.sender !== this.window.webContents) {
|
2018-10-26 14:17:20 +00:00
|
|
|
return
|
|
|
|
}
|
2018-08-31 13:41:28 +00:00
|
|
|
this.window.setAlwaysOnTop(flag)
|
|
|
|
})
|
|
|
|
|
2018-10-26 14:17:20 +00:00
|
|
|
ipcMain.on('window-set-vibrancy', (event, enabled, type) => {
|
2019-02-09 21:38:45 +00:00
|
|
|
if (!this.window || event.sender !== this.window.webContents) {
|
2018-10-26 14:17:20 +00:00
|
|
|
return
|
|
|
|
}
|
2018-10-13 11:30:12 +00:00
|
|
|
this.setVibrancy(enabled, type)
|
2018-08-31 13:41:28 +00:00
|
|
|
})
|
2018-09-20 09:42:51 +00:00
|
|
|
|
2023-07-14 18:57:27 +00:00
|
|
|
ipcMain.on('window-set-window-controls-color', (event, theme) => {
|
|
|
|
if (!this.window || event.sender !== this.window.webContents) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-08-09 16:15:46 +00:00
|
|
|
if (process.platform === 'win32') {
|
|
|
|
const symbolColor: string = theme.foreground
|
|
|
|
this.window.setTitleBarOverlay(
|
|
|
|
{
|
|
|
|
symbolColor: symbolColor,
|
|
|
|
height: 32,
|
|
|
|
},
|
|
|
|
)
|
|
|
|
}
|
2023-07-14 18:57:27 +00:00
|
|
|
})
|
|
|
|
|
2018-10-26 14:17:20 +00:00
|
|
|
ipcMain.on('window-set-title', (event, title) => {
|
2019-02-09 21:38:45 +00:00
|
|
|
if (!this.window || event.sender !== this.window.webContents) {
|
2018-10-26 14:17:20 +00:00
|
|
|
return
|
|
|
|
}
|
2018-09-20 09:42:51 +00:00
|
|
|
this.window.setTitle(title)
|
|
|
|
})
|
2018-10-13 11:35:16 +00:00
|
|
|
|
2018-10-31 16:37:34 +00:00
|
|
|
ipcMain.on('window-bring-to-front', event => {
|
2019-02-09 21:38:45 +00:00
|
|
|
if (!this.window || event.sender !== this.window.webContents) {
|
2018-10-31 16:37:34 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
if (this.window.isMinimized()) {
|
|
|
|
this.window.restore()
|
|
|
|
}
|
2021-12-15 22:21:56 +00:00
|
|
|
this.present()
|
2018-10-31 16:37:34 +00:00
|
|
|
})
|
|
|
|
|
2018-12-29 11:41:32 +00:00
|
|
|
ipcMain.on('window-close', event => {
|
2019-02-09 21:38:45 +00:00
|
|
|
if (!this.window || event.sender !== this.window.webContents) {
|
2018-12-29 11:41:32 +00:00
|
|
|
return
|
|
|
|
}
|
2018-11-22 16:51:12 +00:00
|
|
|
this.closing = true
|
|
|
|
this.window.close()
|
|
|
|
})
|
|
|
|
|
2021-08-07 17:34:37 +00:00
|
|
|
ipcMain.on('window-set-touch-bar', (_event, segments, selectedIndex) => {
|
2021-08-15 22:03:25 +00:00
|
|
|
this.touchBarControl.segments = segments.map(s => ({
|
|
|
|
label: s.label,
|
|
|
|
icon: s.hasActivity ? activityIcon : undefined,
|
2021-08-15 22:04:47 +00:00
|
|
|
}))
|
2021-08-07 17:34:37 +00:00
|
|
|
this.touchBarControl.selectedIndex = selectedIndex
|
|
|
|
})
|
|
|
|
|
2023-02-26 19:42:31 +00:00
|
|
|
this.window.webContents.setWindowOpenHandler(() => {
|
|
|
|
return { action: 'deny' }
|
|
|
|
})
|
2020-02-05 13:02:58 +00:00
|
|
|
|
|
|
|
ipcMain.on('window-set-disable-vibrancy-while-dragging', (_event, value) => {
|
2022-04-05 07:21:04 +00:00
|
|
|
this.disableVibrancyWhileDragging = value && this.configStore.hacks?.disableVibrancyWhileDragging
|
2020-02-05 13:02:58 +00:00
|
|
|
})
|
|
|
|
|
2021-07-06 08:44:30 +00:00
|
|
|
let moveEndedTimeout: any = null
|
2020-12-27 12:03:38 +00:00
|
|
|
const onBoundsChange = () => {
|
2022-03-08 19:05:58 +00:00
|
|
|
if (!this.lastVibrancy?.enabled || !this.disableVibrancyWhileDragging || !this.isFluentVibrancy) {
|
2020-02-05 13:02:58 +00:00
|
|
|
return
|
|
|
|
}
|
2020-12-27 12:03:38 +00:00
|
|
|
this.setVibrancy(false, undefined, false)
|
|
|
|
if (moveEndedTimeout) {
|
|
|
|
clearTimeout(moveEndedTimeout)
|
2020-02-05 13:02:58 +00:00
|
|
|
}
|
2020-12-27 12:03:38 +00:00
|
|
|
moveEndedTimeout = setTimeout(() => {
|
|
|
|
this.setVibrancy(this.lastVibrancy.enabled, this.lastVibrancy.type)
|
|
|
|
}, 50)
|
|
|
|
}
|
|
|
|
this.window.on('move', onBoundsChange)
|
|
|
|
this.window.on('resize', onBoundsChange)
|
2021-09-25 16:11:35 +00:00
|
|
|
|
|
|
|
ipcMain.on('window-set-traffic-light-position', (_event, x, y) => {
|
2023-07-18 21:17:07 +00:00
|
|
|
this.window.setWindowButtonPosition({ x, y })
|
2021-09-25 16:11:35 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
ipcMain.on('window-set-opacity', (_event, opacity) => {
|
|
|
|
this.window.setOpacity(opacity)
|
|
|
|
})
|
|
|
|
|
|
|
|
ipcMain.on('window-set-progress-bar', (_event, value) => {
|
|
|
|
this.window.setProgressBar(value, { mode: value < 0 ? 'none' : 'normal' })
|
|
|
|
})
|
2018-08-31 13:41:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private destroy () {
|
|
|
|
this.window = null
|
2020-04-19 09:47:31 +00:00
|
|
|
this.closed.next()
|
2018-08-31 13:41:28 +00:00
|
|
|
this.visible.complete()
|
2020-04-19 09:47:31 +00:00
|
|
|
this.closed.complete()
|
2018-08-31 13:41:28 +00:00
|
|
|
}
|
|
|
|
}
|