slackgmailskypefacebook-workplaceoutlookemailmicrosoft-teamsdiscordmessengercustom-servicesmacoslinuxwindowsinboxwhatsappicloudtweetdeckhipchattelegramhangouts
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
68 lines
1.8 KiB
68 lines
1.8 KiB
8 years ago
|
/**
|
||
6 years ago
|
* This file is loaded in the service web views to provide a Hamsket API.
|
||
8 years ago
|
*/
|
||
|
|
||
|
const { ipcRenderer } = require('electron');
|
||
7 years ago
|
const { MenuItem } = require('electron').remote;
|
||
|
const { ContextMenuBuilder, ContextMenuListener } = require('electron-contextmenu-wrapper');
|
||
8 years ago
|
|
||
|
/**
|
||
6 years ago
|
* Make the Hamsket API available via a global "hamsket" variable.
|
||
8 years ago
|
*
|
||
|
* @type {{}}
|
||
|
*/
|
||
6 years ago
|
window.hamsket = {};
|
||
8 years ago
|
|
||
6 years ago
|
window.hamsket.locale = ipcRenderer.sendSync('getConfig').locale;
|
||
7 years ago
|
|
||
8 years ago
|
/**
|
||
7 years ago
|
* Sets the unread count of the tab.
|
||
8 years ago
|
*
|
||
|
* @param {*} count The unread count
|
||
|
*/
|
||
6 years ago
|
window.hamsket.setUnreadCount = function(count) {
|
||
|
ipcRenderer.sendToHost('hamsket.setUnreadCount', count);
|
||
8 years ago
|
};
|
||
|
|
||
7 years ago
|
/**
|
||
|
* Update the badge of the tab.
|
||
|
* @param {*} direct
|
||
|
* @param {*} indirect
|
||
|
*/
|
||
6 years ago
|
window.hamsket.updateBadge = function(direct, indirect = 0) {
|
||
|
ipcRenderer.sendToHost('hamsket.updateBadge', direct, indirect);
|
||
7 years ago
|
};
|
||
|
|
||
8 years ago
|
/**
|
||
|
* Clears the unread count.
|
||
|
*/
|
||
6 years ago
|
window.hamsket.clearUnreadCount = function() {
|
||
|
ipcRenderer.sendToHost('hamsket.clearUnreadCount');
|
||
8 years ago
|
}
|
||
8 years ago
|
|
||
6 years ago
|
window.hamsket.contextMenuBuilder = new ContextMenuBuilder();
|
||
|
window.hamsket.contextMenuListener = new ContextMenuListener(function(event, info) {
|
||
|
window.hamsket.contextMenuBuilder.showPopupMenu(info);
|
||
7 years ago
|
});
|
||
|
|
||
|
|
||
8 years ago
|
/**
|
||
6 years ago
|
* Override to add notification click event to display Hamsket window and activate service tab
|
||
8 years ago
|
*/
|
||
6 years ago
|
const NativeNotification = Notification;
|
||
8 years ago
|
Notification = function(title, options) {
|
||
6 years ago
|
const notification = new NativeNotification(title, options);
|
||
8 years ago
|
|
||
|
notification.addEventListener('click', function() {
|
||
6 years ago
|
ipcRenderer.sendToHost('hamsket.showWindowAndActivateTab');
|
||
8 years ago
|
});
|
||
|
|
||
|
return notification;
|
||
6 years ago
|
};
|
||
8 years ago
|
|
||
|
Notification.prototype = NativeNotification.prototype;
|
||
|
Notification.permission = NativeNotification.permission;
|
||
|
Notification.requestPermission = NativeNotification.requestPermission.bind(Notification);
|
||
7 years ago
|
|
||
|
window.close = function() { location.href = location.origin };
|