diff --git a/app/lib/window.ts b/app/lib/window.ts index c0a3f1c6..1b180b53 100644 --- a/app/lib/window.ts +++ b/app/lib/window.ts @@ -3,12 +3,21 @@ import { BrowserWindow, app, ipcMain, Rectangle } from 'electron' import ElectronConfig = require('electron-config') import * as yaml from 'js-yaml' import * as fs from 'fs' +import * as os from 'os' import * as path from 'path' let electronVibrancy: any -if (process.platform !== 'linux') { +let SetWindowCompositionAttribute: any +let AccentState: any +let DwmEnableBlurBehindWindow: any +if (process.platform === 'darwin') { electronVibrancy = require('electron-vibrancy') } +if (process.platform === 'win32') { + SetWindowCompositionAttribute = require('windows-swca').SetWindowCompositionAttribute + AccentState = require('windows-swca').AccentState + DwmEnableBlurBehindWindow = require('windows-blurbehind').DwmEnableBlurBehindWindow +} export class Window { ready: Promise @@ -42,6 +51,7 @@ export class Window { webPreferences: { webSecurity: false }, frame: false, show: false, + backgroundColor: '#00000000' } Object.assign(options, this.windowBounds) @@ -53,10 +63,6 @@ export class Window { } } - if (process.platform === 'win32' && (configData.appearance || {}).vibrancy) { - options.transparent = true - } - if (process.platform === 'linux') { options.backgroundColor = '#131d27' } @@ -95,11 +101,29 @@ export class Window { } setVibrancy (enabled: boolean) { - if (enabled && !this.vibrancyViewID) { - this.vibrancyViewID = electronVibrancy.SetVibrancy(this.window, 0) - } else if (!enabled && this.vibrancyViewID) { - electronVibrancy.RemoveView(this.window, this.vibrancyViewID) - this.vibrancyViewID = null + if (process.platform === 'win32') { + if (parseFloat(os.release()) >= 10) { + let attribValue = AccentState.ACCENT_DISABLED + let color = 0x00000000 + if (enabled) { + if (parseInt(os.release().split('.')[2]) >= 17063) { + attribValue = AccentState.ACCENT_ENABLE_FLUENT + color = 0x01000000 // using a small alpha because acrylic bugs out at full transparency. + } else { + attribValue = AccentState.ACCENT_ENABLE_BLURBEHIND + } + } + SetWindowCompositionAttribute(this.window, attribValue, color) + } else { + DwmEnableBlurBehindWindow(this.window, enabled) + } + } else if (process.platform === 'darwin') { + if (enabled && !this.vibrancyViewID) { + this.vibrancyViewID = electronVibrancy.SetVibrancy(this.window, 0) + } else if (!enabled && this.vibrancyViewID) { + electronVibrancy.RemoveView(this.window, this.vibrancyViewID) + this.vibrancyViewID = null + } } } diff --git a/app/package.json b/app/package.json index e3573fe1..4518530e 100644 --- a/app/package.json +++ b/app/package.json @@ -31,6 +31,8 @@ "ngx-toastr": "^8.7.3", "path": "0.12.7", "rxjs": "^6.1.0", + "windows-blurbehind": "^1.0.0", + "windows-swca": "^1.1.1", "yargs": "^12.0.1", "zone.js": "~0.8.26" }, diff --git a/app/webpack.main.config.js b/app/webpack.main.config.js index d392cd97..353906c0 100644 --- a/app/webpack.main.config.js +++ b/app/webpack.main.config.js @@ -41,6 +41,8 @@ module.exports = { mz: 'commonjs mz', path: 'commonjs path', yargs: 'commonjs yargs', + 'windows-swca': 'commonjs windows-swca', + 'windows-blurbehind': 'commonjs windows-blurbehind', }, plugins: [ new webpack.optimize.ModuleConcatenationPlugin(), diff --git a/app/yarn.lock b/app/yarn.lock index f6d952b1..03f49342 100644 --- a/app/yarn.lock +++ b/app/yarn.lock @@ -532,6 +532,14 @@ which@^1.2.9: dependencies: isexe "^2.0.0" +windows-blurbehind@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/windows-blurbehind/-/windows-blurbehind-1.0.0.tgz#050efb988704c44335bdc3efefd757f6e463b8ac" + +windows-swca@^1.1.1: + version "1.1.1" + resolved "https://registry.yarnpkg.com/windows-swca/-/windows-swca-1.1.1.tgz#0b3530278c67d408baac71c3a6aeb16d55318bf8" + wrap-ansi@^2.0.0: version "2.1.0" resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-2.1.0.tgz#d8fc3d284dd05794fe84973caecdd1cf824fdd85"