Indicate in the desktop if the user gets rate limited for indexing

This commit is contained in:
sabaimran
2023-11-25 22:31:23 -08:00
parent 73e38fccf3
commit 52b88de7f4
4 changed files with 27 additions and 1 deletions

View File

@@ -101,6 +101,9 @@
<div class="card-description-row"> <div class="card-description-row">
<div id="sync-status"></div> <div id="sync-status"></div>
</div> </div>
<div id="needs-subscription" style="display: none;">
Looks like you're out of space to sync your files. <a href="https://app.khoj.dev/config">Upgrade your plan</a> to unlock more space.
</div>
</div> </div>
</body> </body>

View File

@@ -198,6 +198,11 @@ function pushDataToKhoj (regenerate = false) {
}) })
.catch(error => { .catch(error => {
console.error(error); console.error(error);
if (error.response.status == 429) {
const win = BrowserWindow.getAllWindows()[0];
if (win) win.webContents.send('needsSubscription', true);
if (win) win.webContents.send('update-state', state);
}
state['completed'] = false state['completed'] = false
}) })
.finally(() => { .finally(() => {
@@ -396,6 +401,11 @@ app.whenReady().then(() => {
event.reply('update-state', arg); event.reply('update-state', arg);
}); });
ipcMain.on('needsSubscription', (event, arg) => {
console.log(arg);
event.reply('needsSubscription', arg);
});
ipcMain.on('navigate', (event, page) => { ipcMain.on('navigate', (event, page) => {
win.loadFile(page); win.loadFile(page);
}); });

View File

@@ -31,6 +31,10 @@ contextBridge.exposeInMainWorld('updateStateAPI', {
onUpdateState: (callback) => ipcRenderer.on('update-state', callback) onUpdateState: (callback) => ipcRenderer.on('update-state', callback)
}) })
contextBridge.exposeInMainWorld('needsSubscriptionAPI', {
onNeedsSubscription: (callback) => ipcRenderer.on('needsSubscription', callback)
})
contextBridge.exposeInMainWorld('removeFileAPI', { contextBridge.exposeInMainWorld('removeFileAPI', {
removeFile: (filePath) => ipcRenderer.invoke('removeFile', filePath) removeFile: (filePath) => ipcRenderer.invoke('removeFile', filePath)
}) })

View File

@@ -1,7 +1,7 @@
const setFolderButton = document.getElementById('update-folder'); const setFolderButton = document.getElementById('update-folder');
const setFileButton = document.getElementById('update-file'); const setFileButton = document.getElementById('update-file');
const showKey = document.getElementById('show-key');
const loadingBar = document.getElementById('loading-bar'); const loadingBar = document.getElementById('loading-bar');
const needsSubscriptionElement = document.getElementById('needs-subscription');
async function removeFile(filePath) { async function removeFile(filePath) {
const updatedFiles = await window.removeFileAPI.removeFile(filePath); const updatedFiles = await window.removeFileAPI.removeFile(filePath);
@@ -165,6 +165,15 @@ window.updateStateAPI.onUpdateState((event, state) => {
syncStatusElement.innerHTML = `⏱️ Synced at ${currentTime.toLocaleTimeString(undefined, options)}. Next sync at ${nextSyncTime.toLocaleTimeString(undefined, options)}.`; syncStatusElement.innerHTML = `⏱️ Synced at ${currentTime.toLocaleTimeString(undefined, options)}. Next sync at ${nextSyncTime.toLocaleTimeString(undefined, options)}.`;
}); });
window.needsSubscriptionAPI.onNeedsSubscription((event, needsSubscription) => {
console.log("needs subscription", needsSubscription);
if (needsSubscription) {
needsSubscriptionElement.style.display = 'block';
} else {
needsSubscriptionElement.style.display = 'none';
}
});
const urlInput = document.getElementById('khoj-host-url'); const urlInput = document.getElementById('khoj-host-url');
(async function() { (async function() {
const url = await window.hostURLAPI.getURL(); const url = await window.hostURLAPI.getURL();