|
| 1 | +import { GOGCloudSavesLocation } from 'common/types/gog' |
| 2 | +import { ipcRenderer } from 'electron' |
| 3 | +import { Runner, Tools } from '../../common/types' |
| 4 | + |
| 5 | +export const clearCache = () => ipcRenderer.send('clearCache') |
| 6 | +export const resetHeroic = () => ipcRenderer.send('resetHeroic') |
| 7 | + |
| 8 | +export const openWeblate = () => ipcRenderer.send('openWeblate') |
| 9 | +export const changeLanguage = (newLanguage: string) => |
| 10 | + ipcRenderer.send('changeLanguage', newLanguage) |
| 11 | + |
| 12 | +export const openExternalUrl = (url: string) => |
| 13 | + ipcRenderer.send('openExternalUrl', url) |
| 14 | +export const getHeroicVersion = async () => |
| 15 | + ipcRenderer.invoke('getHeroicVersion') |
| 16 | +export const getLatestReleases = async () => |
| 17 | + ipcRenderer.invoke('getLatestReleases') |
| 18 | + |
| 19 | +export const openPatreonPage = () => ipcRenderer.send('openPatreonPage') |
| 20 | +export const openKofiPage = () => ipcRenderer.send('openKofiPage') |
| 21 | +export const isFullscreen = async () => ipcRenderer.invoke('isFullscreen') |
| 22 | + |
| 23 | +export const openWebviewPage = (url: string) => |
| 24 | + ipcRenderer.send('openWebviewPage', url) |
| 25 | + |
| 26 | +export const setZoomFactor = (zoom: string) => |
| 27 | + ipcRenderer.send('setZoomFactor', zoom) |
| 28 | +export const frontendReady = () => ipcRenderer.send('frontendReady') |
| 29 | +export const lock = () => ipcRenderer.send('lock') |
| 30 | +export const unlock = () => ipcRenderer.send('unlock') |
| 31 | +export const login = async (sid: string) => ipcRenderer.invoke('login', sid) |
| 32 | +export const logoutLegendary = async () => ipcRenderer.invoke('logoutLegendary') |
| 33 | +export const authGOG = async (token: string) => |
| 34 | + ipcRenderer.invoke('authGOG', token) |
| 35 | +export const logoutGOG = async () => ipcRenderer.invoke('logoutGOG') |
| 36 | +export const checkGameUpdates = async () => |
| 37 | + ipcRenderer.invoke('checkGameUpdates') |
| 38 | +export const refreshLibrary = async ( |
| 39 | + fullRefresh?: boolean, |
| 40 | + library?: Runner | 'all' |
| 41 | +) => ipcRenderer.invoke('refreshLibrary', fullRefresh, library) |
| 42 | + |
| 43 | +export const gamepadAction = async ( |
| 44 | + args: [action: string, metadata: { elementTag: string; x: number; y: number }] |
| 45 | +) => ipcRenderer.invoke('gamepadAction', args) |
| 46 | + |
| 47 | +export const logError = (error: string) => ipcRenderer.send('logError', error) |
| 48 | +export const logInfo = (info: string) => ipcRenderer.send('logInfo', info) |
| 49 | +export const showConfigFileInFolder = (appName: string) => |
| 50 | + ipcRenderer.send('showConfigFileInFolder', appName) |
| 51 | +export const openFolder = (installPath: string) => |
| 52 | + ipcRenderer.send('openFolder', installPath) |
| 53 | +export const syncGOGSaves = async ( |
| 54 | + gogSaves: GOGCloudSavesLocation[], |
| 55 | + appName: string, |
| 56 | + arg: string |
| 57 | +) => ipcRenderer.invoke('syncGOGSaves', gogSaves, appName, arg) |
| 58 | +export const getFonts = async (reload: boolean) => |
| 59 | + ipcRenderer.invoke('getFonts', reload) |
| 60 | +export const checkDiskSpace = async (installPath: string) => |
| 61 | + ipcRenderer.invoke('checkDiskSpace', installPath) |
| 62 | +export const getGOGLinuxInstallersLangs = async (appName: string) => |
| 63 | + ipcRenderer.invoke('getGOGLinuxInstallersLangs', appName) |
| 64 | +export const getAlternativeWine = async () => |
| 65 | + ipcRenderer.invoke('getAlternativeWine') |
| 66 | +export const getGOGGameClientId = async (appName: string) => |
| 67 | + ipcRenderer.invoke('getGOGGameClientId', appName) |
| 68 | +export const getShellPath = async (saveLocation: string) => |
| 69 | + ipcRenderer.invoke('getShellPath', saveLocation) |
| 70 | +export const getRealPath = async (actualPath: string) => |
| 71 | + ipcRenderer.invoke('getRealPath', actualPath) |
| 72 | +export const callTool = async (toolArgs: Tools) => |
| 73 | + ipcRenderer.invoke('callTool', toolArgs) |
| 74 | +export const getAnticheatInfo = async (namespace: string) => |
| 75 | + ipcRenderer.invoke('getAnticheatInfo', namespace) |
| 76 | + |
| 77 | +export const requestSettingsRemoveListeners = () => |
| 78 | + ipcRenderer.removeAllListeners('requestSettings') |
| 79 | + |
| 80 | +export const clipboardReadText = async () => |
| 81 | + ipcRenderer.invoke('clipboardReadText') |
| 82 | + |
| 83 | +export const clipboardWriteText = async (text: string) => |
| 84 | + ipcRenderer.send('clipboardWriteText', text) |
| 85 | + |
| 86 | +import Store from 'electron-store' |
| 87 | +// FUTURE WORK |
| 88 | +// here is how the store methods can be refactored |
| 89 | +// in order to set nodeIntegration: false |
| 90 | +// but converting sync methods to async propagates through frontend |
| 91 | + |
| 92 | +// export const storeNew = async ( |
| 93 | +// name: string, |
| 94 | +// options: Store.Options<Record<string, unknown>> |
| 95 | +// ) => ipcRenderer.send('storeNew', name, options) |
| 96 | + |
| 97 | +// export const storeSet = async (name: string, key: string, value?: unknown) => |
| 98 | +// ipcRenderer.send('storeSet', name, key, value) |
| 99 | + |
| 100 | +// export const storeHas = async (name: string, key: string) => |
| 101 | +// ipcRenderer.invoke('storeHas', name, key) |
| 102 | + |
| 103 | +// export const storeGet = async (name: string, key: string) => |
| 104 | +// ipcRenderer.invoke('storeGet', name, key) |
| 105 | + |
| 106 | +interface StoreMap { |
| 107 | + [key: string]: Store |
| 108 | +} |
| 109 | +const stores: StoreMap = {} |
| 110 | + |
| 111 | +export const storeNew = function ( |
| 112 | + storeName: string, |
| 113 | + options: Store.Options<Record<string, unknown>> |
| 114 | +) { |
| 115 | + stores[storeName] = new Store(options) |
| 116 | +} |
| 117 | + |
| 118 | +export const storeSet = (storeName: string, key: string, value?: unknown) => |
| 119 | + stores[storeName].set(key, value) |
| 120 | + |
| 121 | +export const storeHas = (storeName: string, key: string) => |
| 122 | + stores[storeName].has(key) |
| 123 | + |
| 124 | +export const storeGet = ( |
| 125 | + storeName: string, |
| 126 | + key: string, |
| 127 | + defaultValue?: unknown |
| 128 | +) => stores[storeName].get(key, defaultValue) |
0 commit comments