Fix clicking on notification doesn't open the matching workspace (#288)

This commit is contained in:
Quang Lam 2020-06-08 20:58:48 +07:00 committed by GitHub
parent 72eb950112
commit fc97683f2e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 1227 additions and 1080 deletions

View file

@ -21,19 +21,19 @@
"repository": "https://github.com/atomery/singlebox",
"author": "Quang Lam <quang.lam2807@gmail.com>",
"dependencies": {
"@cliqz/adblocker-electron": "1.15.0",
"@cliqz/adblocker-electron": "1.15.1",
"cheerio": "1.0.0-rc.3",
"darkreader": "4.9.2",
"darkreader": "4.9.10",
"download": "8.0.0",
"electron-context-menu": "2.0.1",
"electron-is-dev": "1.2.0",
"electron-settings": "3.2.0",
"electron-updater": "4.3.2",
"electron-updater": "4.3.3",
"electron-window-state": "5.0.3",
"follow-redirects": "1.11.0",
"fs-extra": "9.0.0",
"fs-extra": "9.0.1",
"is-url": "1.2.4",
"jimp": "0.12.1",
"jimp": "0.13.0",
"menubar": "8.0.2",
"node-fetch": "2.6.0",
"proxy-agent": "3.1.1",
@ -44,7 +44,7 @@
},
"devDependencies": {
"@date-io/date-fns": "1.3.13",
"@material-ui/core": "4.10.0",
"@material-ui/core": "4.10.1",
"@material-ui/icons": "4.9.1",
"@material-ui/pickers": "3.2.10",
"ace-builds": "1.4.11",
@ -57,12 +57,12 @@
"concurrently": "5.2.0",
"cross-env": "7.0.2",
"date-fns": "2.14.0",
"electron": "8.3.0",
"electron-builder": "22.6.1",
"electron": "8.3.1",
"electron-builder": "22.7.0",
"electron-notarize": "0.3.0",
"eslint": "6.8.0",
"eslint-config-airbnb": "18.1.0",
"eslint-plugin-import": "2.20.2",
"eslint-plugin-import": "2.21.1",
"eslint-plugin-jsx-a11y": "6.2.3",
"eslint-plugin-react": "7.20.0",
"eslint-plugin-react-hooks": "1.7.0",
@ -80,7 +80,7 @@
"simplebar": "5.2.0",
"simplebar-react": "2.2.0",
"typeface-roboto": "0.0.75",
"wait-on": "5.0.0"
"wait-on": "5.0.1"
},
"homepage": "./",
"private": true,

View file

@ -158,6 +158,7 @@ const addView = (browserWindow, workspace) => {
const view = new BrowserView({
webPreferences: sharedWebPreferences,
});
view.webContents.workspaceId = workspace.id;
// background needs to explictly set
// if not, by default, the background of BrowserView is transparent
// which would break the CSS of certain websites

View file

@ -248,8 +248,10 @@ const loadListeners = () => {
});
ipcMain.on('request-set-active-workspace', (e, id) => {
setActiveWorkspaceView(id);
createMenu();
if (getWorkspace(id)) {
setActiveWorkspaceView(id);
createMenu();
}
});
ipcMain.on('request-realign-active-workspace', () => {

View file

@ -261,9 +261,16 @@ ipcRenderer.on('display-media-id-received', (e, val) => {
});
window.addEventListener('message', (e) => {
if (!e.data || e.data.type !== 'get-display-media-id') return;
if (!e.data) return;
ipcRenderer.send('request-show-display-media-window');
if (e.data.type === 'get-display-media-id') {
ipcRenderer.send('request-show-display-media-window');
}
// set workspace to active when its notification is clicked
if (e.data.type === 'focus-workspace') {
ipcRenderer.send('request-set-active-workspace', e.data.workspaceId);
}
});
// Fix Can't show file list of Google Drive
@ -272,6 +279,8 @@ window.addEventListener('message', (e) => {
// Fix chrome.runtime.sendMessage is undefined for FastMail
// https://github.com/atomery/singlebox/issues/21
const initialShouldPauseNotifications = ipcRenderer.sendSync('get-pause-notifications-info') != null;
const { workspaceId } = remote.getCurrentWebContents();
webFrame.executeJavaScript(`
(function() {
window.chrome = {
@ -309,7 +318,12 @@ webFrame.executeJavaScript(`
window.Notification = function() {
if (!shouldPauseNotifications) {
return new oldNotification(...arguments);
const notif = new oldNotification(...arguments);
notif.addEventListener('click', () => {
window.postMessage({ type: 'focus-workspace', workspaceId: "${workspaceId}" });
});
console.log(notif);
return notif;
}
return null;
}

2260
yarn.lock

File diff suppressed because it is too large Load diff