Skip to content

Commit 4287f51

Browse files
authored
Fix files drag-and-drop (#13548)
Fixes #13535 The Electron API has changed.
1 parent 408a76e commit 4287f51

File tree

5 files changed

+23
-22
lines changed

5 files changed

+23
-22
lines changed

app/gui/env.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ interface DownloadUrlOptions {
8585
interface SystemApi {
8686
readonly downloadURL: (options: DownloadUrlOptions) => Promise<void>
8787
readonly showItemInFolder: (fullPath: string) => void
88+
readonly getFilePath: (item: File) => string
8889
}
8990

9091
/** Metadata for a newly imported project. */

app/gui/src/dashboard/services/LocalBackend.ts

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -732,26 +732,17 @@ export default class LocalBackend extends Backend {
732732
} else {
733733
const title = backend.stripProjectExtension(body.fileName)
734734
let id: string
735-
if (
736-
'backendApi' in window &&
737-
// This non-standard property is defined in Electron.
738-
'path' in file &&
739-
typeof file.path === 'string' &&
740-
file.path !== ''
741-
) {
742-
const projectInfo = await window.backendApi.importProjectFromPath(
743-
file.path,
744-
parentPath,
745-
title,
746-
)
735+
const path = window.systemApi?.getFilePath(file)
736+
if ('backendApi' in window && path != null) {
737+
const projectInfo = await window.backendApi.importProjectFromPath(path, parentPath, title)
747738
id = projectInfo.id
748739
} else {
749740
const searchParams = new URLSearchParams({
750741
directory: parentPath,
751742
name: title,
752743
}).toString()
753-
const path = `/api/upload-project?${searchParams}`
754-
const response = await fetch(path, { method: 'POST', body: file })
744+
const url = `/api/upload-project?${searchParams}`
745+
const response = await fetch(url, { method: 'POST', body: file })
755746
id = await response.text()
756747
}
757748
const projectId = newProjectId(projectManager.UUID(id), parentPath)

app/gui/src/project-view/components/GraphEditor/upload.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ export class Uploader {
5656
awareness: Awareness
5757
},
5858
private file: File,
59+
private filePath: string | undefined,
5960
private position: Vec2,
6061
private isOnLocalBackend: boolean,
6162
private disableDirectRead: boolean,
@@ -81,7 +82,16 @@ export class Uploader {
8182
disableDirectRead: boolean,
8283
method: ExternalId,
8384
): Uploader {
84-
return new Uploader(projectStore, file, position, isOnLocalBackend, disableDirectRead, method)
85+
const filePath = window.systemApi?.getFilePath(file)
86+
return new Uploader(
87+
projectStore,
88+
file,
89+
filePath,
90+
position,
91+
isOnLocalBackend,
92+
disableDirectRead,
93+
method,
94+
)
8595
}
8696

8797
private progressUpdate(sizePercentage: number) {
@@ -95,13 +105,8 @@ export class Uploader {
95105
/** Start the upload process */
96106
async upload(): Promise<Result<UploadResult>> {
97107
// This non-standard property is defined in Electron.
98-
if (
99-
this.isOnLocalBackend &&
100-
!this.disableDirectRead &&
101-
'path' in this.file &&
102-
typeof this.file.path === 'string'
103-
) {
104-
return Ok({ source: 'FileSystemRoot', name: this.file.path })
108+
if (this.isOnLocalBackend && !this.disableDirectRead && this.filePath != null) {
109+
return Ok({ source: 'FileSystemRoot', name: this.filePath })
105110
}
106111
const rootId = await this.projectFiles.projectRootId
107112
if (rootId == null) return Err('Could not identify project root.')

app/ide-desktop/client/src/globals.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ export type DownloadUrlOptions = {
106106
interface SystemApi {
107107
readonly downloadURL: (options: DownloadUrlOptions) => Promise<void>
108108
readonly showItemInFolder: (fullPath: string) => void
109+
readonly getFilePath: (item: File) => string
109110
}
110111

111112
// ========================

app/ide-desktop/client/src/preload.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,9 @@ exposeInMainWorld(SYSTEM_API_KEY, {
203203
showItemInFolder: (fullPath: string) => {
204204
electron.ipcRenderer.send(ipc.Channel.showItemInFolder, fullPath)
205205
},
206+
getFilePath: (item: File) => {
207+
return electron.webUtils.getPathForFile(item)
208+
},
206209
})
207210

208211
// ====================

0 commit comments

Comments
 (0)