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/store/RunList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ 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
21 changes: 21 additions & 0 deletions src/app/updateDownload.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,24 @@ it( 'the page follows the update download in a dialog that cannot be dismissed',
} );
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();
} );
1 change: 1 addition & 0 deletions src/common/rendererBridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ export interface RendererBridge {
onToggleMultifurcatingConstraint: ( listener: Listener ) => Unsubscribe;
onUnhandledError: ( listener: Listener ) => Unsubscribe;
onUpdateDownload: ( listener: ( payload: UpdateDownloadPayload ) => void ) => Unsubscribe;
getUpdateDownload: () => Promise<UpdateDownload>;
getPathForFile: ( file: File ) => string;
}

Expand Down
1 change: 1 addition & 0 deletions src/constants/ipc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ 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
10 changes: 10 additions & 0 deletions src/preload-proofs/getUpdateDownload.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"key": "heldUpdateDownload",
"method": "getUpdateDownload",
"args": [],
"channel": "GET_UPDATE_DOWNLOAD",
"result": {
"status": "downloading",
"percent": 42
}
}
4 changes: 4 additions & 0 deletions src/preload/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
FILE_SHOW_IN_FOLDER,
GET_DARK_MODE,
GET_VERSION,
GET_UPDATE_DOWNLOAD,
HOST,
SET_DARK_MODE,
LIGHT_MODE,
Expand Down Expand Up @@ -195,6 +196,9 @@ const rendererBridge = {
onUpdateDownload( listener: ( payload: UpdateDownloadPayload ) => void ) {
return onEvent( UPDATE_DOWNLOAD, listener );
},
getUpdateDownload() {
return ipcRenderer.invoke( GET_UPDATE_DOWNLOAD );
},
getPathForFile( file: File ): string {
return webUtils.getPathForFile( file );
},
Expand Down
4 changes: 4 additions & 0 deletions src/test/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ function withBridgeEvents( next: TestBridge ): TestBridge {
if ( typeof next.getVersion !== 'function' ) {
next.getVersion = () => Promise.resolve( undefined );
}
// The run list seeds the update download when it listens.
if ( typeof next.getUpdateDownload !== 'function' ) {
next.getUpdateDownload = () => Promise.resolve( { status: 'idle' } );
}
// The output panel checks the output name; MobX 6 re-renders it inside the render test when this rejects.
if ( typeof next.checkOutput !== 'function' ) {
next.checkOutput = ( { outputDir, outputName } ) =>
Expand Down
Loading