Форк Rambox
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.7 KiB

/**
* This file is loaded in the service web views to provide a Hamsket API.
*/
const { ipcRenderer, remote } = require('electron');
const contextMenu = require('electron-context-menu');
/**
* Make the Hamsket API available via a global "hamsket" variable.
*
* @type {{}}
*/
window.hamsket = {};
window.hamsket.locale = ipcRenderer.sendSync('getConfig').locale;
/**
* Sets the unread count of the tab.
*
* @param {*} count The unread count
*/
window.hamsket.setUnreadCount = function(count) {
ipcRenderer.sendToHost('hamsket.setUnreadCount', count);
};
/**
* Update the badge of the tab.
* @param {*} direct
* @param {*} indirect
*/
window.hamsket.updateBadge = function(direct, indirect = 0) {
ipcRenderer.sendToHost('hamsket.updateBadge', direct, indirect);
};
/**
* Clears the unread count.
*/
window.hamsket.clearUnreadCount = function() {
ipcRenderer.sendToHost('hamsket.clearUnreadCount');
}
contextMenu({
window: remote.getCurrentWebContents(),
showCopyImageAddress: true,
showSaveImage: false,
showSaveImageAs: true
});
/**
* Override to add notification click event to display Hamsket window and activate service tab
*/
const NativeNotification = Notification;
Notification = function(title, options) {
const notification = new NativeNotification(title, options);
notification.addEventListener('click', function() {
ipcRenderer.sendToHost('hamsket.showWindowAndActivateTab');
});
return notification;
};
Notification.prototype = NativeNotification.prototype;
Notification.permission = NativeNotification.permission;
Notification.requestPermission = NativeNotification.requestPermission.bind(Notification);
window.close = function() { location.href = location.origin };