fix(quick-actions): improve Open Repository in Browser error handling

- Add await to shell.openExternal call to ensure proper async handling
- Show toast notification when no remote URL is found for the repository
- Add error handling with toast feedback for any failures
- Update tests to verify toast notifications are shown on error

Fixes issue where the command didn't provide feedback when failing.
This commit is contained in:
Pedram Amini
2026-02-01 23:19:04 -06:00
parent 65af8a23c7
commit 25b6545ab8
2 changed files with 55 additions and 5 deletions

View File

@@ -37,9 +37,10 @@ vi.mock('../../../renderer/contexts/LayerStackContext', () => ({
}),
}));
const mockAddToast = vi.fn();
vi.mock('../../../renderer/contexts/ToastContext', () => ({
useToast: () => ({
addToast: vi.fn(),
addToast: mockAddToast,
}),
}));
@@ -1271,7 +1272,7 @@ describe('QuickActionsModal', () => {
});
});
it('handles git remote URL returning null', async () => {
it('handles git remote URL returning null with toast notification', async () => {
const { gitService } = await import('../../../renderer/services/git');
vi.mocked(gitService.getRemoteBrowserUrl).mockResolvedValueOnce(null);
@@ -1282,10 +1283,41 @@ describe('QuickActionsModal', () => {
await waitFor(() => {
expect(window.maestro.shell.openExternal).not.toHaveBeenCalled();
expect(mockAddToast).toHaveBeenCalledWith({
type: 'error',
title: 'No Remote URL',
message: 'Could not find a remote URL for this repository',
});
expect(props.setQuickActionOpen).toHaveBeenCalledWith(false);
});
});
it('handles error when opening repository in browser', async () => {
const { gitService } = await import('../../../renderer/services/git');
const consoleSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
vi.mocked(gitService.getRemoteBrowserUrl).mockRejectedValueOnce(new Error('Network error'));
const props = createDefaultProps();
render(<QuickActionsModal {...props} />);
fireEvent.click(screen.getByText('Open Repository in Browser'));
await waitFor(() => {
expect(consoleSpy).toHaveBeenCalledWith(
'Failed to open repository in browser:',
expect.any(Error)
);
expect(mockAddToast).toHaveBeenCalledWith({
type: 'error',
title: 'Error',
message: 'Network error',
});
expect(props.setQuickActionOpen).toHaveBeenCalledWith(false);
});
consoleSpy.mockRestore();
});
it('sorts actions alphabetically', () => {
const props = createDefaultProps();
render(<QuickActionsModal {...props} />);

View File

@@ -777,9 +777,27 @@ export function QuickActionsModal(props: QuickActionsModalProps) {
activeSession.inputMode === 'terminal'
? activeSession.shellCwd || activeSession.cwd
: activeSession.cwd;
const browserUrl = await gitService.getRemoteBrowserUrl(cwd);
if (browserUrl) {
window.maestro.shell.openExternal(browserUrl);
try {
const browserUrl = await gitService.getRemoteBrowserUrl(cwd);
if (browserUrl) {
await window.maestro.shell.openExternal(browserUrl);
} else {
addToast({
type: 'error',
title: 'No Remote URL',
message: 'Could not find a remote URL for this repository',
});
}
} catch (error) {
console.error('Failed to open repository in browser:', error);
addToast({
type: 'error',
title: 'Error',
message:
error instanceof Error
? error.message
: 'Failed to open repository in browser',
});
}
setQuickActionOpen(false);
},