Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions src/app/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import CitationModal from './CitationModal';
import ErrorBoundary from './components/ErrorBoundary';
import ErrorDialog from './components/ErrorDialog';
import ModifiedDialog from './components/ModifiedDialog';
import UpdateDownloadDialog from './components/UpdateDownloadDialog';

const VerticalHeading = styled( Typography )( () => ( {
writingMode: 'vertical-rl',
Expand Down Expand Up @@ -522,6 +523,7 @@ const App = (): React.JSX.Element => {
</Modal>
)
: null}
<UpdateDownloadDialog download={store.updateDownload} />
<ErrorDialog error={store.error} title={store.errorTitle} onClose={store.clearError} />
</Box>
</React.Fragment>
Expand Down
54 changes: 54 additions & 0 deletions src/app/components/UpdateDownloadDialog.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import React from 'react';
import Dialog from '@mui/material/Dialog';
import DialogTitle from '@mui/material/DialogTitle';
import DialogContent from '@mui/material/DialogContent';
import LinearProgress from '@mui/material/LinearProgress';
import Typography from '@mui/material/Typography';
import type { UpdateDownload } from '../../common/rendererBridge';

export interface UpdateDownloadDialogProps {
download: UpdateDownload;
}

function dialogCopy( download: UpdateDownload ): { percent?: number; text: string; detail: string } {
switch ( download.status ) {
case 'connecting':
return { text: 'Starting…', detail: 'Connecting to the update server…' };
case 'downloading':
case 'restarted':
if ( download.percent < 100 ) {
return {
percent: download.percent,
text: `${Math.round( download.percent )}%`,
detail: download.status === 'restarted'
? 'Retrying with the full download…'
: 'RAxML-GUI will quit and install when the download finishes.',
};
}
break;
default:
}
return { percent: 100, text: '100%', detail: 'Download complete. Preparing to install…' };
}

export default function UpdateDownloadDialog( { download }: UpdateDownloadDialogProps ): React.JSX.Element | null {
if ( download.status === 'idle' ) {
return null;
}
const { percent, text, detail } = dialogCopy( download );
return (
<Dialog open={true} maxWidth="xs" fullWidth disableEscapeKeyDown aria-labelledby="update-download-title">
<DialogTitle id="update-download-title">Downloading update</DialogTitle>
<DialogContent>
<LinearProgress
variant={percent === undefined
? 'indeterminate'
: 'determinate'}
value={percent}
/>
<Typography variant="body2" sx={{ mt: 1 }}>{text}</Typography>
<Typography variant="body2" color="text.secondary">{detail}</Typography>
</DialogContent>
</Dialog>
);
}
12 changes: 12 additions & 0 deletions src/app/store/RunList.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { observable, computed, action, makeObservable } from 'mobx';
import type { StateReport } from '../../main/getActiveState';
import type { UpdateDownload } from '../../common/rendererBridge';
import Run from './Run';
import AppStore from './AppStore';
import { runEvents } from './StoreBase';
Expand All @@ -23,6 +24,8 @@ class RunList extends AppStore {
deleteActive: action,
onError: action,
onUnhandledError: action,
updateDownload: observable,
onUpdateDownload: action,
onBackboneConstraint: action,
onMultifurcatingConstraint: action,
} );
Expand Down Expand Up @@ -77,6 +80,12 @@ class RunList extends AppStore {
this.error = error;
};

updateDownload: UpdateDownload = { status: 'idle' };

onUpdateDownload = ( download: UpdateDownload ): void => {
this.updateDownload = download;
};

onBackboneConstraint = (): void => {
this.activeRun.useBackboneConstraint =
!this.activeRun.useBackboneConstraint;
Expand All @@ -89,6 +98,9 @@ class RunList extends AppStore {

listen = (): void => {
this.subscribe( runEvents.onUnhandledError, this.onUnhandledError );
this.subscribe( runEvents.onUpdateDownload, this.onUpdateDownload );
// A reloaded or reopened page starts mid-download; seed from main's held state.
window.rendererBridge.getUpdateDownload().then( this.onUpdateDownload );
this.subscribe( runEvents.onAddRun, this.addRun );
this.subscribe( runEvents.onRemoveRun, this.deleteActive );
this.subscribe( runEvents.onToggleBackboneConstraint, this.onBackboneConstraint );
Expand Down
1 change: 1 addition & 0 deletions src/app/store/StoreBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export const runEvents = {
onToggleBackboneConstraint: 'onToggleBackboneConstraint',
onToggleMultifurcatingConstraint: 'onToggleMultifurcatingConstraint',
onUnhandledError: 'onUnhandledError',
onUpdateDownload: 'onUpdateDownload',
} as const;

export default class StoreBase {
Expand Down
88 changes: 88 additions & 0 deletions src/app/updateDownload.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import { expect, it } from 'vitest';
import { act } from 'react';
import { createRoot } from 'react-dom/client';
import Page from './index';
import store from './store';
import { installBridge } from '../test/setup';
import type { UpdateDownloadPayload } from '../common/rendererBridge';

function title() {
return document.getElementById( 'update-download-title' )?.textContent;
}

it( 'the page follows the update download in a dialog that cannot be dismissed', () => {
let hear: ( payload: UpdateDownloadPayload ) => void;
installBridge( {
onUpdateDownload( listener ) {
hear = listener;
return () => {};
},
} );
store.listen();

const div = document.createElement( 'div' );
document.body.appendChild( div );
const root = createRoot( div );
act( () => {
root.render( <Page /> );
} );
expect( title() ).toBeUndefined();

const rows: [UpdateDownloadPayload, string, string][] = [
[{ id: 'update', status: 'connecting' }, 'Starting…', 'Connecting to the update server…'],
[
{ id: 'update', status: 'downloading', percent: 42 },
'42%',
'RAxML-GUI will quit and install when the download finishes.',
],
[{ id: 'update', status: 'restarted', percent: 10 }, '10%', 'Retrying with the full download…'],
[{ id: 'update', status: 'done' }, '100%', 'Download complete. Preparing to install…'],
];
for ( const [payload, percent, status] of rows ) {
act( () => {
hear( payload );
} );
expect( title() ).toBe( 'Downloading update' );
const dialog = document.querySelector( '[role="dialog"]' );
expect( dialog.textContent ).toContain( percent );
expect( dialog.textContent ).toContain( status );
expect( dialog.querySelector( 'button' ) ).toBeNull();
}

act( () => {
document.querySelector( '[role="dialog"]' ).dispatchEvent( new KeyboardEvent( 'keydown', { key: 'Escape', bubbles: true } ) );
document.querySelector<HTMLElement>( '.MuiBackdrop-root' ).click();
} );
expect( title() ).toBe( 'Downloading update' );

act( () => {
hear( { id: 'update', status: 'idle' } );
} );
expect( title() ).toBeUndefined();

act( () => {
root.unmount();
} );
div.remove();
} );

it( 'a page that starts mid-download shows the dialog with no event pushed', async () => {
installBridge( {
getUpdateDownload: () => Promise.resolve( { status: 'downloading', percent: 37 } ),
} );
store.listen();

const div = document.createElement( 'div' );
document.body.appendChild( div );
const root = createRoot( div );
await act( async () => {
root.render( <Page /> );
} );
expect( title() ).toBe( 'Downloading update' );
expect( document.querySelector( '[role="dialog"]' ).textContent ).toContain( '37%' );

act( () => {
root.unmount();
} );
div.remove();
} );
12 changes: 12 additions & 0 deletions src/common/rendererBridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ export interface HostInfo {
cpuModel: string;
}

export type UpdateDownload =
| { status: 'idle' }
| { status: 'connecting' }
| { status: 'downloading'; percent: number }
// a differential download fell back to a full one, so the percent dropped
| { status: 'restarted'; percent: number }
| { status: 'done' };

export type UpdateDownloadPayload = UpdateDownload & { id: string };

// An event payload the page does not read yet; the leaf that reads it tightens it.
type Listener = ( payload: unknown ) => void;
type Unsubscribe = () => void;
Expand Down Expand Up @@ -68,6 +78,8 @@ export interface RendererBridge {
onToggleBackboneConstraint: ( listener: Listener ) => Unsubscribe;
onToggleMultifurcatingConstraint: ( listener: Listener ) => Unsubscribe;
onUnhandledError: ( listener: Listener ) => Unsubscribe;
onUpdateDownload: ( listener: ( payload: UpdateDownloadPayload ) => void ) => Unsubscribe;
getUpdateDownload: () => Promise<UpdateDownload>;
getPathForFile: ( file: File ) => string;
}

Expand Down
2 changes: 2 additions & 0 deletions src/constants/ipc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ export const ALIGNMENT_MODEL_SELECTION_SUCCESS =
export const ALIGNMENT_MODEL_SELECTION_FAILURE =
'ALIGNMENT_MODEL_SELECTION_FAILURE' as const;
export const UNHANDLED_ERROR = 'UNHANDLED_ERROR' as const;
export const UPDATE_DOWNLOAD = 'UPDATE_DOWNLOAD' as const;
export const GET_UPDATE_DOWNLOAD = 'GET_UPDATE_DOWNLOAD' as const;
export const TOGGLE_BACKBONE_CONSTRAINT = 'TOGGLE_BACKBONE_CONSTRAINT' as const;
export const TOGGLE_MULTIFURCATING_CONSTRAINT =
'TOGGLE_MULTIFURCATING_CONSTRAINT' as const;
Expand Down
2 changes: 2 additions & 0 deletions src/main/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { selectAstralFile } from './selectAstralFile';
import { selectOutputDir } from './selectOutputDir';
import { checkOutput } from './checkOutput';
import { debugInfo } from './debugInfo';
import { getUpdateDownload } from './updates';
import { selectPartitionFile } from './selectPartitionFile';
import { selectTree } from './selectTree';
import { appStore } from './appStore';
Expand Down Expand Up @@ -71,6 +72,7 @@ ipcMain.on( ipc.HOST, ( event: IpcMainEvent ) => {
};
} );
ipcMain.handle( ipc.GET_VERSION, (): string => app.getVersion() );
ipcMain.handle( ipc.GET_UPDATE_DOWNLOAD, getUpdateDownload );
ipcMain.handle( ipc.GET_DARK_MODE, (): boolean => Boolean( appStore.get( 'darkMode' ) ) );
ipcMain.handle( ipc.SET_DARK_MODE, ( _event: IpcMainInvokeEvent, value: boolean ): void => {
appStore.set( 'darkMode', value );
Expand Down
6 changes: 4 additions & 2 deletions src/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import './api';
import MenuBuilder from './menu';
import { is } from '../common/utils';
import { pageWindowPreferences } from './pageWindowPreferences';
import { checkForUpdates, listenForUpdates } from './updates';
import { applyUpdateDownloadBar, checkForUpdates, listenForUpdates } from './updates';
// TODO: Have removed electron-debug dependency, because it used remote module. Maybe we need some alternative.
//-------------------------------------------------------------------
// From https://github.com/iffy/electron-updater-example/blob/master/main.js
Expand All @@ -34,7 +34,7 @@ const isE2eMode = process.env.RAXMLGUI_E2E === '1';
// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the JavaScript object is garbage collected.
let mainWindow: BrowserWindow | null = null;
listenForUpdates( autoUpdater, dialog );
listenForUpdates( autoUpdater, dialog, () => mainWindow );
/**
* Add event listeners...
*/
Expand Down Expand Up @@ -62,6 +62,8 @@ function initialize(): void {
// Create the browser window.
const win = new BrowserWindow( mainWindowOptions );
mainWindow = win;
// a macOS window reopened mid-download gets the bar back
applyUpdateDownloadBar( win );
// and load the index.html of the app.
let startUrl = process.env.ELECTRON_RENDERER_URL ||
url.format( {
Expand Down
Loading
Loading