Skip to content

Commit

Permalink
fix(ssr): fix window references
Browse files Browse the repository at this point in the history
  • Loading branch information
adamdbradley committed Feb 23, 2019
1 parent e3e8c85 commit 5b1bdc3
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/@ionic-native/core/decorators/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ export function checkAvailability(
pluginInstance = getPlugin(pluginRef);

if (!pluginInstance || (!!methodName && typeof pluginInstance[methodName] === 'undefined')) {
if (!window.cordova) {
if (typeof window === 'undefined' || !window.cordova) {
cordovaWarn(pluginName, methodName);
return ERR_CORDOVA_NOT_AVAILABLE;
}
Expand Down
2 changes: 1 addition & 1 deletion src/@ionic-native/core/ng1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ declare const window: any;
* creates Angular 1 services of the form $cordovaSERVICE, ex: $cordovaStatusBar.
*/
export function initAngular1(plugins: any) {
if (window.angular) {
if (typeof window !== 'undefined' && window.angular) {
const ngModule = window.angular.module('ionic.native', []);

for (const name in plugins) {
Expand Down
2 changes: 1 addition & 1 deletion src/@ionic-native/core/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export function get(element: Element | Window, path: string) {
*/
export function getPromise(callback: Function = () => {}): Promise<any> {
const tryNativePromise = () => {
if (window.Promise) {
if (typeof Promise === 'function' || (typeof window !== 'undefined' && window.Promise)) {
return new Promise<any>((resolve, reject) => {
callback(resolve, reject);
});
Expand Down
2 changes: 1 addition & 1 deletion src/@ionic-native/plugins/geofence/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ export class Geofence extends IonicNativePlugin {
*/
onNotificationClicked(): Observable<any> {
return new Observable<any>(observer => {
window &&
typeof window !== 'undefined' &&
window.geofence &&
(window.geofence.onNotificationClicked = observer.next.bind(observer));
return () => (window.geofence.onNotificationClicked = () => {});
Expand Down
4 changes: 3 additions & 1 deletion src/@ionic-native/plugins/in-app-browser/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,9 @@ export class InAppBrowserObject {

this._objectInstance = cordova.InAppBrowser.open(url, target, options);
} catch (e) {
window.open(url, target);
if (typeof window !== 'undefined') {
window.open(url, target);
}
console.warn(
'Native: InAppBrowser is not installed or you are running on a browser. Falling back to window.open.'
);
Expand Down
4 changes: 3 additions & 1 deletion src/@ionic-native/plugins/push/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,9 @@ export class PushObject {
if (
checkAvailability('PushNotification', 'init', 'PushNotification') === true
) {
this._objectInstance = window.PushNotification.init(options);
if (typeof window !== 'undefined') {
this._objectInstance = window.PushNotification.init(options);
}
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/@ionic-native/plugins/themeable-browser/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ export class ThemeableBrowserObject {
styleOptions
);
} catch (e) {
window.open(url);
if (typeof window !== 'undefined') {
window.open(url);
}
console.warn(
'Native: ThemeableBrowser is not installed or you are running on a browser. Falling back to window.open.'
);
Expand Down

0 comments on commit 5b1bdc3

Please sign in to comment.