fix: stop relying on window.isElectron
This commit is contained in:
@@ -13,6 +13,7 @@ import {
|
||||
} from '@/services';
|
||||
import { AppState } from '@/ui_models/app_state';
|
||||
import { Bridge } from '@/services/bridge';
|
||||
import { isDesktopApplication } from '@/utils';
|
||||
|
||||
export class ApplicationGroup extends SNApplicationGroup {
|
||||
|
||||
@@ -42,8 +43,7 @@ export class ApplicationGroup extends SNApplicationGroup {
|
||||
applicationCreator: this.createApplication
|
||||
});
|
||||
|
||||
/** FIXME(baptiste): rely on a less fragile method to detect Electron */
|
||||
if ((window as any).isElectron) {
|
||||
if (isDesktopApplication()) {
|
||||
Object.defineProperty(window, 'desktopManager', {
|
||||
get: () => (this.primaryApplication as WebApplication).getDesktopService()
|
||||
});
|
||||
|
||||
@@ -74,10 +74,6 @@ export function debounce(this: any, func: any, wait: number, immediate = false)
|
||||
};
|
||||
};
|
||||
|
||||
export function isDesktopApplication() {
|
||||
return (window as any).isElectron;
|
||||
}
|
||||
|
||||
// https://tc39.github.io/ecma262/#sec-array.prototype.includes
|
||||
if (!Array.prototype.includes) {
|
||||
// eslint-disable-next-line no-extend-native
|
||||
@@ -148,3 +144,15 @@ export async function preventRefreshing(
|
||||
window.onbeforeunload = onBeforeUnload;
|
||||
}
|
||||
}
|
||||
|
||||
/** Platform-detection functions */
|
||||
declare const __WEB__: boolean;
|
||||
declare const __DESKTOP__: boolean;
|
||||
|
||||
if (!__WEB__ && !__DESKTOP__) {
|
||||
throw Error('Neither __WEB__ nor __DESKTOP__ is true. Check your configuration files.');
|
||||
}
|
||||
|
||||
export function isDesktopApplication() {
|
||||
return __DESKTOP__;
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ module.exports = (env = {
|
||||
new webpack.DefinePlugin({
|
||||
__VERSION__: JSON.stringify(require('./package.json').version),
|
||||
__WEB__: JSON.stringify(env.platform === 'web'),
|
||||
__DESKTOP__: JSON.stringify(env.platform === 'desktop'),
|
||||
}),
|
||||
new MiniCssExtractPlugin({
|
||||
// Options similar to the same options in webpackOptions.output
|
||||
|
||||
Reference in New Issue
Block a user