This commit is contained in:
Eugene Pankov 2024-08-03 21:22:40 +02:00
parent 9b86ec0a4c
commit 7e3fe7e938
10 changed files with 25 additions and 121 deletions

View File

@ -1,10 +1,8 @@
import * as glasstron from 'glasstron'
import { autoUpdater } from 'electron-updater'
import { Subject, Observable, debounceTime } from 'rxjs'
import { BrowserWindow, app, ipcMain, Rectangle, Menu, screen, BrowserWindowConstructorOptions, TouchBar, nativeImage, WebContents } from 'electron'
import ElectronConfig = require('electron-config')
import { enable as enableRemote } from '@electron/remote/main'
import * as os from 'os'
import * as path from 'path'
import macOSRelease from 'macos-release'
import { compare as compareVersions } from 'compare-versions'
@ -16,11 +14,6 @@ export interface WindowOptions {
hidden?: boolean
}
abstract class GlasstronWindow extends BrowserWindow {
blurType: string
abstract setBlur (_: boolean)
}
const macOSVibrancyType: any = process.platform === 'darwin' ? compareVersions(macOSRelease().version || '0.0', '10.14', '>=') ? 'under-window' : 'dark' : null
const activityIcon = nativeImage.createFromPath(`${app.getAppPath()}/assets/activity.png`)
@ -31,14 +24,11 @@ export class Window {
webContents: WebContents
private visible = new Subject<boolean>()
private closed = new Subject<void>()
private window?: GlasstronWindow
private window?: BrowserWindow
private windowConfig: ElectronConfig
private windowBounds?: Rectangle
private closing = false
private lastVibrancy: { enabled: boolean, type?: string } | null = null
private disableVibrancyWhileDragging = false
private touchBarControl: any
private isFluentVibrancy = false
private dockHidden = false
get visible$ (): Observable<boolean> { return this.visible }
@ -66,6 +56,7 @@ export class Window {
},
maximizable: true,
frame: false,
transparent: true,
show: false,
backgroundColor: '#00000000',
acceptFirstMouse: true,
@ -95,11 +86,15 @@ export class Window {
}
}
if (process.platform === 'darwin') {
this.window = new BrowserWindow(bwOptions) as GlasstronWindow
} else {
this.window = new glasstron.BrowserWindow(bwOptions)
}
this.window = new BrowserWindow(bwOptions)
// https://github.com/electron/electron/issues/39959#issuecomment-1758736966
this.window.on('blur', () => {
this.window.setBackgroundColor('#00000000')
})
this.window.on('focus', () => {
this.window.setBackgroundColor('#00000000')
})
this.webContents = this.window.webContents
@ -172,28 +167,12 @@ export class Window {
this.window.webContents.send('host:became-main-window')
}
setMaterial (material: string): void {
setMaterial (material: 'mica'|'acrylic'|'auto'): void {
this.window.setBackgroundMaterial(material)
}
setVibrancy (enabled: boolean, type?: string, userRequested?: boolean): void {
if (userRequested ?? true) {
this.lastVibrancy = { enabled, type }
}
if (process.platform === 'win32') {
if (parseFloat(os.release()) >= 10) {
this.window.blurType = enabled ? type === 'fluent' ? 'acrylic' : 'blurbehind' : null
try {
this.window.setBlur(enabled)
this.isFluentVibrancy = enabled && type === 'fluent'
} catch (error) {
console.error('Failed to set window blur', error)
}
}
} else if (process.platform === 'linux') {
this.window.setBackgroundColor(enabled ? '#00000000' : '#131d27')
this.window.setBlur(enabled)
} else {
setVibrancy (enabled: boolean): void {
if (process.platform === 'darwin') {
this.window.setVibrancy(enabled ? macOSVibrancyType : null)
}
}
@ -366,8 +345,8 @@ export class Window {
this.window?.setAlwaysOnTop(flag)
})
this.on('window-set-vibrancy', (_, enabled, type) => {
this.setVibrancy(enabled, type)
this.on('window-set-vibrancy', (_, enabled) => {
this.setVibrancy(enabled)
})
this.on('window-set-material', (_, material) => {
@ -414,26 +393,6 @@ export class Window {
return { action: 'deny' }
})
ipcMain.on('window-set-disable-vibrancy-while-dragging', (_event, value) => {
this.disableVibrancyWhileDragging = value && this.configStore.hacks?.disableVibrancyWhileDragging
})
let moveEndedTimeout: any = null
const onBoundsChange = () => {
if (!this.lastVibrancy?.enabled || !this.disableVibrancyWhileDragging || !this.isFluentVibrancy) {
return
}
this.setVibrancy(false, undefined, false)
if (moveEndedTimeout) {
clearTimeout(moveEndedTimeout)
}
moveEndedTimeout = setTimeout(() => {
this.setVibrancy(this.lastVibrancy.enabled, this.lastVibrancy.type)
}, 50)
}
this.window.on('move', onBoundsChange)
this.window.on('resize', onBoundsChange)
ipcMain.on('window-set-traffic-light-position', (_event, x, y) => {
this.window.setWindowButtonPosition({ x, y })
})

View File

@ -23,7 +23,6 @@
"electron-promise-ipc": "^2.2.4",
"electron-updater": "^5.2.1",
"fontmanager-redux": "1.1.0",
"glasstron": "0.1.1",
"js-yaml": "4.1.0",
"keytar": "^7.9.0",
"mz": "^2.7.0",

View File

@ -44,7 +44,6 @@ const config = {
'electron-promise-ipc': 'commonjs electron-promise-ipc',
'electron-updater': 'commonjs electron-updater',
fs: 'commonjs fs',
glasstron: 'commonjs glasstron',
mz: 'commonjs mz',
npm: 'commonjs npm',
'node:os': 'commonjs os',

View File

@ -173,13 +173,6 @@
dependencies:
debug "^4.3.2"
"@tabby-gang/windows-blurbehind@^3.0.0":
version "3.0.0"
resolved "https://registry.yarnpkg.com/@tabby-gang/windows-blurbehind/-/windows-blurbehind-3.0.0.tgz#48d409c2eb14a12c867b70de5ee4d6769ef45e8f"
integrity sha512-ah6eJcoQZWOZfu9sd2pWlOJmfl1v+2EZQMeIp7MWvg+/16WS16UFNdnOtlV6AUiABHfZo2QKfCNUEuorCM+Q2A==
dependencies:
"@types/node" "^10.12.18"
"@types/mz@2.7.4":
version "2.7.4"
resolved "https://registry.yarnpkg.com/@types/mz/-/mz-2.7.4.tgz#f9d1535cb5171199b28ae6abd6ec29e856551401"
@ -192,11 +185,6 @@
resolved "https://registry.yarnpkg.com/@types/node/-/node-20.3.1.tgz#e8a83f1aa8b649377bb1fb5d7bac5cb90e784dfe"
integrity sha512-EhcH/wvidPy1WeML3TtYFGR83UzjxeWRen9V402T8aUGYsCHOmfoisV3ZSg03gAFIbLq8TnWOJ0f4cALtnSEUg==
"@types/node@^10.12.18":
version "10.17.60"
resolved "https://registry.yarnpkg.com/@types/node/-/node-10.17.60.tgz#35f3d6213daed95da7f0f73e75bcc6980e90597b"
integrity sha512-F0KIgDJfy2nA3zMLmWGKxcH2ZVEtCZXHHdOQs2gSaQ27+lNeEfGxzkIw90aXswATX7AZ33tahPbzy6KAfUreVw==
"@types/semver@^7.3.6":
version "7.3.9"
resolved "https://registry.yarnpkg.com/@types/semver/-/semver-7.3.9.tgz#152c6c20a7688c30b967ec1841d31ace569863fc"
@ -1481,14 +1469,6 @@ github-from-package@0.0.0:
resolved "https://registry.npmjs.org/github-from-package/-/github-from-package-0.0.0.tgz"
integrity sha1-l/tdlr/eiXMxPyDoKI75oWf6ZM4=
glasstron@0.1.1:
version "0.1.1"
resolved "https://registry.yarnpkg.com/glasstron/-/glasstron-0.1.1.tgz#491a2e6f7e7b285c3776c5f7af7aaba2269833b2"
integrity sha512-oLEMQM5wwdAQ44NrXD3wjk+b3dsfQG1XtkLn5pCxQNa3ri1AtWvvzpnhFUd88ZTmguHvkY4c3JKzcPSYaJAKKA==
dependencies:
node-addon-api "^4.0.0"
x11 "^2.3.0"
glob@^10.2.2, glob@^10.3.10:
version "10.3.10"
resolved "https://registry.yarnpkg.com/glob/-/glob-10.3.10.tgz#0351ebb809fd187fe421ab96af83d3a70715df4b"

View File

@ -54,7 +54,5 @@ providerBlacklist: []
profileBlacklist: []
hacks:
disableGPU: false
disableVibrancyWhileDragging: false
enableFluentBackground: false
language: null
defaultQuickConnectProvider: "ssh"

View File

@ -5,7 +5,6 @@ import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker'
export const WIN_BUILD_CONPTY_SUPPORTED = 17692
export const WIN_BUILD_CONPTY_STABLE = 18309
export const WIN_BUILD_WSL_EXE_DISTRO_FLAG = 17763
export const WIN_BUILD_FLUENT_BG_SUPPORTED = 17063
export const WIN_BUILD_WINDOW_MATERIAL_SUPPORTED = 22621
export function getWindows10Build (): number|undefined {

View File

@ -1,5 +1,5 @@
import { NgModule } from '@angular/core'
import { PlatformService, LogService, UpdaterService, DockingService, HostAppService, ThemesService, Platform, AppService, ConfigService, WIN_BUILD_FLUENT_BG_SUPPORTED, isWindowsBuild, HostWindowService, HotkeyProvider, ConfigProvider, FileProvider, WIN_BUILD_WINDOW_MATERIAL_SUPPORTED } from 'tabby-core'
import { PlatformService, LogService, UpdaterService, DockingService, HostAppService, ThemesService, Platform, AppService, ConfigService, isWindowsBuild, HostWindowService, HotkeyProvider, ConfigProvider, FileProvider, WIN_BUILD_WINDOW_MATERIAL_SUPPORTED } from 'tabby-core'
import { TerminalColorSchemeProvider } from 'tabby-terminal'
import { SFTPContextMenuItemProvider, SSHProfileImporter, AutoPrivateKeyLocator } from 'tabby-ssh'
import { PTYInterface, ShellProvider, UACService } from 'tabby-local'
@ -178,11 +178,9 @@ export default class ElectronModule {
return
}
let vibrancyType = this.config.store.appearance.vibrancyType
if (this.hostApp.platform === Platform.Windows && !isWindowsBuild(WIN_BUILD_FLUENT_BG_SUPPORTED)) {
vibrancyType = null
if (this.hostApp.platform === Platform.macOS) {
this.electron.ipcRenderer.send('window-set-vibrancy', this.config.store.appearance.vibrancy)
}
this.electron.ipcRenderer.send('window-set-vibrancy', this.config.store.appearance.vibrancy, vibrancyType)
}
private updateWindowControlsColor () {

View File

@ -1,5 +1,5 @@
import { Injectable, NgZone, Injector } from '@angular/core'
import { isWindowsBuild, WIN_BUILD_FLUENT_BG_SUPPORTED, HostAppService, Platform, CLIHandler, WIN_BUILD_WINDOW_MATERIAL_SUPPORTED } from 'tabby-core'
import { HostAppService, Platform, CLIHandler } from 'tabby-core'
import { ElectronService } from '../services/electron.service'
@ -48,10 +48,6 @@ export class ElectronHostAppService extends HostAppService {
electron.ipcRenderer.on('host:config-change', () => this.zone.run(() => {
this.configChangeBroadcast.next()
}))
if (isWindowsBuild(WIN_BUILD_FLUENT_BG_SUPPORTED) && !isWindowsBuild(WIN_BUILD_WINDOW_MATERIAL_SUPPORTED)) {
electron.ipcRenderer.send('window-set-disable-vibrancy-while-dragging', true)
}
}
newWindow (): void {

View File

@ -32,19 +32,18 @@ h3.mb-3(translate) Window
)
.form-line(*ngIf='platform.supportsWindowControls')
.form-line(*ngIf='platform.supportsWindowControls && (hostApp.platform !== Platform.Windows || isWindowMaterialSupported)')
.header
.title(*ngIf='hostApp.platform !== Platform.macOS', translate) Blurred background
.title(*ngIf='hostApp.platform === Platform.macOS', translate) Vibrancy
.description(*ngIf='hostApp.platform !== Platform.Linux', translate) Gives the window a blurred transparent background
.description(*ngIf='hostApp.platform === Platform.Linux', translate) Enables transparent windows background under KWM
.description(*ngIf='hostApp.platform === Platform.Linux', translate) Gives the window a blurred transparent background
toggle(
[(ngModel)]='config.store.appearance.vibrancy',
(ngModelChange)='saveConfiguration()'
)
.form-line(*ngIf='config.store.appearance.vibrancy && (isWindowMaterialSupported || (isFluentVibrancySupported && config.store.hacks.enableFluentBackground))')
.form-line(*ngIf='config.store.appearance.vibrancy && isWindowMaterialSupported')
.header
.title(translate) Background type
.btn-group
@ -59,7 +58,7 @@ h3.mb-3(translate) Window
label.btn.btn-secondary(
for='vibrancyTypeBlur'
)
span(translate) Blur
span(translate) Acrylic
input.btn-check(
type='radio',
name='vibracy',
@ -71,7 +70,7 @@ h3.mb-3(translate) Window
label.btn.btn-secondary(
for='vibrancyTypeFluent'
)
span Fluent
span Mica
.form-line(*ngIf='platform.supportsWindowControls')
.header
@ -423,23 +422,3 @@ h3.mt-4(translate) Hacks
[(ngModel)]='config.store.hacks.disableGPU',
(ngModelChange)='config.save(); config.requestRestart()'
)
.form-line(*ngIf='hostApp.platform === Platform.Windows && isFluentVibrancySupported')
.header
.title(translate) Enable fluent background option
.description(translate) Experimental Windows 10 background style known to cause issues
toggle(
[(ngModel)]='config.store.hacks.enableFluentBackground',
(ngModelChange)='config.save()'
)
.form-line(*ngIf='hostApp.platform === Platform.Windows && isFluentVibrancySupported')
.header
.title(translate) Disable fluent background while dragging
.description(translate) Fluent background sometimes causes drag lag
toggle(
[(ngModel)]='config.store.hacks.disableVibrancyWhileDragging',
(ngModelChange)='config.save(); config.requestRestart()'
)

View File

@ -8,7 +8,6 @@ import {
HostAppService,
Platform,
isWindowsBuild,
WIN_BUILD_FLUENT_BG_SUPPORTED,
BaseComponent,
Screen,
PlatformService,
@ -24,7 +23,6 @@ import {
export class WindowSettingsTabComponent extends BaseComponent {
screens: Screen[]
Platform = Platform
isFluentVibrancySupported = false
isWindowMaterialSupported = false
@HostBinding('class.content-box') true
@ -49,7 +47,6 @@ export class WindowSettingsTabComponent extends BaseComponent {
this.screens = dockingService.getScreens()
}
this.isFluentVibrancySupported = isWindowsBuild(WIN_BUILD_FLUENT_BG_SUPPORTED)
this.isWindowMaterialSupported = isWindowsBuild(WIN_BUILD_WINDOW_MATERIAL_SUPPORTED)
}