Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Load the web app for chat, search from the Desktop app #1086

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions src/interface/desktop/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ let titleBarStyle = process.platform === 'win32' ? 'default' : 'hidden';
const {globalShortcut, clipboard} = require('electron'); // global shortcut and clipboard dependencies for shortcut window
const openShortcutWindowKeyBind = 'CommandOrControl+Shift+K'

const createWindow = (tab = 'settings.html') => {
const createWindow = (tab = '') => {
win = new BrowserWindow({
width: 800,
height: 800,
Expand Down Expand Up @@ -494,7 +494,10 @@ const createWindow = (tab = 'settings.html') => {

job.start();

win.loadFile(tab)
const isWebApp = !tab?.endsWith('.html');
const webAppBaseUrl = store.get('hostURL') || KHOJ_URL;
const pageUrl = `${webAppBaseUrl}/${tab}`;
isWebApp ? win.loadURL(pageUrl) : win.loadFile(tab);

if (firstRun === true) {
firstRun = false;
Expand Down Expand Up @@ -660,7 +663,7 @@ app.whenReady().then(() => {
globalShortcut.unregister('Escape');
});
ipcMain.on('continue-conversation-button-clicked', () => {
openWindow('settings.html');
openWindow();
if (shortcutWin && !shortcutWin.isDestroyed()) {
shortcutWin.close();
}
Expand Down Expand Up @@ -721,11 +724,15 @@ function openAboutWindow() {

let tray

openWindow = (page) => {
openWindow = (page = '') => {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow(page);
} else {
win.loadFile(page); win.show();
const isWebApp = !page?.endsWith('.html');
const webAppBaseUrl = store.get('hostURL') || KHOJ_URL;
const pageUrl = isWebApp ? `${webAppBaseUrl}/${page}` : page;
isWebApp ? win.loadURL(pageUrl) : win.loadFile(pageUrl);
win.show();
}
}

Expand All @@ -735,6 +742,8 @@ app.whenReady().then(() => {
tray = new Tray(icon)

const contextMenu = Menu.buildFromTemplate([
{ label: 'Chat', type: 'normal', click: () => { openWindow(); }},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should also add the home page, agents, automations, settings, as well right? Otherwise the links would be broken. I'm not sure if they'll all work either as intended.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These menu tray actions I added were just the main entry points (consistent with previous behavior). Adding all the top level web app pages to the system tray maybe too many items? The web app links all work consistently internally so you can reach the rest of the pages from the chat, search pages

{ label: 'Search', type: 'normal', click: () => { openWindow('search') }},
{ label: 'Configure', type: 'normal', click: () => { openWindow('settings.html') }},
{ type: 'separator' },
{ label: 'About Khoj', type: 'normal', click: () => { openAboutWindow(); } },
Expand Down
Loading