Skip to content

Commit

Permalink
anywhere window stuff fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
nbonamy committed Nov 3, 2024
1 parent 5ec1ecd commit fec6ec2
Show file tree
Hide file tree
Showing 11 changed files with 35 additions and 30 deletions.
2 changes: 1 addition & 1 deletion build/build_number.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
371
383
25 changes: 15 additions & 10 deletions src/automations/anywhere.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default class PromptAnywhere {
constructor() {
}

static initPrompt = async (): Promise<void> => {
static open = async (): Promise<void> => {

// get foremost app
let foremostApp = '';
Expand All @@ -24,6 +24,15 @@ export default class PromptAnywhere {
foremostApp: foremostApp
});
}

static close = async (): Promise<void> => {

// close
await window.closePromptAnywhere();
await window.restoreWindows();
//await window.releaseFocus();

}

static insert = async (app: App, response: string): Promise<void> => {

Expand All @@ -47,26 +56,22 @@ export default class PromptAnywhere {

// done
await window.restoreWindows();
await window.releaseFocus();
//await window.releaseFocus();
return;

} catch (error) {
console.error('Error while testing', error);
}

// done waiting
await window.closeWaitingPanel();
await window.restoreWindows();
await window.releaseFocus();
// done
await this.close()

}

static continueAsChat = async (app: App, chatId: string): Promise<void> => {

// done with this
await window.closePromptAnywhere();
await window.restoreWindows();
await window.releaseFocus();
// done
await this.close();

// now open main
await window.openMainWindow({ queryParams: { chatId: chatId } });
Expand Down
10 changes: 5 additions & 5 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ if (!process.mas) {
// this is going to be called later
const registerShortcuts = () => {
shortcuts.registerShortcuts(app, {
prompt: PromptAnywhere.initPrompt,
prompt: PromptAnywhere.open,
chat: window.openMainWindow,
command: Commander.initCommand,
readaloud: ReadAloud.read,
Expand Down Expand Up @@ -123,7 +123,7 @@ app.whenReady().then(() => {
menu.installMenu(app, {
quit: app.quit,
checkForUpdates: autoUpdater.check,
newPrompt: PromptAnywhere.initPrompt,
newPrompt: PromptAnywhere.open,
newChat: window.openMainWindow,
newScratchpad: window.openScratchPad,
settings: window.openSettingsWindow,
Expand Down Expand Up @@ -430,7 +430,7 @@ ipcMain.on('code-python-run', async (event, payload) => {
})

ipcMain.on('anywhere-prompt', async () => {
await PromptAnywhere.initPrompt();
await PromptAnywhere.open();
});

ipcMain.on('anywhere-insert', async (event, payload) => {
Expand All @@ -441,8 +441,8 @@ ipcMain.on('anywhere-continue-as-chat', async (_, chatId) => {
await PromptAnywhere.continueAsChat(app, chatId);
})

ipcMain.on('anywhere-cancel', async () => {
await window.closePromptAnywhere();
ipcMain.on('anywhere-close', async () => {
await PromptAnywhere.close();
})

ipcMain.on('anywhere-resize', async (_, payload) => {
Expand Down
2 changes: 1 addition & 1 deletion src/main/tray.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export default class {
// add common stuff
return [
...menuItems,
{ label: 'New Prompt', accelerator: shortcuts.shortcutAccelerator(configShortcuts?.prompt), click: PromptAnywhere.initPrompt },
{ label: 'New Prompt', accelerator: shortcuts.shortcutAccelerator(configShortcuts?.prompt), click: PromptAnywhere.open },
{ label: 'New Chat', accelerator: shortcuts.shortcutAccelerator(configShortcuts?.chat), click: window.openMainWindow },
{ label: 'New Scratchpad', accelerator: shortcuts.shortcutAccelerator(configShortcuts?.scratchpad), click: window.openScratchPad },
{ label: 'Run AI Command', accelerator: shortcuts.shortcutAccelerator(configShortcuts?.command), click: Commander.initCommand },
Expand Down
2 changes: 1 addition & 1 deletion src/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ contextBridge.exposeInMainWorld(
prompt: () => { return ipcRenderer.send('anywhere-prompt') },
insert: (text: string): void => { return ipcRenderer.send('anywhere-insert', text) },
continue: (chatid: string): void => { return ipcRenderer.send('anywhere-continue-as-chat', chatid) },
cancel: (): void => { return ipcRenderer.send('anywhere-cancel') },
close: (): void => { return ipcRenderer.send('anywhere-close') },
resize: (deltaX : number, deltaY: number): void => { return ipcRenderer.send('anywhere-resize', { deltaX, deltaY }) },
},
experts: {
Expand Down
2 changes: 1 addition & 1 deletion src/screens/PromptAnywhere.vue
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ const onClose = () => {
document.removeEventListener('keydown', onKeyDown)
// done
window.api.anywhere.cancel()
window.api.anywhere.close()
}
const onStopGeneration = () => {
Expand Down
2 changes: 1 addition & 1 deletion src/screens/Wait.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const hover = ref(false)
const onCancel = () => {
window.api.commands.cancel()
window.api.anywhere.cancel()
window.api.anywhere.close()
}
</script>
Expand Down
2 changes: 1 addition & 1 deletion src/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ declare global {
prompt?(): void
insert?(prompt: string): void
continue?(chatId: string): void
cancel?(): void
close?(): void
resize?(deltaX: number, deltaY: number): void
}
experts?: {
Expand Down
10 changes: 5 additions & 5 deletions tests/screens/prompt.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ beforeAll(() => {
prompt: vi.fn(),
insert: vi.fn(),
continue: vi.fn(),
cancel: vi.fn(),
close: vi.fn(),
},
markdown: {
render: renderMarkdown
Expand Down Expand Up @@ -100,10 +100,10 @@ test('Closes when click on container', async () => {
const wrapper = mount(PromptAnywhere)
wrapper.find('.prompt').trigger('mousedown')
wrapper.find('.container').trigger('mouseup')
expect(window.api.anywhere.cancel).not.toHaveBeenCalled()
expect(window.api.anywhere.close).not.toHaveBeenCalled()
wrapper.find('.container').trigger('mousedown')
wrapper.find('.container').trigger('mouseup')
expect(window.api.anywhere.cancel).toHaveBeenCalled()
expect(window.api.anywhere.close).toHaveBeenCalled()
})

test('Renders response', async () => {
Expand Down Expand Up @@ -144,7 +144,7 @@ test('Closes when click on icon', async () => {
wrapper.vm.response = new Message('assistant', 'This is a response')
await wrapper.vm.$nextTick()
wrapper.find('.close').trigger('click')
expect(window.api.anywhere?.cancel).toHaveBeenCalledWith()
expect(window.api.anywhere.close).toHaveBeenCalledWith()
})

test('Manages conversation', async () => {
Expand Down Expand Up @@ -245,5 +245,5 @@ test('Supports keyboard shortcuts', async () => {
// quit
vi.clearAllMocks()
document.dispatchEvent(new KeyboardEvent('keyup', { key: 'Escape' }));
expect(window.api.anywhere?.cancel).toHaveBeenCalled()
expect(window.api.anywhere.close).toHaveBeenCalled()
})
4 changes: 2 additions & 2 deletions tests/screens/wait.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ window.api = {
cancel: vi.fn()
},
anywhere: {
cancel: vi.fn()
close: vi.fn()
}
}

Expand Down Expand Up @@ -38,5 +38,5 @@ test('Cancels command', () => {
const wrapper = mount(Wait)
wrapper.find('.cancel').trigger('click')
expect(window.api.commands.cancel).toHaveBeenCalled()
expect(window.api.anywhere.cancel).toHaveBeenCalled()
expect(window.api.anywhere.close).toHaveBeenCalled()
})
4 changes: 2 additions & 2 deletions tests/unit/anywhere.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ beforeEach(() => {

test('Prepare prompt', async () => {

await PromptAnywhere.initPrompt()
await PromptAnywhere.open()

expect(window.hideWindows).toHaveBeenCalledOnce()
expect(window.openPromptAnywhere).toHaveBeenCalledOnce()
Expand All @@ -67,6 +67,7 @@ test('Execute Prompt', async () => {

expect(window.closePromptAnywhere).toHaveBeenCalledOnce()
expect(window.restoreWindows).toHaveBeenCalledOnce()
expect(window.releaseFocus).toHaveBeenCalledOnce()

expect(Automator.prototype.pasteText).toHaveBeenCalledWith('Explain this')

Expand All @@ -78,7 +79,6 @@ test('Continue as Chat Prompt', async () => {

expect(window.closePromptAnywhere).toHaveBeenCalledOnce()
expect(window.restoreWindows).toHaveBeenCalledOnce()
expect(window.releaseFocus).toHaveBeenCalledOnce()

expect(window.openMainWindow).toHaveBeenCalledWith({
queryParams: { chatId: '123' }
Expand Down

0 comments on commit fec6ec2

Please sign in to comment.