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
10 changes: 5 additions & 5 deletions src/app/AlignmentCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ interface CardAlignment {
loading: boolean;
showPartition: boolean;
partition: { isComplete: boolean };
substitutionModel: OptionSelectOptionLike;
substitutionModel: OptionSelectOptionLike<string>;
multistateNumber: OptionTextFieldOptionLike;
ngStationaryFrequencies: OptionSelectOptionLike;
ngInvariantSites: OptionSelectOptionLike;
ngRateHeterogeneity: OptionSelectOptionLike;
ngAscertainmentBias: OptionSelectOptionLike;
ngStationaryFrequencies: OptionSelectOptionLike<string>;
ngInvariantSites: OptionSelectOptionLike<string>;
ngRateHeterogeneity: OptionSelectOptionLike<string>;
ngAscertainmentBias: OptionSelectOptionLike<string>;
modelExtra: CardModelExtra | null;
modelTestCanRun: boolean;
modeltestLoading: boolean;
Expand Down
24 changes: 12 additions & 12 deletions src/app/Model.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,25 @@ import type { OptionCheckOptionLike } from './components/OptionCheck';
interface ModelRun {
usesModeltestNg: boolean;
usesAstral: boolean;
analysis: OptionSelectOptionLike;
numRuns: OptionSelectOptionLike;
numRepetitions: OptionSelectOptionLike;
numRepetitionsNg: OptionSelectOptionLike;
analysis: OptionSelectOptionLike<string>;
numRuns: OptionSelectOptionLike<number>;
numRepetitions: OptionSelectOptionLike<number | string>;
numRepetitionsNg: OptionSelectOptionLike<number | string>;
branchLength: OptionCheckOptionLike;
sHlike: OptionCheckOptionLike;
combinedOutput: OptionCheckOptionLike;
startingTree: OptionSelectOptionLike;
outGroup: OptionSelectOptionLike;
startingTree: OptionSelectOptionLike<string>;
outGroup: OptionSelectOptionLike<string[]>;
haveRandomSeed: boolean;
randomSeed: number;
setRandomSeed: ( value: string ) => void;
substitutionMatrix: OptionSelectOptionLike;
substitutionRate: OptionSelectOptionLike;
substitutionI: OptionSelectOptionLike;
substitutionAscertainment: OptionSelectOptionLike;
multistateModel: OptionSelectOptionLike;
substitutionMatrix: OptionSelectOptionLike<string>;
substitutionRate: OptionSelectOptionLike<string>;
substitutionI: OptionSelectOptionLike<string>;
substitutionAscertainment: OptionSelectOptionLike<string>;
multistateModel: OptionSelectOptionLike<string>;
estimatedFrequencies: OptionCheckOptionLike;
baseFrequencies: OptionSelectOptionLike;
baseFrequencies: OptionSelectOptionLike<string>;
}

export interface ModelProps {
Expand Down
6 changes: 3 additions & 3 deletions src/app/PartitionEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ interface PartPositionOption extends Omit<OptionTextFieldOptionLike, 'setValue'>

interface EditorPartition {
partToAdd: {
type: OptionSelectOptionLike;
aaType: OptionSelectOptionLike;
type: OptionSelectOptionLike<string>;
aaType: OptionSelectOptionLike<string>;
name: OptionTextFieldOptionLike;
start: PartPositionOption;
end: PartPositionOption;
codon: OptionSelectOptionLike;
codon: OptionSelectOptionLike<string>;
};
progress: number;
currentEndValue: number;
Expand Down
4 changes: 2 additions & 2 deletions src/app/Raxml.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import { FormHelperText } from '@mui/material';

interface RaxmlRun {
command: string;
binary: OptionSelectOptionLike;
numThreads: OptionSelectOptionLike;
binary: OptionSelectOptionLike<string>;
numThreads: OptionSelectOptionLike<number>;
modelTestIsRunningOnAlignment: boolean;
cancelModeltestOnAlignment: () => void;
running: boolean;
Expand Down
21 changes: 11 additions & 10 deletions src/app/components/OptionSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,27 @@ export interface OptionSelectChoice {
title: string | number;
}

export interface OptionSelectOptionLike {
export interface OptionSelectOptionLike<Value extends string | number | readonly string[]> {
notAvailable?: boolean;
title: string;
hoverInfo: string;
options: readonly OptionSelectChoice[];
value: string | number | readonly string[];
setValue: ( value: unknown ) => void;
value: Value;
setValue: ( value: Value ) => void;
multiple?: boolean;
error: unknown;
placeholder?: string;
}

export interface OptionSelectProps {
option: OptionSelectOptionLike;
export interface OptionSelectProps<Value extends string | number | readonly string[]> {
option: OptionSelectOptionLike<Value>;
sx?: SxProps<Theme>;
}

const OptionSelect = observer( function OptionSelect( {
function OptionSelect<Value extends string | number | readonly string[]>( {
option,
sx,
}: OptionSelectProps ) {
}: OptionSelectProps<Value> ) {
if ( option.notAvailable || option.options.length === 0 ) {
return null;
}
Expand Down Expand Up @@ -59,7 +59,8 @@ const OptionSelect = observer( function OptionSelect( {
<FormControl variant="standard" sx={sx} title={option.hoverInfo}>
<Select
value={option.value}
onChange={( e ) => option.setValue( e.target.value )}
// MUI's change event types the value as `Value | string`.
onChange={( e ) => option.setValue( e.target.value as Value )}
inputProps={{
name: option.title,
id: option.title,
Expand All @@ -76,6 +77,6 @@ const OptionSelect = observer( function OptionSelect( {
<FormHelperText>{option.title}</FormHelperText>
</FormControl>
);
} );
}

export default OptionSelect;
export default observer<typeof OptionSelect>( OptionSelect );
9 changes: 5 additions & 4 deletions src/app/store/Option.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ interface OptionSettings {
helperText?: string;
}

/** Reactive option with optional validation */
class Option<Value = unknown, Owner = unknown> {
/** Reactive option with optional validation. `Input` is what `setValue` takes before the schema casts it. */
class Option<Value = unknown, Owner = unknown, Input = Value> {
run: Owner;
defaultValue: Value;
title: string;
Expand Down Expand Up @@ -49,12 +49,13 @@ class Option<Value = unknown, Owner = unknown> {
this.helperText = helperText;
this.value = defaultValue;
}
setValue( value: Value ): void {
setValue( value: Input ): void {
const isValid = this.schema.isValidSync( value );
if ( !this.allowOnlyValidChange || isValid ) {
// An invalid input is kept as typed, so `value` can hold an uncast `Input` despite its type.
this.value = isValid
? this.schema.cast( value )
: value;
: value as unknown as Value;
}
}
reset(): void {
Expand Down
4 changes: 2 additions & 2 deletions src/app/store/Part.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,10 +297,10 @@ describe( 'part options', () => {
const { start } = makeAlignment().partition.partToAdd;
expect( start.notAvailable ).toBe( false );
expect( start.disabled ).toBe( true );
// @ts-expect-error A numeric string on purpose: the schema casts it to a number.
// The schema casts a numeric string to a number.
start.setValue( '7' );
expect( start.value ).toBe( 7 );
// @ts-expect-error A non-numeric string on purpose: an invalid value is stored as given.
// An invalid value is stored as given.
start.setValue( 'abc' );
expect( start.value ).toBe( 'abc' );
} );
Expand Down
7 changes: 4 additions & 3 deletions src/app/store/PartOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ interface PartLike {
codon: { value: string };
}

class PartBase<Value> extends Option<Value> {
class PartBase<Value, Input = Value> extends Option<Value, unknown, Input> {
part: PartLike;
constructor(
part: PartLike,
Expand Down Expand Up @@ -126,7 +126,8 @@ class PartName extends PartBase<string> {
return false;
}
}
class PartStart extends PartBase<number> {
// OptionTextField hands start and end the field's text; the number schema casts it.
class PartStart extends PartBase<number, number | string> {
disabled: boolean;
constructor( part: PartLike, value = 1 ) {
super( part, value, 'from', 'Start position for this part', '', {
Expand All @@ -143,7 +144,7 @@ class PartStart extends PartBase<number> {
}
}

class PartEnd extends PartBase<number> {
class PartEnd extends PartBase<number, number | string> {
constructor( part: PartLike, value = 1 ) {
super(
part,
Expand Down
4 changes: 2 additions & 2 deletions src/app/store/RunList.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { observable, computed, action, makeObservable } from 'mobx';
import type { StateReport } from '../../main/getActiveState';
import type { UpdateDownload } from '../../common/rendererBridge';
import type { UnhandledErrorPayload, UpdateDownload } from '../../common/rendererBridge';
import Run from './Run';
import AppStore from './AppStore';
import { runEvents } from './StoreBase';
Expand Down Expand Up @@ -74,7 +74,7 @@ class RunList extends AppStore {
this.error = error;
};

onUnhandledError = ( { title, error }: { title: string; error: unknown } ): void => {
onUnhandledError = ( { title, error }: UnhandledErrorPayload ): void => {
console.log( 'Unhandled error:', error );
this.errorTitle = title;
this.error = error;
Expand Down
3 changes: 2 additions & 1 deletion src/app/unhandledError.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import { createRoot } from 'react-dom/client';
import Page from './index';
import store from './store';
import { installBridge } from '../test/setup';
import type { UnhandledErrorPayload } from '../common/rendererBridge';

it( 'the page shows an unhandled error title and error', () => {
let hear: ( payload: unknown ) => void;
let hear: ( payload: UnhandledErrorPayload ) => void;
installBridge( {
onUnhandledError( listener ) {
hear = listener;
Expand Down
8 changes: 7 additions & 1 deletion src/common/rendererBridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ export type UpdateDownload =

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

// `error` arrives as main's `serializeError` output.
export interface UnhandledErrorPayload {
title: string;
error: unknown;
}

// 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 @@ -77,7 +83,7 @@ export interface RendererBridge {
onDarkMode: ( listener: () => void ) => Unsubscribe;
onToggleBackboneConstraint: ( listener: Listener ) => Unsubscribe;
onToggleMultifurcatingConstraint: ( listener: Listener ) => Unsubscribe;
onUnhandledError: ( listener: Listener ) => Unsubscribe;
onUnhandledError: ( listener: ( payload: UnhandledErrorPayload ) => void ) => Unsubscribe;
onUpdateDownload: ( listener: ( payload: UpdateDownloadPayload ) => void ) => Unsubscribe;
getUpdateDownload: () => Promise<UpdateDownload>;
getPathForFile: ( file: File ) => string;
Expand Down
3 changes: 2 additions & 1 deletion src/main/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { serializeError } from 'serialize-error';
import * as Sentry from '@sentry/electron/main';
import * as ipc from '../constants/ipc';
import io from '../common/io';
import type { UnhandledErrorPayload } from '../common/rendererBridge';
import { parseAlignment } from './parseAlignment';
import { selectAlignment } from './selectAlignment';
import { selectAstralFile } from './selectAstralFile';
Expand Down Expand Up @@ -48,7 +49,7 @@ function handleError( title: string, error: unknown ): void {
win.webContents.send( ipc.UNHANDLED_ERROR, {
title,
error: serializeError( error ),
} );
} satisfies UnhandledErrorPayload );
}
}
process.on( 'uncaughtException', ( error: Error ) => {
Expand Down
4 changes: 2 additions & 2 deletions src/main/astral.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import path from 'path';
import type { IpcMainEvent } from 'electron';
import type { IpcMainInvokeEvent } from 'electron';
import * as ipc from '../constants/ipc';
import { quote } from '../common/utils';
import {
Expand Down Expand Up @@ -28,7 +28,7 @@ export interface AstralSuccessPayload {
}

export async function runAstral(
event: IpcMainEvent,
event: IpcMainInvokeEvent,
payload: AstralPayload,
): Promise<void> {
const { id, binaryName, args } = payload;
Expand Down
4 changes: 2 additions & 2 deletions src/main/modelSelection.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { afterEach, expect, it, vi } from 'vitest';
import type { IpcMainEvent } from 'electron';
import type { IpcMainInvokeEvent } from 'electron';

import { runModelSelection } from './modelSelection';
import { ALIGNMENT_MODEL_SELECTION_FAILURE } from '../constants/ipc';
Expand All @@ -18,7 +18,7 @@ afterEach( () => {
it( 'a failed modeltest-ng run reports its own command', async () => {
vi.spyOn( console, 'log' ).mockImplementation( () => {} );
vi.spyOn( console, 'error' ).mockImplementation( () => {} );
await runModelSelection( {} as IpcMainEvent, {
await runModelSelection( {} as IpcMainInvokeEvent, {
id: 'a1',
filePath: '/data/primates.fasta',
outputDir: '/nonexistent-out',
Expand Down
4 changes: 2 additions & 2 deletions src/main/modelSelection.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import path from 'path';
import _fs from 'fs';
import parsePath from 'parse-filepath';
import type { IpcMainEvent } from 'electron';
import type { IpcMainInvokeEvent } from 'electron';
import * as ipc from '../constants/ipc';
import { quote } from '../common/utils';
import {
Expand Down Expand Up @@ -48,7 +48,7 @@ export interface ModelSelectionFailurePayload {
}

export async function runModelSelection(
event: IpcMainEvent,
event: IpcMainInvokeEvent,
payload: ModelSelectionPayload,
): Promise<void> {
const { id, filePath, outputDir, dataType, numThreads, binaryName } = payload;
Expand Down
4 changes: 2 additions & 2 deletions src/main/processHelpers.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect, it, vi } from 'vitest';
import path from 'path';
import type { IpcMainEvent } from 'electron';
import type { IpcMainInvokeEvent } from 'electron';

vi.mock( 'electron', () => ( {
app: { isPackaged: false, getAppPath: () => '' },
Expand All @@ -25,7 +25,7 @@ const eventWith = ( destroyed: boolean ) => {
}
} ),
};
return { event: { sender } as unknown as IpcMainEvent, sender };
return { event: { sender } as unknown as IpcMainInvokeEvent, sender };
};

it( 'send delivers to a live window', () => {
Expand Down
6 changes: 3 additions & 3 deletions src/main/processHelpers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { app, Notification } from 'electron';
import type { IpcMainEvent } from 'electron';
import type { IpcMainInvokeEvent } from 'electron';
import path from 'path';
import childProcess from 'child_process';
import type { ChildProcess } from 'child_process';
Expand Down Expand Up @@ -60,7 +60,7 @@ const binParentDir = app.isPackaged
export const binaryDir: string = path.join( getStaticDir(), 'bin', binParentDir );

export function send(
event: IpcMainEvent,
event: IpcMainInvokeEvent,
channel: string,
data: { error?: unknown; [key: string]: unknown },
): void {
Expand Down Expand Up @@ -89,7 +89,7 @@ export function spawnProcess(

export async function runProcess(
id: TrackedId,
event: IpcMainEvent,
event: IpcMainInvokeEvent,
binaryDir: string,
binaryName: string,
args: string[],
Expand Down
4 changes: 2 additions & 2 deletions src/main/startRun.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import util from 'util';
import _fs from 'fs';
import childProcess from 'child_process';
import type { ExecOptions } from 'child_process';
import type { IpcMainEvent } from 'electron';
import type { IpcMainInvokeEvent } from 'electron';
import * as Sentry from '@sentry/electron/main';
import * as ipc from '../constants/ipc';
import { is } from '../common/utils';
Expand Down Expand Up @@ -75,7 +75,7 @@ async function combineOutput( outputDir: string, outputFilename: string ): Promi
console.log( stdout, stderr );
}

export async function startRun( event: IpcMainEvent, { id, args, binaryName, outputDir, outputFilename, outputName, combinedOutput, usesRaxmlNg, usesModeltestNg, inputPath }: StartRunPayload ): Promise<void> {
export async function startRun( event: IpcMainInvokeEvent, { id, args, binaryName, outputDir, outputFilename, outputName, combinedOutput, usesRaxmlNg, usesModeltestNg, inputPath }: StartRunPayload ): Promise<void> {
const token = beginRun( id );
stopRun( id );
const reportError = ( error: unknown ): void => {
Expand Down
Loading
Loading