Skip to content

Commit 3faf909

Browse files
authored
[CP-3909][App Refactor][Kompakt] Manage Files - export (download) (#2746)
1 parent 8a7d4a9 commit 3faf909

File tree

28 files changed

+754
-161
lines changed

28 files changed

+754
-161
lines changed

apps/app/electron-builder.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ win:
1919
icon: ./resources/icons/icon.ico
2020
target:
2121
- nsis
22+
extraFiles:
23+
- from: ./resources/MtpFileTransfer.exe
24+
to: resources/MtpFileTransfer.exe
2225
nsis:
2326
artifactName: Mudita-Center.${ext}
2427
uninstallDisplayName: ${productName}
1.01 MB
Binary file not shown.

libs/app-localize/utils/src/lib/locales/en-US.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,7 @@
364364
"manageFiles.progressWarning.secondLineText": "to close them if you have them open.",
365365
"manageFiles.refreshButton.text": "Refresh",
366366
"manageFiles.selection.delete": "Delete",
367+
"manageFiles.selection.download": "Export",
367368
"manageFiles.selection.selectedCount": "{count, plural, =-1 {All files} =0 {No files} one {# file} other {# files}} selected",
368369
"manageFiles.summary.usedLabel": "Used:",
369370
"manageFiles.uploadSuccess.toast.text": "{fileCount, plural, one {# file transferred} other {# files transferred}}",

libs/app-mtp/main/src/lib/dotnet-mtp/utils/handle-command.ts

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,32 @@
66
import { spawn } from "child_process"
77
import * as readline from "readline"
88
import path from "path"
9+
import fs from "node:fs"
910
import { MTPError } from "app-mtp/models"
1011

12+
const PREFIX_LOG = `[app-mtp/dotnet-mtp]`
13+
1114
const getExecPath = () => {
12-
if (process.env["NODE_ENV"] === "production" && process.resourcesPath) {
13-
return path.join(process.resourcesPath, "MtpFileTransfer.exe")
14-
} else {
15-
return path.join(
16-
process.cwd().replace("apps\\mudita-center", ""),
17-
"apps/mudita-center/resources/MtpFileTransfer.exe"
15+
try {
16+
const buildExecPath = path.join(process.resourcesPath, "MtpFileTransfer.exe")
17+
const localExecPath = path.join(
18+
process.cwd().replace("apps\\app", ""),
19+
"apps/app/resources/MtpFileTransfer.exe"
1820
)
21+
22+
if (fs.existsSync(buildExecPath)) {
23+
return buildExecPath
24+
} else {
25+
return localExecPath
26+
}
27+
} catch (error) {
28+
console.error(`${PREFIX_LOG} Error determining exec path: ${error}`)
29+
return ""
1930
}
2031
}
2132

2233
const exePath = getExecPath()
2334

24-
const PREFIX_LOG = `[app-mtp/dotnet-mtp]`
25-
2635
export async function runCommand(
2736
request: object,
2837
stdOutHandler: (line: string) => void,

libs/app-mtp/main/src/lib/init-app-mtp.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,16 @@ export const initAppMtp = (ipcMain: IpcMain, appMtp: AppMtp) => {
1515
ipcMain.handle(
1616
AppMtpIpcEvents.GetMtpDeviceId,
1717
async (_, portInfo: Partial<PortInfo>) => {
18-
if (!portInfo.serialNumber && !portInfo.pnpId) {
19-
return undefined
20-
}
2118
const devices = await appMtp.getDevices()
2219
const device = devices.find((device) => {
2320
switch (process.platform) {
2421
case "darwin":
2522
case "linux":
2623
return portInfo.serialNumber === device.id
27-
case "win32":
28-
return (
29-
mapToCoreUsbId(portInfo.pnpId ?? "", "\\") ===
30-
mapToCoreUsbId(device.id)
31-
)
24+
case "win32": {
25+
const pnpId = `USB\\VID_${portInfo.vendorId}&PID_${portInfo.productId}\\${portInfo.serialNumber}`
26+
return mapToCoreUsbId(pnpId, "\\") === mapToCoreUsbId(device.id)
27+
}
3228
default:
3329
throw new Error(`Unsupported platform: ${process.platform}`)
3430
}

libs/app-theme/models/src/lib/components/icon.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ export enum IconType {
8181
Support = "support",
8282
ThinFail = "thin-fail",
8383
Trash = "trash",
84+
Upload = "upload",
8485
}
8586

8687
export enum IconSize {

libs/app-theme/ui/src/lib/icon/icons.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ import StarFilled from "./svg/star-filled.svg?react"
8383
import Support from "./svg/support.svg?react"
8484
import ThinFail from "./svg/thin-fail.svg?react"
8585
import Trash from "./svg/trash.svg?react"
86+
import Upload from "./svg/upload.svg?react"
8687

8788
export const icons = {
8889
[IconType.AirplaneMode]: AirplaneMode,
@@ -162,4 +163,5 @@ export const icons = {
162163
[IconType.Support]: Support,
163164
[IconType.ThinFail]: ThinFail,
164165
[IconType.Trash]: Trash,
166+
[IconType.Upload]: Upload,
165167
} as const satisfies Record<IconType, typeof Svg>
Lines changed: 10 additions & 0 deletions
Loading

libs/app-utils/main/src/lib/app-file-system/app-file-system.guard.ts

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -131,13 +131,13 @@ export class AppFileSystemGuard {
131131
return false
132132
}
133133

134+
const targetPath = Array.isArray(options.fileAbsolutePath)
135+
? path.join(...options.fileAbsolutePath)
136+
: options.fileAbsolutePath
137+
134138
let targetRealPath: string
135139
try {
136-
targetRealPath = this.resolveRealPath(
137-
Array.isArray(options.fileAbsolutePath)
138-
? path.join(...options.fileAbsolutePath)
139-
: options.fileAbsolutePath
140-
)
140+
targetRealPath = this.resolveRealPathAllowNonExisting(targetPath)
141141
} catch {
142142
return false
143143
}
@@ -147,7 +147,9 @@ export class AppFileSystemGuard {
147147
const grantedStats = fs.lstatSync(grantedRealPath)
148148

149149
if (grantedStats.isFile()) {
150-
if (targetRealPath === grantedRealPath) return true
150+
if (targetRealPath === grantedRealPath) {
151+
return true
152+
}
151153
continue
152154
}
153155

@@ -166,6 +168,17 @@ export class AppFileSystemGuard {
166168
return false
167169
}
168170

171+
private resolveRealPathAllowNonExisting(targetPath: string): string {
172+
if (fs.existsSync(targetPath)) {
173+
return this.resolveRealPath(targetPath)
174+
}
175+
176+
const parentDir = path.dirname(targetPath)
177+
const parentRealPath = this.resolveRealPath(parentDir)
178+
179+
return path.join(parentRealPath, path.basename(targetPath))
180+
}
181+
169182
private resolveRealPath(inputPath: string): string {
170183
return fs.realpathSync.native(inputPath)
171184
}

libs/app-utils/models/src/lib/app-file-system.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export interface AppFileSystemWriteFileOptions
4646
encoding?: BufferEncoding | string
4747
writeAsJson?: boolean
4848
}
49-
data: Buffer | Record<string, unknown>
49+
data: Buffer | string | Record<string, unknown>
5050
}
5151

5252
export interface AppFileSystemReadFileOptions

0 commit comments

Comments
 (0)