mirror of
https://github.com/fanchenio/DawnLauncher.git
synced 2025-07-13 12:52:10 +08:00
优化拖拽文件速度。
This commit is contained in:
parent
342d8939ab
commit
56517f059c
@ -1,6 +1,6 @@
|
|||||||
import { BrowserWindow, shell, app } from "electron";
|
import { BrowserWindow, shell, app } from "electron";
|
||||||
import { join } from "node:path";
|
import { extname, join } from "node:path";
|
||||||
import { parsePath, getURLParams } from "../../commons/utils";
|
import { parsePath, getURLParams, getFileIcon } from "../../commons/utils";
|
||||||
import { Item } from "../../../types/item";
|
import { Item } from "../../../types/item";
|
||||||
import {
|
import {
|
||||||
batchAdd,
|
batchAdd,
|
||||||
@ -15,8 +15,10 @@ import { writeFile, statSync, readFileSync, accessSync } from "node:fs";
|
|||||||
import mime from "mime";
|
import mime from "mime";
|
||||||
import {
|
import {
|
||||||
deleteExtname,
|
deleteExtname,
|
||||||
|
getFileName,
|
||||||
getItemName,
|
getItemName,
|
||||||
isAbsolutePath,
|
isAbsolutePath,
|
||||||
|
newItem,
|
||||||
} from "../../../commons/utils/common";
|
} from "../../../commons/utils/common";
|
||||||
import { iconExts } from "../../commons/utils";
|
import { iconExts } from "../../commons/utils";
|
||||||
import { addAssociateFolderWatcher } from "../classification";
|
import { addAssociateFolderWatcher } from "../classification";
|
||||||
@ -29,6 +31,7 @@ import {
|
|||||||
showSaveDialogSync,
|
showSaveDialogSync,
|
||||||
} from "../commons/index";
|
} from "../commons/index";
|
||||||
import { fork } from "../../commons/utilityProcessUtils";
|
import { fork } from "../../commons/utilityProcessUtils";
|
||||||
|
import { ShortcutInfo } from "../../../types/common";
|
||||||
|
|
||||||
// 窗口
|
// 窗口
|
||||||
let itemAddEditWindow: BrowserWindow | null = null;
|
let itemAddEditWindow: BrowserWindow | null = null;
|
||||||
@ -260,14 +263,9 @@ function move(idList: Array<number>, toClassificationId: number) {
|
|||||||
* @param classificationId
|
* @param classificationId
|
||||||
* @param pathList
|
* @param pathList
|
||||||
*/
|
*/
|
||||||
function drop(classificationId: number, pathList: Array<string>) {
|
async function drop(classificationId: number, pathList: Array<string>) {
|
||||||
fork(
|
// 获取项目信息
|
||||||
"getDropItemInfo",
|
let resultList = await getDropItemInfo(classificationId, pathList);
|
||||||
{
|
|
||||||
classificationId,
|
|
||||||
pathList,
|
|
||||||
},
|
|
||||||
(resultList: Array<Item>) => {
|
|
||||||
// 添加项目
|
// 添加项目
|
||||||
let itemList = batchAdd(classificationId, resultList);
|
let itemList = batchAdd(classificationId, resultList);
|
||||||
// 发送消息到页面
|
// 发送消息到页面
|
||||||
@ -277,8 +275,6 @@ function drop(classificationId: number, pathList: Array<string>) {
|
|||||||
classificationId: null,
|
classificationId: null,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 更新项目打开信息
|
* 更新项目打开信息
|
||||||
@ -708,6 +704,90 @@ function deleteQuickSearchHistory(itemId: number) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过路径获取项目信息
|
||||||
|
* @param classificationId
|
||||||
|
* @param pathList
|
||||||
|
*/
|
||||||
|
async function getDropItemInfo(
|
||||||
|
classificationId: number,
|
||||||
|
pathList: Array<string>
|
||||||
|
) {
|
||||||
|
// 项目列表
|
||||||
|
let itemList: Array<Item> = [];
|
||||||
|
// 解析文件信息并添加项目
|
||||||
|
for (const path of pathList) {
|
||||||
|
try {
|
||||||
|
// item
|
||||||
|
let item = newItem({ classificationId });
|
||||||
|
// 目标
|
||||||
|
item.data.target = path;
|
||||||
|
// 名称
|
||||||
|
item.name = getFileName(item.data.target);
|
||||||
|
// 判断是否是快捷方式,如果是的话,需要获取真实路径
|
||||||
|
if (mime.getType(path) === "application/x-ms-shortcut") {
|
||||||
|
// 快捷方式
|
||||||
|
// 获取真实文件路径和参数
|
||||||
|
let shortcutInfo: ShortcutInfo | null =
|
||||||
|
global.addon.getShortcutFileInfo(path);
|
||||||
|
if (shortcutInfo) {
|
||||||
|
// 路径
|
||||||
|
if (shortcutInfo.target) {
|
||||||
|
item.data.target = shortcutInfo.target;
|
||||||
|
}
|
||||||
|
// 参数
|
||||||
|
if (shortcutInfo.arguments) {
|
||||||
|
item.data.params = shortcutInfo.arguments;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 获取图标
|
||||||
|
item.data.icon = await getFileIcon(item.data.target);
|
||||||
|
// 获取后缀,判断是否是url
|
||||||
|
let ext = extname(item.data.target);
|
||||||
|
if (ext && ext.toLowerCase() === ".url") {
|
||||||
|
// url
|
||||||
|
let url = parseUrlFileContent(readFileSync(item.data.target, "utf-8"));
|
||||||
|
if (url && url.trim() !== "") {
|
||||||
|
item.data.target = url;
|
||||||
|
item.type = 2;
|
||||||
|
} else {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// 文件类型
|
||||||
|
let stats = statSync(item.data.target);
|
||||||
|
item.type = stats.isFile() ? 0 : 1;
|
||||||
|
}
|
||||||
|
// 去掉后缀
|
||||||
|
if (item.type === 0 || item.type === 2) {
|
||||||
|
item.name = deleteExtname(item.name);
|
||||||
|
}
|
||||||
|
// push
|
||||||
|
itemList.push(item);
|
||||||
|
} catch (e) {}
|
||||||
|
}
|
||||||
|
return itemList;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 解析.url文件内容以获取URL
|
||||||
|
* @param content
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
function parseUrlFileContent(content: string) {
|
||||||
|
if (content) {
|
||||||
|
const lines = content.split("\n");
|
||||||
|
for (const line of lines) {
|
||||||
|
if (line.startsWith("URL=")) {
|
||||||
|
const url = line.substring(4).trim();
|
||||||
|
return url;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
export {
|
export {
|
||||||
createAddEditWindow,
|
createAddEditWindow,
|
||||||
createNetworkIconWindow,
|
createNetworkIconWindow,
|
||||||
|
@ -5,7 +5,7 @@ import {
|
|||||||
newItem,
|
newItem,
|
||||||
} from "../../commons/utils/common";
|
} from "../../commons/utils/common";
|
||||||
import { CommonItem, Item } from "../../types/item";
|
import { CommonItem, Item } from "../../types/item";
|
||||||
import { parse, join, extname } from "node:path";
|
import { parse, join } from "node:path";
|
||||||
import { readdirSync, readFileSync, statSync, writeFileSync } from "node:fs";
|
import { readdirSync, readFileSync, statSync, writeFileSync } from "node:fs";
|
||||||
import xml2js from "xml2js";
|
import xml2js from "xml2js";
|
||||||
import { newCommonItem, newCommonItemData } from "../../commons/utils/common";
|
import { newCommonItem, newCommonItemData } from "../../commons/utils/common";
|
||||||
@ -43,11 +43,6 @@ process.parentPort.once("message", async (event) => {
|
|||||||
res = await getStartMenuItemList(dataParam);
|
res = await getStartMenuItemList(dataParam);
|
||||||
} else if (params.name === "getAppxItemList") {
|
} else if (params.name === "getAppxItemList") {
|
||||||
res = await getAppxItemList();
|
res = await getAppxItemList();
|
||||||
} else if (params.name === "getDropItemInfo") {
|
|
||||||
res = await getDropItemInfo(
|
|
||||||
dataParam.classificationId,
|
|
||||||
dataParam.pathList
|
|
||||||
);
|
|
||||||
} else if (params.name === "refreshItemIcon") {
|
} else if (params.name === "refreshItemIcon") {
|
||||||
res = await refreshItemIcon(dataParam);
|
res = await refreshItemIcon(dataParam);
|
||||||
} else if (params.name === "getDirectoryItemList") {
|
} else if (params.name === "getDirectoryItemList") {
|
||||||
@ -558,90 +553,6 @@ function getPropertiesIcon(installLocation: string, result: any) {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 通过路径获取项目信息
|
|
||||||
* @param classificationId
|
|
||||||
* @param pathList
|
|
||||||
*/
|
|
||||||
async function getDropItemInfo(
|
|
||||||
classificationId: number,
|
|
||||||
pathList: Array<string>
|
|
||||||
) {
|
|
||||||
// 项目列表
|
|
||||||
let itemList: Array<Item> = [];
|
|
||||||
// 解析文件信息并添加项目
|
|
||||||
for (const path of pathList) {
|
|
||||||
try {
|
|
||||||
// item
|
|
||||||
let item = newItem({ classificationId });
|
|
||||||
// 目标
|
|
||||||
item.data.target = path;
|
|
||||||
// 名称
|
|
||||||
item.name = getFileName(item.data.target);
|
|
||||||
// 判断是否是快捷方式,如果是的话,需要获取真实路径
|
|
||||||
if (mime.getType(path) === "application/x-ms-shortcut") {
|
|
||||||
// 快捷方式
|
|
||||||
// 获取真实文件路径和参数
|
|
||||||
let shortcutInfo: ShortcutInfo | null =
|
|
||||||
global.addon.getShortcutFileInfo(path);
|
|
||||||
if (shortcutInfo) {
|
|
||||||
// 路径
|
|
||||||
if (shortcutInfo.target) {
|
|
||||||
item.data.target = shortcutInfo.target;
|
|
||||||
}
|
|
||||||
// 参数
|
|
||||||
if (shortcutInfo.arguments) {
|
|
||||||
item.data.params = shortcutInfo.arguments;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// 获取图标
|
|
||||||
item.data.icon = await getFileIcon(item.data.target);
|
|
||||||
// 获取后缀,判断是否是url
|
|
||||||
let ext = extname(item.data.target);
|
|
||||||
if (ext && ext.toLowerCase() === ".url") {
|
|
||||||
// url
|
|
||||||
let url = parseUrlFileContent(readFileSync(item.data.target, "utf-8"));
|
|
||||||
if (url && url.trim() !== "") {
|
|
||||||
item.data.target = url;
|
|
||||||
item.type = 2;
|
|
||||||
} else {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// 文件类型
|
|
||||||
let stats = statSync(item.data.target);
|
|
||||||
item.type = stats.isFile() ? 0 : 1;
|
|
||||||
}
|
|
||||||
// 去掉后缀
|
|
||||||
if (item.type === 0 || item.type === 2) {
|
|
||||||
item.name = deleteExtname(item.name);
|
|
||||||
}
|
|
||||||
// push
|
|
||||||
itemList.push(item);
|
|
||||||
} catch (e) {}
|
|
||||||
}
|
|
||||||
return itemList;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 解析.url文件内容以获取URL
|
|
||||||
* @param content
|
|
||||||
* @returns
|
|
||||||
*/
|
|
||||||
function parseUrlFileContent(content: string) {
|
|
||||||
if (content) {
|
|
||||||
const lines = content.split("\n");
|
|
||||||
for (const line of lines) {
|
|
||||||
if (line.startsWith("URL=")) {
|
|
||||||
const url = line.substring(4).trim();
|
|
||||||
return url;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 刷新项目图标
|
* 刷新项目图标
|
||||||
* @param itemList
|
* @param itemList
|
||||||
|
Loading…
Reference in New Issue
Block a user