mirror of
https://github.com/khoaliber/khoj.git
synced 2026-03-07 13:23:15 +00:00
Only render first run setup message once if error or server not running
This commit is contained in:
@@ -638,6 +638,7 @@
|
|||||||
const khojToken = await window.tokenAPI.getToken();
|
const khojToken = await window.tokenAPI.getToken();
|
||||||
const headers = { 'Authorization': `Bearer ${khojToken}` };
|
const headers = { 'Authorization': `Bearer ${khojToken}` };
|
||||||
|
|
||||||
|
let firstRunSetupMessageRendered = false;
|
||||||
let chatBody = document.getElementById("chat-body");
|
let chatBody = document.getElementById("chat-body");
|
||||||
chatBody.innerHTML = "";
|
chatBody.innerHTML = "";
|
||||||
let chatHistoryUrl = `/api/chat/history?client=desktop`;
|
let chatHistoryUrl = `/api/chat/history?client=desktop`;
|
||||||
@@ -650,19 +651,8 @@
|
|||||||
.then(data => {
|
.then(data => {
|
||||||
if (data.detail) {
|
if (data.detail) {
|
||||||
// If the server returns a 500 error with detail, render a setup hint.
|
// If the server returns a 500 error with detail, render a setup hint.
|
||||||
first_run_message = `Hi 👋🏾, to get started:
|
renderFirstRunSetupMessage();
|
||||||
<ol>
|
firstRunSetupMessageRendered = true;
|
||||||
<li>Generate an API token in the <a class='inline-chat-link' href="#" onclick="window.navigateAPI.navigateToWebSettings()">Khoj Web settings</a></li>
|
|
||||||
<li>Paste it into the API Key field in the <a class='inline-chat-link' href="#" onclick="window.navigateAPI.navigateToSettings()">Khoj Desktop settings</a></li>
|
|
||||||
</ol>`
|
|
||||||
.trim()
|
|
||||||
.replace(/(\r\n|\n|\r)/gm, "");
|
|
||||||
|
|
||||||
renderMessage(first_run_message, "khoj", null, null, true);
|
|
||||||
|
|
||||||
// Disable chat input field and update placeholder text
|
|
||||||
document.getElementById("chat-input").setAttribute("disabled", "disabled");
|
|
||||||
document.getElementById("chat-input").setAttribute("placeholder", "Configure Khoj to enable chat");
|
|
||||||
} else if (data.status != "ok") {
|
} else if (data.status != "ok") {
|
||||||
throw new Error(data.message);
|
throw new Error(data.message);
|
||||||
} else {
|
} else {
|
||||||
@@ -697,19 +687,8 @@
|
|||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
// If the server returns a 500 error with detail, render a setup hint.
|
// If the server returns a 500 error with detail, render a setup hint.
|
||||||
first_run_message = `Hi 👋🏾, to get started:
|
if (!firstRunSetupMessageRendered)
|
||||||
<ol>
|
renderFirstRunSetupMessage();
|
||||||
<li>Generate an API token in the <a class='inline-chat-link' href="#" onclick="window.navigateAPI.navigateToWebSettings()">Khoj Web settings</a></li>
|
|
||||||
<li>Paste it into the API Key field in the <a class='inline-chat-link' href="#" onclick="window.navigateAPI.navigateToSettings()">Khoj Desktop settings</a></li>
|
|
||||||
</ol>`
|
|
||||||
.trim()
|
|
||||||
.replace(/(\r\n|\n|\r)/gm, "");
|
|
||||||
|
|
||||||
renderMessage(first_run_message, "khoj", null, null, true);
|
|
||||||
|
|
||||||
// Disable chat input field and update placeholder text
|
|
||||||
document.getElementById("chat-input").setAttribute("disabled", "disabled");
|
|
||||||
document.getElementById("chat-input").setAttribute("placeholder", "Configure Khoj to enable chat");
|
|
||||||
return;
|
return;
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -760,6 +739,22 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function renderFirstRunSetupMessage() {
|
||||||
|
first_run_message = `Hi 👋🏾, to get started:
|
||||||
|
<ol>
|
||||||
|
<li>Generate an API token in the <a class='inline-chat-link' href="#" onclick="window.navigateAPI.navigateToWebSettings()">Khoj Web settings</a></li>
|
||||||
|
<li>Paste it into the API Key field in the <a class='inline-chat-link' href="#" onclick="window.navigateAPI.navigateToSettings()">Khoj Desktop settings</a></li>
|
||||||
|
</ol>`
|
||||||
|
.trim()
|
||||||
|
.replace(/(\r\n|\n|\r)/gm, "");
|
||||||
|
|
||||||
|
renderMessage(first_run_message, "khoj", null, null, true);
|
||||||
|
|
||||||
|
// Disable chat input field and update placeholder text
|
||||||
|
document.getElementById("chat-input").setAttribute("disabled", "disabled");
|
||||||
|
document.getElementById("chat-input").setAttribute("placeholder", "Configure Khoj to enable chat");
|
||||||
|
}
|
||||||
|
|
||||||
function flashStatusInChatInput(message) {
|
function flashStatusInChatInput(message) {
|
||||||
// Get chat input element and original placeholder
|
// Get chat input element and original placeholder
|
||||||
let chatInput = document.getElementById("chat-input");
|
let chatInput = document.getElementById("chat-input");
|
||||||
|
|||||||
@@ -472,7 +472,8 @@ app.whenReady().then(() => {
|
|||||||
});
|
});
|
||||||
ipcMain.handle('deleteAllFiles', deleteAllFiles);
|
ipcMain.handle('deleteAllFiles', deleteAllFiles);
|
||||||
|
|
||||||
createWindow()
|
createWindow();
|
||||||
|
|
||||||
|
|
||||||
app.setAboutPanelOptions({
|
app.setAboutPanelOptions({
|
||||||
applicationName: "Khoj",
|
applicationName: "Khoj",
|
||||||
|
|||||||
Reference in New Issue
Block a user