This repository has been archived by the owner on Sep 24, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 13
/
darwin.js
98 lines (81 loc) · 2.94 KB
/
darwin.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/*
Copyright 2020 AryToNeX
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
"use strict";
const Platform = require("./_platform.js");
module.exports = class Darwin extends Platform {
static init(win, _options){
this._wrapVibrancy(win, _options.vibrancy || null);
}
static setBlur(win, bool){
return win.setBlur(bool);
}
static getBlur(win){
return win.getBlur();
}
/**
* Note for everyone, not just developers and contributors
* the win.vibrancy variable should always return a string.
* It can return null but only initially, when the vibrancy is not set.
* It MUST NOT return null afterwards, even if win.setBlur(false) has been called.
* win.vibrancy defines the vibrancy effect to be used when blurring.
*/
static _wrapVibrancy(win, vibrancyInitialValue = "fullscreen-ui"){
// Wrap the original setVibrancy
const originalFunction = win.setVibrancy.bind(win);
// Set an array of two values
// [
// Vibrancy value to be reported,
// Current applied value (can be null in case of blur = false)
// ]
let _vibrancy = [vibrancyInitialValue, vibrancyInitialValue];
// Here we define the actual win.vibrancy variable
Object.defineProperty(win, "vibrancy", {
get: () => _vibrancy[0],
set: async (_newVibrancy) => {
// Yeet any undefined value
if(typeof _newVibrancy === "undefined")
return;
// Handle Electron handling "" vibrancy as null (disables stuff)
if(_newVibrancy === "")
_newVibrancy = null;
// If the new vibrancy is null, set the internal vibrancy to null
// and call the original function to reflect the change, then return.
if(_newVibrancy === null){
originalFunction(null);
_vibrancy[1] = null;
return;
}
// Set the new vibrancy to the nominal one
_vibrancy[0] = _newVibrancy;
// Update the actual vibrancy if it's not null
if(_vibrancy[1] !== null){
_vibrancy[1] = _vibrancy[0];
originalFunction(_vibrancy[1]);
}
}
});
// Bind the new wrapped setVibrancy function and apply it
win.setVibrancy = vibrancy => { win.vibrancy = vibrancy; };
// Now we need an exposed method to get the correct blur status
Object.defineProperty(win, "getBlur", {
get: () => _vibrancy[1] === null
});
// And a correct method to set the blur status
Object.defineProperty(win, "setBlur", {
get: () => (bool) => {
_vibrancy[1] = bool ? _vibrancy[0] : null;
originalFunction(_vibrancy[1]);
}
});
}
};