khoj/src/interface/desktop/preload.js
Raghav Tirumale 24a0d8b073
Add OS Level Shortcut Window for Quick Access to Khoj Desktop (#815)
* rough sketch of desktop shortcuts. many bugs to fix still

* working MVP of desktop shortcut khoj

* UI fixes

* UI improvements for editable shortcut message

* major rendering fix to prevent clipboard text from getting lost

* UI improvements and bug fixes

* UI upgrades: custom top bar, edit sent message and color matching

* removed debug javascript file

* font reverted to Noto Sans

* cleaning up the code and removing diffs

* UX fixes

* cleaning up unused methods from html

* front end for button to send user back to main window to continue conversation

* UX fix for window and continue conversation support added

* migrated common js functions into chatutils.js

* Fix window closing issue in macos by

1. Use a helper function to determine if the window is open by seeing if there's a browser window with shortcut.html loaded
2. Use the  event listener on the window to handle teardown

* removed extra comment and renamed continue convo button

---------

Co-authored-by: sabaimran <narmiabas@gmail.com>
2024-06-27 07:20:13 -07:00

86 lines
2.7 KiB
JavaScript

window.addEventListener('DOMContentLoaded', () => {
const replaceText = (selector, text) => {
const element = document.getElementById(selector)
if (element) element.innerText = text
}
for (const dependency of ['chrome', 'node', 'electron']) {
replaceText(`${dependency}-version`, process.versions[dependency])
}
})
const { contextBridge, ipcRenderer } = require('electron');
contextBridge.exposeInMainWorld('electronAPI', {
setTitle: (title) => ipcRenderer.send('set-title', title)
})
contextBridge.exposeInMainWorld('clipboardAPI', {
sendClipboardText: (callback) => {
ipcRenderer.on('clip', (event, message) => {
callback(message);
});
}
});
contextBridge.exposeInMainWorld('routeBackToMainWindowAPI', {
sendSignal: () => {
ipcRenderer.send('continue-conversation-button-clicked'); // Custom event name
}
});
contextBridge.exposeInMainWorld('storeValueAPI', {
handleFileOpen: (key) => ipcRenderer.invoke('handleFileOpen', key)
})
contextBridge.exposeInMainWorld('getFilesAPI', {
getFiles: () => ipcRenderer.invoke('getFiles')
})
contextBridge.exposeInMainWorld('getFoldersAPI', {
getFolders: () => ipcRenderer.invoke('getFolders')
})
contextBridge.exposeInMainWorld('updateStateAPI', {
onUpdateState: (callback) => ipcRenderer.on('update-state', callback)
})
contextBridge.exposeInMainWorld('needsSubscriptionAPI', {
onNeedsSubscription: (callback) => ipcRenderer.on('needsSubscription', callback)
})
contextBridge.exposeInMainWorld('removeFileAPI', {
removeFile: (filePath) => ipcRenderer.invoke('removeFile', filePath)
})
contextBridge.exposeInMainWorld('removeFolderAPI', {
removeFolder: (folderPath) => ipcRenderer.invoke('removeFolder', folderPath)
})
contextBridge.exposeInMainWorld('hostURLAPI', {
setURL: (url) => ipcRenderer.invoke('setURL', url),
getURL: () => ipcRenderer.invoke('getURL')
})
contextBridge.exposeInMainWorld('syncDataAPI', {
syncData: (regenerate) => ipcRenderer.invoke('syncData', regenerate),
deleteAllFiles: () => ipcRenderer.invoke('deleteAllFiles')
})
contextBridge.exposeInMainWorld('userInfoAPI', {
getUserInfo: () => ipcRenderer.invoke('getUserInfo')
})
contextBridge.exposeInMainWorld('tokenAPI', {
setToken: (token) => ipcRenderer.invoke('setToken', token),
getToken: () => ipcRenderer.invoke('getToken')
})
contextBridge.exposeInMainWorld('appInfoAPI', {
getInfo: (callback) => ipcRenderer.on('appInfo', callback)
})
contextBridge.exposeInMainWorld('navigateAPI', {
navigateToSettings: () => ipcRenderer.send('navigate', 'config.html'),
navigateToWebSettings: () => ipcRenderer.send('navigateToWebApp', 'config'),
})