Skip to content

Commit 98afc38

Browse files
authored
Fix the types of electron functions and awaiting rename (#8028)
1 parent 214b9bc commit 98afc38

File tree

3 files changed

+10
-8
lines changed

3 files changed

+10
-8
lines changed

interface.d.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,14 @@ export interface IElectronAPI {
4747
writeFile: (
4848
path: string,
4949
data: string | Uint8Array
50-
) => ReturnType<fs.writeFile>
51-
readdir: (path: string) => ReturnType<fs.readdir>
52-
exists: (path: string) => ReturnType<fs.exists>
50+
) => ReturnType<typeof fs.writeFile>
51+
readdir: (path: string) => Promise<string[]>
52+
// This is synchronous.
53+
exists: (path: string) => boolean
5354
getPath: (name: string) => Promise<string>
5455
rm: typeof fs.rm
55-
stat: (path: string) => ReturnType<fs.stat>
56+
// TODO: Use a real return type.
57+
stat: (path: string) => Promise<any>
5658
statIsDirectory: (path: string) => Promise<boolean>
5759
canReadWriteDirectory: (
5860
path: string
@@ -61,7 +63,7 @@ export interface IElectronAPI {
6163
mkdir: typeof fs.mkdir
6264
join: typeof path.join
6365
sep: typeof path.sep
64-
rename: (prev: string, next: string) => typeof fs.rename
66+
rename: (prev: string, next: string) => ReturnType<typeof fs.rename>
6567
packageJson: {
6668
name: string
6769
}

src/components/FileMachineProvider.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ export const FileMachineProvider = ({
294294
}
295295
}
296296

297-
window.electron.rename(oldPath, newPath)
297+
await window.electron.rename(oldPath, newPath)
298298

299299
if (!file) {
300300
return Promise.reject(new Error('file is not defined'))

src/machines/systemIO/systemIOMachineDesktop.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ export const systemIOMachineDesktop = systemIOMachine.provide({
457457
}
458458
}
459459

460-
window.electron.rename(oldPath, newPath)
460+
await window.electron.rename(oldPath, newPath)
461461

462462
return {
463463
message: `Successfully renamed folder "${folderName}" to "${requestedFolderName}"`,
@@ -523,7 +523,7 @@ export const systemIOMachineDesktop = systemIOMachine.provide({
523523
}
524524
}
525525

526-
window.electron.rename(oldPath, newPath)
526+
await window.electron.rename(oldPath, newPath)
527527

528528
return {
529529
message: `Successfully renamed file "${fileNameWithExtension}" to "${requestedFileNameWithExtension}"`,

0 commit comments

Comments
 (0)