Fix focusing tab on notification's click
This commit is contained in:
parent
4d798eb302
commit
59c02ce5d1
@ -25,6 +25,7 @@ import stateStorage from "../stateStorage";
|
|||||||
import apiUpdatesManager from "./apiUpdatesManager";
|
import apiUpdatesManager from "./apiUpdatesManager";
|
||||||
import appChatsManager from "./appChatsManager";
|
import appChatsManager from "./appChatsManager";
|
||||||
import appPeersManager from "./appPeersManager";
|
import appPeersManager from "./appPeersManager";
|
||||||
|
import appRuntimeManager from "./appRuntimeManager";
|
||||||
import appStateManager from "./appStateManager";
|
import appStateManager from "./appStateManager";
|
||||||
import appUsersManager from "./appUsersManager";
|
import appUsersManager from "./appUsersManager";
|
||||||
|
|
||||||
@ -599,7 +600,7 @@ export class AppNotificationsManager {
|
|||||||
|
|
||||||
notification.onclick = () => {
|
notification.onclick = () => {
|
||||||
notification.close();
|
notification.close();
|
||||||
//AppRuntimeManager.focus();
|
appRuntimeManager.focus();
|
||||||
this.clear();
|
this.clear();
|
||||||
if(data.onclick) {
|
if(data.onclick) {
|
||||||
data.onclick();
|
data.onclick();
|
||||||
|
53
src/lib/appManagers/appRuntimeManager.ts
Normal file
53
src/lib/appManagers/appRuntimeManager.ts
Normal file
@ -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;
|
@ -25,6 +25,7 @@ import singleInstance from './singleInstance';
|
|||||||
import sessionStorage from '../sessionStorage';
|
import sessionStorage from '../sessionStorage';
|
||||||
import webPushApiManager from './webPushApiManager';
|
import webPushApiManager from './webPushApiManager';
|
||||||
import AppStorage from '../storage';
|
import AppStorage from '../storage';
|
||||||
|
import appRuntimeManager from '../appManagers/appRuntimeManager';
|
||||||
|
|
||||||
type Task = {
|
type Task = {
|
||||||
taskId: number,
|
taskId: number,
|
||||||
@ -102,7 +103,7 @@ export class ApiManagerProxy extends CryptoWorkerMethods {
|
|||||||
sessionStorage.clear(),
|
sessionStorage.clear(),
|
||||||
webPushApiManager.forceUnsubscribe()
|
webPushApiManager.forceUnsubscribe()
|
||||||
]).finally(() => {
|
]).finally(() => {
|
||||||
location.reload();
|
appRuntimeManager.reload();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -18,6 +18,7 @@ import { ServiceWorkerNotificationsClearTask, ServiceWorkerPingTask, ServiceWork
|
|||||||
import apiManager from "./mtprotoworker";
|
import apiManager from "./mtprotoworker";
|
||||||
import I18n, { LangPackKey } from "../langPack";
|
import I18n, { LangPackKey } from "../langPack";
|
||||||
import { isMobile } from "../../helpers/userAgent";
|
import { isMobile } from "../../helpers/userAgent";
|
||||||
|
import appRuntimeManager from "../appManagers/appRuntimeManager";
|
||||||
|
|
||||||
export type PushSubscriptionNotifyType = 'init' | 'subscribe' | 'unsubscribe';
|
export type PushSubscriptionNotifyType = 'init' | 'subscribe' | 'unsubscribe';
|
||||||
export type PushSubscriptionNotifyEvent = `push_${PushSubscriptionNotifyType}`;
|
export type PushSubscriptionNotifyEvent = `push_${PushSubscriptionNotifyType}`;
|
||||||
@ -211,8 +212,7 @@ export class WebPushApiManager {
|
|||||||
|
|
||||||
apiManager.addServiceWorkerTaskListener('push_click', (task: ServiceWorkerPushClickTask) => {
|
apiManager.addServiceWorkerTaskListener('push_click', (task: ServiceWorkerPushClickTask) => {
|
||||||
if(rootScope.idle && rootScope.idle.deactivated) {
|
if(rootScope.idle && rootScope.idle.deactivated) {
|
||||||
// AppRuntimeManager.reload(); // WARNING
|
appRuntimeManager.reload();
|
||||||
location.reload();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user