Skip to content

Commit 777d780

Browse files
authored
TypeScript rewrite: Exports window (#1016)
1 parent 448e7f0 commit 777d780

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+1063
-2701
lines changed

main/common/flags.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@ import Store from 'electron-store';
22

33
export const flags = new Store<{
44
backgroundEditorConversion: boolean;
5+
editorDragTooltip: boolean;
56
}>({
67
name: 'flags',
78
defaults: {
8-
backgroundEditorConversion: false
9+
backgroundEditorConversion: false,
10+
editorDragTooltip: false
911
}
1012
});

main/common/types/conversion-options.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import {App, Format} from './base';
22

3-
export type CreateConversionOptions = {
3+
export type CreateExportOptions = {
44
filePath: string;
5-
options: ConversionOptions;
5+
conversionOptions: ConversionOptions;
66
format: Format;
77
plugins: {
88
share: {
@@ -29,8 +29,7 @@ export type ConversionOptions = {
2929
editService?: EditServiceInfo;
3030
};
3131

32-
export enum ConversionStatus {
33-
idle = 'idle',
32+
export enum ExportStatus {
3433
inProgress = 'inProgress',
3534
failed = 'failed',
3635
canceled = 'canceled',

main/common/types/remote-states.ts

Lines changed: 51 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,26 @@
11
import {App, Format} from './base';
2-
import {ConversionStatus} from './conversion-options';
2+
import {ExportStatus} from './conversion-options';
3+
4+
// eslint-disable-next-line @typescript-eslint/ban-types
5+
export type RemoteState<State = any, Actions extends Record<string, (...args: any[]) => any> = {}> = {
6+
actions: Actions;
7+
state: State;
8+
};
9+
10+
export type RemoteStateHook<Base extends RemoteState> = Base extends RemoteState<infer State, infer Actions> ? (
11+
Actions & {
12+
state: State;
13+
isLoading: boolean;
14+
refreshState: () => void;
15+
}
16+
) : never;
17+
18+
export type RemoteStateHandler<Base extends RemoteState> = Base extends RemoteState<infer State, infer Actions> ? (sendUpdate: (state: State, id?: string) => void) => {
19+
actions: {
20+
[Key in keyof Actions]: Actions[Key] extends (...args: any[]) => any ? (id: string, ...args: Parameters<Actions[Key]>) => void : never
21+
};
22+
getState: (id: string) => State | undefined;
23+
} : never;
324

425
export interface ExportOptionsPlugin {
526
title: string;
@@ -29,34 +50,40 @@ export type ExportOptions = {
2950
fpsHistory: {[key in Format]: number};
3051
};
3152

32-
export type EditorOptionsRemoteState = (sendUpdate: (state: ExportOptions) => void) => {
33-
actions: {
34-
updatePluginUsage: ({format, plugin}: {
35-
format: Format;
36-
plugin: string;
37-
}) => void;
38-
updateFpsUsage: ({format, fps}: {
39-
format: Format;
40-
fps: number;
41-
}) => void;
42-
};
43-
getState: () => ExportOptions;
44-
};
53+
export type EditorOptionsRemoteState = RemoteState<ExportOptions, {
54+
updatePluginUsage: ({format, plugin}: {
55+
format: Format;
56+
plugin: string;
57+
}) => void;
58+
updateFpsUsage: ({format, fps}: {
59+
format: Format;
60+
fps: number;
61+
}) => void;
62+
}>;
4563

46-
export interface ConversionState {
64+
export interface ExportState {
65+
id: string;
4766
title: string;
4867
description: string;
4968
message: string;
5069
progress?: number;
51-
size?: string;
52-
status: ConversionStatus;
70+
image?: string;
71+
filePath?: string;
72+
error?: Error;
73+
fileSize?: string;
74+
status: ExportStatus;
5375
canCopy: boolean;
76+
disableOutputActions: boolean;
77+
canPreviewExport: boolean;
78+
titleWithFormat: string;
5479
}
5580

56-
export type ConversionRemoteState = (sendUpdate: (state: ConversionState, id: string) => void) => {
57-
actions: {
58-
copy: (_?: undefined, conversionId?: string) => void;
59-
cancel: (_?: undefined, conversionId?: string) => void;
60-
};
61-
getState: (conversionId: string) => ConversionState | undefined;
62-
};
81+
export type ExportsRemoteState = RemoteState<ExportState, {
82+
copy: () => void;
83+
cancel: () => void;
84+
retry: () => void;
85+
openInEditor: () => void;
86+
showInFolder: () => void;
87+
}>;
88+
89+
export type ExportsListRemoteState = RemoteState<string[]>;

0 commit comments

Comments
 (0)