Skip to content

Bounce dock only once on receiving a private message #733

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 10 additions & 15 deletions app/renderer/js/components/webview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,21 +91,6 @@ class WebView extends BaseComponent {
this.canGoBackButton();
});

this.$el.addEventListener('page-favicon-updated', event => {
const { favicons } = event;

// This returns a string of favicons URL. If there is a PM counts in unread messages then the URL would be like
// https://chat.zulip.org/static/images/favicon/favicon-pms.png
if (favicons[0].indexOf('favicon-pms') > 0 && process.platform === 'darwin') {
// This api is only supported on macOS
app.dock.setBadge('●');
// bounce the dock
if (ConfigUtil.getConfigItem('dockBouncing')) {
app.dock.bounce();
}
}
});

this.$el.addEventListener('dom-ready', () => {
if (this.props.role === 'server') {
this.$el.classList.add('onload');
Expand Down Expand Up @@ -197,6 +182,16 @@ class WebView extends BaseComponent {
}
}

updatePMCount(count: number): void {
if (process.platform === 'darwin') {
app.dock.setBadge(count.toString());
if (ConfigUtil.getConfigItem('dockBouncing') && ConfigUtil.getConfigItem('showNotification')) {
app.dock.bounce();
}
this.props.unreadPmCount = count;
}
}

focus(): void {
// focus Webview and it's contents when Window regain focus.
const webContents = this.$el.getWebContents();
Expand Down
6 changes: 6 additions & 0 deletions app/renderer/js/electron-bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ electron_bridge.on('total_unread_count', (...args) => {
ipcRenderer.send('unread-count', ...args);
});

electron_bridge.on('unread_pm_count', unreadPMs => {
const unreadPMCount = unreadPMs.unread_pm_count;
const realmUri = unreadPMs.realm_uri;
ipcRenderer.send('forward-message', 'unread-pm-count', unreadPMCount, realmUri);
});

electron_bridge.on('realm_name', realmName => {
const serverURL = location.origin;
ipcRenderer.send('realm-name-changed', serverURL, realmName);
Expand Down
10 changes: 9 additions & 1 deletion app/renderer/js/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,8 @@ class ServerManagerView {
onNetworkError: this.openNetworkTroubleshooting.bind(this),
onTitleChange: this.updateBadge.bind(this),
nodeIntegration: false,
preload: true
preload: true,
unreadPMCount: 0
})
}));
this.loading[server.url] = true;
Expand Down Expand Up @@ -994,6 +995,13 @@ class ServerManagerView {
webview.send('set-idle');
});
});

ipcRenderer.on('unread-pm-count', (event: Event, unreadPMCount: number, realmUri: string) => {
const tabIndex = DomainUtil.getIndex(realmUri);
if (tabIndex < 0) {
this.tabs[tabIndex].webview.updatePMCount(unreadPMCount);
}
});
}
}

Expand Down
12 changes: 12 additions & 0 deletions app/renderer/js/utils/domain-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,18 @@ class DomainUtil {
return this.db.getData(`/domains[${index}]`);
}

getIndex(url: string): number {
const domains = this.getDomains();
for (let i = 0; i < domains.length; i++) {
const domain = domains[i];
if (domain.url === url) {
return i;
}
}
// invalid index, use check in calling function
return -1;
}

updateDomain(index: number, server: object): void {
this.reloadDB();
this.db.push(`/domains[${index}]`, server, true);
Expand Down