Skip to content

Commit

Permalink
Warn lack of API credential when creating assistant
Browse files Browse the repository at this point in the history
  • Loading branch information
zcbenz committed Jul 30, 2023
1 parent eb90eb1 commit 6cfe7cc
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
10 changes: 10 additions & 0 deletions src/controller/window-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import gui from 'gui';
import Assistant from '../model/assistant';
import BaseWindow from '../view/base-window';
import WindowStore, {WindowStoreData} from '../model/window-store';
import alert from '../util/alert';
import apiManager from '../controller/api-manager';
import assistantManager from './assistant-manager';
import {collectGarbage} from './gc-center';
import {ConfigStoreItem} from '../model/config-store';
Expand Down Expand Up @@ -77,6 +79,14 @@ export class WindowManager extends ConfigStoreItem {
return this.#namedWindows.showWindow(name);
}

showNewAssistantWindowOrError() {
const hasCredential = apiManager.getCredentials().length > 0;
if (hasCredential)
this.showNamedWindow('newAssistant');
else
alert('Can not create new assistant before adding API credentials.');
}

getCurrentWindow() {
return this.windows.find(w => w.window.isActive());
}
Expand Down
2 changes: 1 addition & 1 deletion src/view/base-menu-bar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ export default class BaseMenuBar extends SignalsOwner {
},
{
label: 'New Assistant...',
onClick: () => windowManager.showNamedWindow('newAssistant'),
onClick: () => windowManager.showNewAssistantWindowOrError(),
},
{ type: 'separator' },
],
Expand Down
2 changes: 1 addition & 1 deletion src/view/dashboard-window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export default class DashboardWindow extends BaseWindow {

this.#addButton = new IconButton('add');
this.#addButton.view.setTooltip('Add new assistant');
this.#addButton.onClick = () => windowManager.showNamedWindow('newAssistant');
this.#addButton.onClick = () => windowManager.showNewAssistantWindowOrError();
this.#sidebar.view.addChildView(this.#addButton.view);

// Create views for assistants.
Expand Down

0 comments on commit 6cfe7cc

Please sign in to comment.