diff --git a/src/lib/appManagers/appNotificationsManager.ts b/src/lib/appManagers/appNotificationsManager.ts index d60f4bdf..8a333014 100644 --- a/src/lib/appManagers/appNotificationsManager.ts +++ b/src/lib/appManagers/appNotificationsManager.ts @@ -25,6 +25,7 @@ import stateStorage from "../stateStorage"; import apiUpdatesManager from "./apiUpdatesManager"; import appChatsManager from "./appChatsManager"; import appPeersManager from "./appPeersManager"; +import appRuntimeManager from "./appRuntimeManager"; import appStateManager from "./appStateManager"; import appUsersManager from "./appUsersManager"; @@ -599,7 +600,7 @@ export class AppNotificationsManager { notification.onclick = () => { notification.close(); - //AppRuntimeManager.focus(); + appRuntimeManager.focus(); this.clear(); if(data.onclick) { data.onclick(); diff --git a/src/lib/appManagers/appRuntimeManager.ts b/src/lib/appManagers/appRuntimeManager.ts new file mode 100644 index 00000000..fc309459 --- /dev/null +++ b/src/lib/appManagers/appRuntimeManager.ts @@ -0,0 +1,53 @@ +/* + * https://github.com/morethanwords/tweb + * Copyright (C) 2019-2021 Eduard Kuzmenko + * https://github.com/morethanwords/tweb/blob/master/LICENSE + * + * Originally from: + * https://github.com/zhukov/webogram + * Copyright (C) 2014 Igor Zhukov + * https://github.com/zhukov/webogram/blob/master/LICENSE + */ + +export class AppRuntimeManager { + public reload() { + try { + location.reload(); + } catch(e) {}; + + // if(window.chrome && chrome.runtime && chrome.runtime.reload) { + // chrome.runtime.reload(); + // } + } + + public close() { + try { + window.close(); + } catch(e) {} + } + + /** + * Better to call from event + */ + public focus() { + // // @ts-ignore + // if(window.navigator.mozApps && document.hidden) { + // // Get app instance and launch it to bring app to foreground + // // @ts-ignore + // window.navigator.mozApps.getSelf().onsuccess = function() { + // this.result.launch(); + // }; + // } else { + // // @ts-ignore + // if(window.chrome && chrome.app && chrome.app.window) { + // // @ts-ignore + // chrome.app.window.current().focus(); + // } + + window.focus(); + // } + } +} + +const appRuntimeManager = new AppRuntimeManager(); +export default appRuntimeManager; diff --git a/src/lib/mtproto/mtprotoworker.ts b/src/lib/mtproto/mtprotoworker.ts index d0d60b96..1e39db92 100644 --- a/src/lib/mtproto/mtprotoworker.ts +++ b/src/lib/mtproto/mtprotoworker.ts @@ -25,6 +25,7 @@ import singleInstance from './singleInstance'; import sessionStorage from '../sessionStorage'; import webPushApiManager from './webPushApiManager'; import AppStorage from '../storage'; +import appRuntimeManager from '../appManagers/appRuntimeManager'; type Task = { taskId: number, @@ -102,7 +103,7 @@ export class ApiManagerProxy extends CryptoWorkerMethods { sessionStorage.clear(), webPushApiManager.forceUnsubscribe() ]).finally(() => { - location.reload(); + appRuntimeManager.reload(); }); }); diff --git a/src/lib/mtproto/webPushApiManager.ts b/src/lib/mtproto/webPushApiManager.ts index e5e3015a..c1feeb62 100644 --- a/src/lib/mtproto/webPushApiManager.ts +++ b/src/lib/mtproto/webPushApiManager.ts @@ -18,6 +18,7 @@ import { ServiceWorkerNotificationsClearTask, ServiceWorkerPingTask, ServiceWork import apiManager from "./mtprotoworker"; import I18n, { LangPackKey } from "../langPack"; import { isMobile } from "../../helpers/userAgent"; +import appRuntimeManager from "../appManagers/appRuntimeManager"; export type PushSubscriptionNotifyType = 'init' | 'subscribe' | 'unsubscribe'; export type PushSubscriptionNotifyEvent = `push_${PushSubscriptionNotifyType}`; @@ -211,8 +212,7 @@ export class WebPushApiManager { apiManager.addServiceWorkerTaskListener('push_click', (task: ServiceWorkerPushClickTask) => { if(rootScope.idle && rootScope.idle.deactivated) { - // AppRuntimeManager.reload(); // WARNING - location.reload(); + appRuntimeManager.reload(); return; }