mirror of
https://github.com/fanchenio/DawnLauncher.git
synced 2025-07-13 21:02:10 +08:00
fixed the bug of invalid environment variables.
This commit is contained in:
parent
28f3ed000f
commit
467f33bc99
@ -98,24 +98,20 @@ function parseEnvPath(path: string) {
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取绝对路径
|
||||
* @param path
|
||||
* 解析路径
|
||||
* @returns
|
||||
*/
|
||||
function getAbsolutePath(path: string) {
|
||||
function parsePath(path: string) {
|
||||
// 尝试解析环境变量
|
||||
path = parseEnvPath(path);
|
||||
// 是否是相对路径
|
||||
if (!isAbsolutePath(path)) {
|
||||
// 尝试解析环境变量
|
||||
let newPath = parseEnvPath(path);
|
||||
// 判断解析之后的路径是否是绝对路径
|
||||
if (isAbsolutePath(newPath)) {
|
||||
return newPath;
|
||||
} else {
|
||||
return resolve(
|
||||
process.env.NODE_ENV === "development"
|
||||
? resolve(".")
|
||||
: dirname(process.execPath),
|
||||
path
|
||||
);
|
||||
}
|
||||
return resolve(
|
||||
process.env.NODE_ENV === "development"
|
||||
? resolve(".")
|
||||
: dirname(process.execPath),
|
||||
path
|
||||
);
|
||||
}
|
||||
return path;
|
||||
}
|
||||
@ -146,10 +142,4 @@ function getFileIcon(filePath: string | null) {
|
||||
return icon;
|
||||
}
|
||||
|
||||
export {
|
||||
getURLParams,
|
||||
getAbsolutePath,
|
||||
getFileIcon,
|
||||
iconExts,
|
||||
getRandomUserAgent,
|
||||
};
|
||||
export { getURLParams, parsePath, getFileIcon, iconExts, getRandomUserAgent };
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { BrowserWindow, shell, dialog, app } from "electron";
|
||||
import { join } from "node:path";
|
||||
import { getAbsolutePath, getURLParams } from "../../commons/utils";
|
||||
import { parsePath, getURLParams } from "../../commons/utils";
|
||||
import { Item } from "../../../types/item";
|
||||
import {
|
||||
batchAdd,
|
||||
@ -326,7 +326,7 @@ function run(
|
||||
// 获取绝对路径
|
||||
if (item.type === 0 || item.type === 1) {
|
||||
// 获取路径
|
||||
item.data.target = getAbsolutePath(item.data.target);
|
||||
item.data.target = parsePath(item.data.target);
|
||||
}
|
||||
try {
|
||||
// 判断文件或文件夹是否存在
|
||||
@ -496,7 +496,7 @@ async function createShortcut(item: Item) {
|
||||
let target = item.data.target;
|
||||
if (item.type === 0 || item.type === 1) {
|
||||
// 获取绝对路径
|
||||
target = getAbsolutePath(target);
|
||||
target = parsePath(target);
|
||||
}
|
||||
// 保存路径
|
||||
let savePath =
|
||||
|
@ -5,9 +5,8 @@ import {
|
||||
ipcMain,
|
||||
clipboard,
|
||||
MenuItemConstructorOptions,
|
||||
screen,
|
||||
} from "electron";
|
||||
import { getAbsolutePath } from "../../commons/utils";
|
||||
import { parsePath } from "../../commons/utils";
|
||||
import {
|
||||
convertTarget,
|
||||
createAddEditWindow,
|
||||
@ -267,7 +266,7 @@ export default function () {
|
||||
.getNativeWindowHandle()
|
||||
.readInt32LE(0),
|
||||
item.type === 0 || item.type === 1
|
||||
? getAbsolutePath(item.data.target)
|
||||
? parsePath(item.data.target)
|
||||
: item.data.target,
|
||||
point[0],
|
||||
point[1]
|
||||
@ -296,7 +295,7 @@ export default function () {
|
||||
click: () => {
|
||||
clipboard.writeText(
|
||||
item.type === 0 || item.type === 1
|
||||
? getAbsolutePath(item.data.target)
|
||||
? parsePath(item.data.target)
|
||||
: item.data.target
|
||||
);
|
||||
},
|
||||
@ -679,7 +678,7 @@ export default function () {
|
||||
}
|
||||
let icon = join(process.env.VITE_PUBLIC, "drag-and-drop.png");
|
||||
event.sender.startDrag({
|
||||
file: getAbsolutePath(item.data.target),
|
||||
file: parsePath(item.data.target),
|
||||
icon: icon,
|
||||
});
|
||||
} finally {
|
||||
|
@ -7,11 +7,10 @@ import {
|
||||
import { CommonItem, Item } from "../../types/item";
|
||||
import { parse, join, extname } from "node:path";
|
||||
import { readdirSync, readFileSync, statSync, writeFileSync } from "node:fs";
|
||||
import { execSync } from "node:child_process";
|
||||
import xml2js from "xml2js";
|
||||
import { newCommonItem, newCommonItemData } from "../../commons/utils/common";
|
||||
import { ShortcutInfo } from "../../types/common";
|
||||
import { getAbsolutePath, getFileIcon } from "../commons/utils";
|
||||
import { parsePath, getFileIcon } from "../commons/utils";
|
||||
|
||||
// AppxInfo
|
||||
export interface AppxInfo {
|
||||
@ -753,7 +752,7 @@ function checkInvalidItem(itemList: Array<Item>) {
|
||||
// 只校验文件和文件夹
|
||||
if (item.type === 0 || item.type === 1) {
|
||||
// 获取绝对路径
|
||||
let path = getAbsolutePath(item.data.target);
|
||||
let path = parsePath(item.data.target);
|
||||
try {
|
||||
statSync(path);
|
||||
} catch (e) {
|
||||
|
Loading…
Reference in New Issue
Block a user