Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Eugeny committed Aug 3, 2024
1 parent 9b86ec0 commit 7e3fe7e
Show file tree
Hide file tree
Showing 10 changed files with 25 additions and 121 deletions.
73 changes: 16 additions & 57 deletions app/lib/window.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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`)
Expand All @@ -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 }
Expand Down Expand Up @@ -66,6 +56,7 @@ export class Window {
},
maximizable: true,
frame: false,
transparent: true,
show: false,
backgroundColor: '#00000000',
acceptFirstMouse: true,
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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)
}
}
Expand Down Expand Up @@ -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) => {
Expand Down Expand Up @@ -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 })
})
Expand Down
1 change: 0 additions & 1 deletion app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 0 additions & 1 deletion app/webpack.config.main.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
20 changes: 0 additions & 20 deletions app/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -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"
Expand Down
2 changes: 0 additions & 2 deletions tabby-core/src/configDefaults.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,5 @@ providerBlacklist: []
profileBlacklist: []
hacks:
disableGPU: false
disableVibrancyWhileDragging: false
enableFluentBackground: false
language: null
defaultQuickConnectProvider: "ssh"
1 change: 0 additions & 1 deletion tabby-core/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 3 additions & 5 deletions tabby-electron/src/index.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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 () {
Expand Down
6 changes: 1 addition & 5 deletions tabby-electron/src/services/hostApp.service.ts
Original file line number Diff line number Diff line change
@@ -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'


Expand Down Expand Up @@ -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 {
Expand Down
31 changes: 5 additions & 26 deletions tabby-settings/src/components/windowSettingsTab.component.pug
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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',
Expand All @@ -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
Expand Down Expand Up @@ -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()'
)
3 changes: 0 additions & 3 deletions tabby-settings/src/components/windowSettingsTab.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
HostAppService,
Platform,
isWindowsBuild,
WIN_BUILD_FLUENT_BG_SUPPORTED,
BaseComponent,
Screen,
PlatformService,
Expand All @@ -24,7 +23,6 @@ import {
export class WindowSettingsTabComponent extends BaseComponent {
screens: Screen[]
Platform = Platform
isFluentVibrancySupported = false
isWindowMaterialSupported = false

@HostBinding('class.content-box') true
Expand All @@ -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)
}

Expand Down

0 comments on commit 7e3fe7e

Please sign in to comment.