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