Browse Source

Fix focusing tab on notification's click

master
Eduard Kuzmenko 4 years ago
parent
commit
59c02ce5d1
  1. 3
      src/lib/appManagers/appNotificationsManager.ts
  2. 53
      src/lib/appManagers/appRuntimeManager.ts
  3. 3
      src/lib/mtproto/mtprotoworker.ts
  4. 4
      src/lib/mtproto/webPushApiManager.ts

3
src/lib/appManagers/appNotificationsManager.ts

@ -25,6 +25,7 @@ import stateStorage from "../stateStorage"; @@ -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 { @@ -599,7 +600,7 @@ export class AppNotificationsManager {
notification.onclick = () => {
notification.close();
//AppRuntimeManager.focus();
appRuntimeManager.focus();
this.clear();
if(data.onclick) {
data.onclick();

53
src/lib/appManagers/appRuntimeManager.ts

@ -0,0 +1,53 @@ @@ -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 <igor.beatle@gmail.com>
* 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;

3
src/lib/mtproto/mtprotoworker.ts

@ -25,6 +25,7 @@ import singleInstance from './singleInstance'; @@ -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 { @@ -102,7 +103,7 @@ export class ApiManagerProxy extends CryptoWorkerMethods {
sessionStorage.clear(),
webPushApiManager.forceUnsubscribe()
]).finally(() => {
location.reload();
appRuntimeManager.reload();
});
});

4
src/lib/mtproto/webPushApiManager.ts

@ -18,6 +18,7 @@ import { ServiceWorkerNotificationsClearTask, ServiceWorkerPingTask, ServiceWork @@ -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 { @@ -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;
}

Loading…
Cancel
Save