Skip to content

Commit c9fba8f

Browse files
committed
Move desktopApi app selection logic into desktop-api services
1 parent 5675eff commit c9fba8f

File tree

2 files changed

+16
-13
lines changed

2 files changed

+16
-13
lines changed

src/components/intercept/config/electron-config.tsx

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { logError } from '../../../errors';
88

99
import { Interceptor } from '../../../model/interception/interceptors';
1010
import { UiStore } from '../../../model/ui-store';
11+
import { DesktopApi } from '../../../services/desktop-api';
1112

1213
import { uploadFile } from '../../../util/ui';
1314
import { Button, SecondaryButton, UnstyledButton } from '../../common/inputs';
@@ -120,12 +121,6 @@ function getReadablePath(path: string) {
120121
}
121122
}
122123

123-
declare global {
124-
interface Window {
125-
desktopApi?: { selectApplication: () => Promise<string | undefined> };
126-
}
127-
}
128-
129124
@inject('uiStore')
130125
@observer
131126
class ElectronConfig extends React.Component<{
@@ -147,13 +142,9 @@ class ElectronConfig extends React.Component<{
147142
}
148143

149144
selectApplication = async () => {
150-
const useNativePicker = window.desktopApi?.selectApplication;
145+
const appPicker = DesktopApi.selectApplication ?? (() => uploadFile('path'));
151146

152-
const pathToApplication = await(
153-
useNativePicker
154-
? window.desktopApi?.selectApplication()
155-
: uploadFile('path')
156-
);
147+
const pathToApplication = await(appPicker());
157148

158149
if (!pathToApplication) {
159150
this.props.closeSelf();

src/services/desktop-api.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,16 @@ export async function getDesktopInjectedValue(key: DesktopInjectedKey): Promise<
1919
});
2020
}
2121
// Note that if we're running in a browser, not the desktop shell, this _never_ resolves.
22-
}
22+
}
23+
24+
declare global {
25+
interface Window {
26+
desktopApi?: DesktopApi;
27+
}
28+
}
29+
30+
interface DesktopApi {
31+
selectApplication?: () => Promise<string | undefined>
32+
}
33+
34+
export const DesktopApi: DesktopApi = window.desktopApi ?? {};

0 commit comments

Comments
 (0)