Skip to content

Commit

Permalink
TypeScript rewrite: Exports window (#1016)
Browse files Browse the repository at this point in the history
  • Loading branch information
karaggeorge committed Aug 26, 2021
1 parent 448e7f0 commit 777d780
Show file tree
Hide file tree
Showing 60 changed files with 1,063 additions and 2,701 deletions.
4 changes: 3 additions & 1 deletion main/common/flags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ import Store from 'electron-store';

export const flags = new Store<{
backgroundEditorConversion: boolean;
editorDragTooltip: boolean;
}>({
name: 'flags',
defaults: {
backgroundEditorConversion: false
backgroundEditorConversion: false,
editorDragTooltip: false
}
});
7 changes: 3 additions & 4 deletions main/common/types/conversion-options.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {App, Format} from './base';

export type CreateConversionOptions = {
export type CreateExportOptions = {
filePath: string;
options: ConversionOptions;
conversionOptions: ConversionOptions;
format: Format;
plugins: {
share: {
Expand All @@ -29,8 +29,7 @@ export type ConversionOptions = {
editService?: EditServiceInfo;
};

export enum ConversionStatus {
idle = 'idle',
export enum ExportStatus {
inProgress = 'inProgress',
failed = 'failed',
canceled = 'canceled',
Expand Down
75 changes: 51 additions & 24 deletions main/common/types/remote-states.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,26 @@
import {App, Format} from './base';
import {ConversionStatus} from './conversion-options';
import {ExportStatus} from './conversion-options';

// eslint-disable-next-line @typescript-eslint/ban-types
export type RemoteState<State = any, Actions extends Record<string, (...args: any[]) => any> = {}> = {
actions: Actions;
state: State;
};

export type RemoteStateHook<Base extends RemoteState> = Base extends RemoteState<infer State, infer Actions> ? (
Actions & {
state: State;
isLoading: boolean;
refreshState: () => void;
}
) : never;

export type RemoteStateHandler<Base extends RemoteState> = Base extends RemoteState<infer State, infer Actions> ? (sendUpdate: (state: State, id?: string) => void) => {
actions: {
[Key in keyof Actions]: Actions[Key] extends (...args: any[]) => any ? (id: string, ...args: Parameters<Actions[Key]>) => void : never
};
getState: (id: string) => State | undefined;
} : never;

export interface ExportOptionsPlugin {
title: string;
Expand Down Expand Up @@ -29,34 +50,40 @@ export type ExportOptions = {
fpsHistory: {[key in Format]: number};
};

export type EditorOptionsRemoteState = (sendUpdate: (state: ExportOptions) => void) => {
actions: {
updatePluginUsage: ({format, plugin}: {
format: Format;
plugin: string;
}) => void;
updateFpsUsage: ({format, fps}: {
format: Format;
fps: number;
}) => void;
};
getState: () => ExportOptions;
};
export type EditorOptionsRemoteState = RemoteState<ExportOptions, {
updatePluginUsage: ({format, plugin}: {
format: Format;
plugin: string;
}) => void;
updateFpsUsage: ({format, fps}: {
format: Format;
fps: number;
}) => void;
}>;

export interface ConversionState {
export interface ExportState {
id: string;
title: string;
description: string;
message: string;
progress?: number;
size?: string;
status: ConversionStatus;
image?: string;
filePath?: string;
error?: Error;
fileSize?: string;
status: ExportStatus;
canCopy: boolean;
disableOutputActions: boolean;
canPreviewExport: boolean;
titleWithFormat: string;
}

export type ConversionRemoteState = (sendUpdate: (state: ConversionState, id: string) => void) => {
actions: {
copy: (_?: undefined, conversionId?: string) => void;
cancel: (_?: undefined, conversionId?: string) => void;
};
getState: (conversionId: string) => ConversionState | undefined;
};
export type ExportsRemoteState = RemoteState<ExportState, {
copy: () => void;
cancel: () => void;
retry: () => void;
openInEditor: () => void;
showInFolder: () => void;
}>;

export type ExportsListRemoteState = RemoteState<string[]>;

0 comments on commit 777d780

Please sign in to comment.