Add bd-windowHasFrame and bd-windowIsTransparent classes
This commit is contained in:
parent
3747417865
commit
26bce739d7
|
@ -25,13 +25,19 @@ export default class {
|
|||
});
|
||||
if (hideButtonSetting.value) document.body.classList.add('bd-hideButton');
|
||||
|
||||
const currentWindow = remote.getCurrentWindow();
|
||||
const windowOptions = currentWindow.__bd_options;
|
||||
|
||||
if (!windowOptions.hasOwnProperty('frame') || windowOptions.frame) document.body.classList.add('bd-windowHasFrame');
|
||||
if (windowOptions.transparent) document.body.classList.add('bd-windowIsTransparent');
|
||||
|
||||
this.pathCache = {
|
||||
isDm: null,
|
||||
server: DiscordApi.currentGuild,
|
||||
channel: DiscordApi.currentChannel
|
||||
};
|
||||
|
||||
remote.getCurrentWindow().webContents.on('did-navigate-in-page', (e, url, isMainFrame) => {
|
||||
currentWindow.webContents.on('did-navigate-in-page', (e, url, isMainFrame) => {
|
||||
const { currentGuild, currentChannel } = DiscordApi;
|
||||
|
||||
if (!this.pathCache.server)
|
||||
|
|
|
@ -59,8 +59,7 @@
|
|||
filePath() {
|
||||
try {
|
||||
return Globals.require.resolve(path.join(Globals.getPath('data'), 'window'));
|
||||
}
|
||||
catch (err) {
|
||||
} catch (err) {
|
||||
FileUtils.writeJsonToFile(this.defaultFilePath, {});
|
||||
return this.defaultFilePath;
|
||||
}
|
||||
|
@ -79,11 +78,13 @@
|
|||
|
||||
if (event.category.id === 'default' && event.setting.id === 'transparent') {
|
||||
newPreferences.transparent = event.value;
|
||||
if (event.value) delete newPreferences.backgroundColor;
|
||||
if (event.value) newPreferences.backgroundColor = null;
|
||||
else if (newPreferences.backgroundColor === null) delete newPreferences.backgroundColor;
|
||||
}
|
||||
|
||||
if (event.category.id === 'default' && event.setting.id === 'background-colour') {
|
||||
newPreferences.backgroundColor = event.value;
|
||||
if (event.value) newPreferences.transparent = false;
|
||||
}
|
||||
|
||||
if (event.category.id === 'default' && event.setting.id === 'frame') {
|
||||
|
|
|
@ -132,16 +132,21 @@ export class Utils {
|
|||
* @param {Function} exclude A function to filter objects that shouldn't be cloned
|
||||
* @return {Any} The cloned value
|
||||
*/
|
||||
static deepclone(value, exclude) {
|
||||
static deepclone(value, exclude, cloned) {
|
||||
if (exclude && exclude(value)) return value;
|
||||
|
||||
if (typeof value === 'object') {
|
||||
if (value instanceof Array) return value.map(i => this.deepclone(i, exclude));
|
||||
if (!cloned) cloned = new WeakMap();
|
||||
|
||||
if (typeof value === 'object' && value !== null) {
|
||||
if (value instanceof Array) return value.map(i => this.deepclone(i, exclude, cloned));
|
||||
|
||||
if (cloned.has(value)) return cloned.get(value);
|
||||
|
||||
const clone = Object.assign({}, value);
|
||||
cloned.set(value, clone);
|
||||
|
||||
for (const key in clone) {
|
||||
clone[key] = this.deepclone(clone[key], exclude);
|
||||
clone[key] = this.deepclone(clone[key], exclude, cloned);
|
||||
}
|
||||
|
||||
return clone;
|
||||
|
@ -159,6 +164,8 @@ export class Utils {
|
|||
if (exclude && exclude(object)) return;
|
||||
|
||||
if (typeof object === 'object' && object !== null) {
|
||||
if (Object.isFrozen(object)) return object;
|
||||
|
||||
const properties = Object.getOwnPropertyNames(object);
|
||||
|
||||
for (const property of properties) {
|
||||
|
|
|
@ -74,7 +74,7 @@ class PatchedBrowserWindow extends BrowserWindow {
|
|||
|
||||
super(options);
|
||||
|
||||
this.__bd_preload = [];
|
||||
Object.defineProperty(this, '__bd_preload', {value: []});
|
||||
|
||||
if (originalOptions.webPreferences && originalOptions.webPreferences.preload) {
|
||||
this.__bd_preload.push(originalOptions.webPreferences.preload);
|
||||
|
@ -82,6 +82,11 @@ class PatchedBrowserWindow extends BrowserWindow {
|
|||
if (userOptions.webPreferences && userOptions.webPreferences.preload) {
|
||||
this.__bd_preload.push(path.resolve(_dataPath, userOptions.webPreferences.preload));
|
||||
}
|
||||
|
||||
Object.defineProperty(this, '__bd_options', {value: options});
|
||||
Object.freeze(options);
|
||||
Object.freeze(options.webPreferences);
|
||||
Object.freeze(this.__bd_preload);
|
||||
}
|
||||
|
||||
static get userWindowPreferences() {
|
||||
|
|
Loading…
Reference in New Issue