|
| 1 | +import { contextBridge, ipcRenderer } from 'electron'; |
| 2 | +import { namespacedEvent } from '../shared/events'; |
| 3 | + |
| 4 | +import { Constants } from '../renderer/utils/constants'; |
| 5 | +import type { GitifyAPI } from './types'; |
| 6 | + |
| 7 | +const api: GitifyAPI = { |
| 8 | + // Define the global variable |
| 9 | + global: globalThis, |
| 10 | + |
| 11 | + openExternalLink: (url) => |
| 12 | + ipcRenderer.send(namespacedEvent('open-external-link'), url), |
| 13 | + |
| 14 | + getAppVersion: () => ipcRenderer.invoke(namespacedEvent('version')), |
| 15 | + |
| 16 | + encryptValue: (value) => |
| 17 | + ipcRenderer.invoke(namespacedEvent('safe-storage-encrypt'), value), |
| 18 | + |
| 19 | + decryptValue: (value) => |
| 20 | + ipcRenderer.invoke(namespacedEvent('safe-storage-decrypt'), value), |
| 21 | + |
| 22 | + quitApp: () => ipcRenderer.send(namespacedEvent('quit')), |
| 23 | + |
| 24 | + showWindow: () => ipcRenderer.send(namespacedEvent('window-show')), |
| 25 | + |
| 26 | + hideWindow: () => ipcRenderer.send(namespacedEvent('window-hide')), |
| 27 | + |
| 28 | + setAutoLaunch: (value) => |
| 29 | + ipcRenderer.send(namespacedEvent('update-auto-launch'), { |
| 30 | + openAtLogin: value, |
| 31 | + openAsHidden: value, |
| 32 | + }), |
| 33 | + |
| 34 | + setAlternateIdleIcon: (value) => |
| 35 | + ipcRenderer.send(namespacedEvent('use-alternate-idle-icon'), value), |
| 36 | + |
| 37 | + setKeyboardShortcut: (keyboardShortcut) => |
| 38 | + ipcRenderer.send(namespacedEvent('update-keyboard-shortcut'), { |
| 39 | + enabled: keyboardShortcut, |
| 40 | + keyboardShortcut: Constants.DEFAULT_KEYBOARD_SHORTCUT, |
| 41 | + }), |
| 42 | + |
| 43 | + updateTrayIcon: (notificationsLength = 0) => { |
| 44 | + if (notificationsLength < 0) { |
| 45 | + ipcRenderer.send(namespacedEvent('icon-error')); |
| 46 | + return; |
| 47 | + } |
| 48 | + |
| 49 | + if (notificationsLength > 0) { |
| 50 | + ipcRenderer.send(namespacedEvent('icon-active')); |
| 51 | + return; |
| 52 | + } |
| 53 | + |
| 54 | + ipcRenderer.send(namespacedEvent('icon-idle')); |
| 55 | + // ipcRenderer.send(namespacedEvent('update-tray-icon'), notificationsLength), |
| 56 | + }, |
| 57 | + |
| 58 | + updateTrayTitle: (title = '') => |
| 59 | + ipcRenderer.send(namespacedEvent('update-title'), title), |
| 60 | +}; |
| 61 | + |
| 62 | +contextBridge.exposeInMainWorld('gitify', api); |
0 commit comments