mirror of
https://github.com/danielsogl/awesome-cordova-plugins.git
synced 2025-02-22 09:49:35 +08:00
fix(ssr): fix window references
This commit is contained in:
parent
e3e8c85087
commit
5b1bdc37e0
@ -186,7 +186,7 @@ export function checkAvailability(
|
|||||||
pluginInstance = getPlugin(pluginRef);
|
pluginInstance = getPlugin(pluginRef);
|
||||||
|
|
||||||
if (!pluginInstance || (!!methodName && typeof pluginInstance[methodName] === 'undefined')) {
|
if (!pluginInstance || (!!methodName && typeof pluginInstance[methodName] === 'undefined')) {
|
||||||
if (!window.cordova) {
|
if (typeof window === 'undefined' || !window.cordova) {
|
||||||
cordovaWarn(pluginName, methodName);
|
cordovaWarn(pluginName, methodName);
|
||||||
return ERR_CORDOVA_NOT_AVAILABLE;
|
return ERR_CORDOVA_NOT_AVAILABLE;
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@ declare const window: any;
|
|||||||
* creates Angular 1 services of the form $cordovaSERVICE, ex: $cordovaStatusBar.
|
* creates Angular 1 services of the form $cordovaSERVICE, ex: $cordovaStatusBar.
|
||||||
*/
|
*/
|
||||||
export function initAngular1(plugins: any) {
|
export function initAngular1(plugins: any) {
|
||||||
if (window.angular) {
|
if (typeof window !== 'undefined' && window.angular) {
|
||||||
const ngModule = window.angular.module('ionic.native', []);
|
const ngModule = window.angular.module('ionic.native', []);
|
||||||
|
|
||||||
for (const name in plugins) {
|
for (const name in plugins) {
|
||||||
|
@ -20,7 +20,7 @@ export function get(element: Element | Window, path: string) {
|
|||||||
*/
|
*/
|
||||||
export function getPromise(callback: Function = () => {}): Promise<any> {
|
export function getPromise(callback: Function = () => {}): Promise<any> {
|
||||||
const tryNativePromise = () => {
|
const tryNativePromise = () => {
|
||||||
if (window.Promise) {
|
if (typeof Promise === 'function' || (typeof window !== 'undefined' && window.Promise)) {
|
||||||
return new Promise<any>((resolve, reject) => {
|
return new Promise<any>((resolve, reject) => {
|
||||||
callback(resolve, reject);
|
callback(resolve, reject);
|
||||||
});
|
});
|
||||||
|
@ -147,7 +147,7 @@ export class Geofence extends IonicNativePlugin {
|
|||||||
*/
|
*/
|
||||||
onNotificationClicked(): Observable<any> {
|
onNotificationClicked(): Observable<any> {
|
||||||
return new Observable<any>(observer => {
|
return new Observable<any>(observer => {
|
||||||
window &&
|
typeof window !== 'undefined' &&
|
||||||
window.geofence &&
|
window.geofence &&
|
||||||
(window.geofence.onNotificationClicked = observer.next.bind(observer));
|
(window.geofence.onNotificationClicked = observer.next.bind(observer));
|
||||||
return () => (window.geofence.onNotificationClicked = () => {});
|
return () => (window.geofence.onNotificationClicked = () => {});
|
||||||
|
@ -129,7 +129,9 @@ export class InAppBrowserObject {
|
|||||||
|
|
||||||
this._objectInstance = cordova.InAppBrowser.open(url, target, options);
|
this._objectInstance = cordova.InAppBrowser.open(url, target, options);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
window.open(url, target);
|
if (typeof window !== 'undefined') {
|
||||||
|
window.open(url, target);
|
||||||
|
}
|
||||||
console.warn(
|
console.warn(
|
||||||
'Native: InAppBrowser is not installed or you are running on a browser. Falling back to window.open.'
|
'Native: InAppBrowser is not installed or you are running on a browser. Falling back to window.open.'
|
||||||
);
|
);
|
||||||
|
@ -391,7 +391,9 @@ export class PushObject {
|
|||||||
if (
|
if (
|
||||||
checkAvailability('PushNotification', 'init', 'PushNotification') === true
|
checkAvailability('PushNotification', 'init', 'PushNotification') === true
|
||||||
) {
|
) {
|
||||||
this._objectInstance = window.PushNotification.init(options);
|
if (typeof window !== 'undefined') {
|
||||||
|
this._objectInstance = window.PushNotification.init(options);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,7 +85,9 @@ export class ThemeableBrowserObject {
|
|||||||
styleOptions
|
styleOptions
|
||||||
);
|
);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
window.open(url);
|
if (typeof window !== 'undefined') {
|
||||||
|
window.open(url);
|
||||||
|
}
|
||||||
console.warn(
|
console.warn(
|
||||||
'Native: ThemeableBrowser is not installed or you are running on a browser. Falling back to window.open.'
|
'Native: ThemeableBrowser is not installed or you are running on a browser. Falling back to window.open.'
|
||||||
);
|
);
|
||||||
|
Loading…
Reference in New Issue
Block a user