mirror of
https://github.com/fofolee/uTools-quickcommand.git
synced 2025-06-06 21:14:09 +08:00
修复进度条高度在增长后无法正常恢复的BUG
This commit is contained in:
parent
dd7fca3b62
commit
2fce45e13b
@ -7,7 +7,7 @@ document.addEventListener("DOMContentLoaded", () => {
|
||||
let dialogType = null;
|
||||
|
||||
// 监听父窗口发来的对话框配置
|
||||
ipcRenderer.on("dialog-config", (event, config) => {
|
||||
ipcRenderer.on("window-config", (event, config) => {
|
||||
parentId = event.senderId;
|
||||
dialogType = config.type;
|
||||
|
||||
@ -79,7 +79,7 @@ document.addEventListener("DOMContentLoaded", () => {
|
||||
const button = document.createElement("button");
|
||||
button.textContent = btn;
|
||||
button.onclick = () => {
|
||||
ipcRenderer.sendTo(parentId, "dialog-result", {
|
||||
ipcRenderer.sendTo(parentId, "window-response", {
|
||||
id: index,
|
||||
text: btn,
|
||||
});
|
||||
@ -137,7 +137,7 @@ document.addEventListener("DOMContentLoaded", () => {
|
||||
text: item,
|
||||
}
|
||||
: item;
|
||||
ipcRenderer.sendTo(parentId, "dialog-result", result);
|
||||
ipcRenderer.sendTo(parentId, "window-response", result);
|
||||
};
|
||||
|
||||
// 鼠标移入事件
|
||||
@ -339,7 +339,7 @@ document.addEventListener("DOMContentLoaded", () => {
|
||||
waitBtn.id = "wait-btn";
|
||||
waitBtn.textContent = config.text;
|
||||
waitBtn.onclick = () => {
|
||||
ipcRenderer.sendTo(parentId, "dialog-result", true);
|
||||
ipcRenderer.sendTo(parentId, "window-response", true);
|
||||
};
|
||||
|
||||
buttonGroup.appendChild(waitBtn);
|
||||
@ -350,7 +350,7 @@ document.addEventListener("DOMContentLoaded", () => {
|
||||
cancelBtn.id = "wait-cancel-btn";
|
||||
cancelBtn.innerHTML = "✕"; // 使用 × 符号
|
||||
cancelBtn.onclick = () => {
|
||||
ipcRenderer.sendTo(parentId, "dialog-result", false);
|
||||
ipcRenderer.sendTo(parentId, "window-response", false);
|
||||
};
|
||||
buttonGroup.appendChild(cancelBtn);
|
||||
}
|
||||
@ -390,11 +390,11 @@ document.addEventListener("DOMContentLoaded", () => {
|
||||
|
||||
// 添加关闭按钮点击事件
|
||||
document.getElementById("process-close-btn").onclick = () => {
|
||||
ipcRenderer.sendTo(parentId, "dialog-result", "close");
|
||||
ipcRenderer.sendTo(parentId, "window-response", "close");
|
||||
};
|
||||
break;
|
||||
}
|
||||
ipcRenderer.sendTo(parentId, "dialog-ready", calculateHeight());
|
||||
ipcRenderer.sendTo(parentId, "window-resize", calculateHeight());
|
||||
});
|
||||
|
||||
// 监听进度条更新事件
|
||||
@ -412,7 +412,7 @@ document.addEventListener("DOMContentLoaded", () => {
|
||||
const processText = document.getElementById("process-text");
|
||||
processText.innerHTML = text;
|
||||
processText.scrollTop = processText.scrollHeight;
|
||||
ipcRenderer.sendTo(parentId, "dialog-ready", calculateHeight());
|
||||
ipcRenderer.sendTo(parentId, "window-resize", calculateHeight());
|
||||
}
|
||||
});
|
||||
|
||||
@ -420,16 +420,23 @@ document.addEventListener("DOMContentLoaded", () => {
|
||||
const titleBar = document.querySelector(".title-bar");
|
||||
const buttonBar = document.querySelector(".button-bar");
|
||||
const contentWrapper = document.querySelector(".content-wrapper");
|
||||
const processText = document.getElementById("process-text");
|
||||
|
||||
// 计算总高度
|
||||
// 对于进度条对话框,特殊处理高度计算
|
||||
if (dialogType === "process") {
|
||||
const processTextHeight = processText ? processText.scrollHeight : 0;
|
||||
const totalHeight = Math.max(60, processTextHeight + 40);
|
||||
return Math.min(totalHeight, 290); // 限制最大高度
|
||||
}
|
||||
|
||||
// 其他对话框的高度计算保持不变
|
||||
const totalHeight =
|
||||
titleBar.offsetHeight +
|
||||
contentWrapper.scrollHeight +
|
||||
(buttonBar.style.display !== "none" ? buttonBar.offsetHeight : 0);
|
||||
|
||||
const maxHeight = dialogType === "select" ? 620 : 520;
|
||||
// 进度条的最大高度通过.process-text的max-height限制
|
||||
const minHeight = dialogType === "process" ? 60 : 100;
|
||||
const minHeight = 100;
|
||||
|
||||
// 确保高度在最小值和最大值之间
|
||||
return Math.min(Math.max(totalHeight, minHeight), maxHeight);
|
||||
@ -458,7 +465,7 @@ document.addEventListener("DOMContentLoaded", () => {
|
||||
break;
|
||||
}
|
||||
|
||||
ipcRenderer.sendTo(parentId, "dialog-result", result);
|
||||
ipcRenderer.sendTo(parentId, "window-response", result);
|
||||
};
|
||||
|
||||
const cancelDialog = () => {
|
||||
@ -482,7 +489,7 @@ document.addEventListener("DOMContentLoaded", () => {
|
||||
default:
|
||||
result = null;
|
||||
}
|
||||
ipcRenderer.sendTo(parentId, "dialog-result", result);
|
||||
ipcRenderer.sendTo(parentId, "window-response", result);
|
||||
};
|
||||
|
||||
// 取消按钮点击事件
|
||||
|
@ -49,13 +49,13 @@ const createDialog = (config, customDialogOptions = {}) => {
|
||||
|
||||
// 创建窗口
|
||||
const UBrowser = createBrowserWindow(dialogPath, dialogOptions, () => {
|
||||
const dialogResultHandler = (event, result) => {
|
||||
const windowResponseHandler = (event, result) => {
|
||||
resolve(result);
|
||||
// 移除监听器
|
||||
UBrowser.destroy();
|
||||
};
|
||||
|
||||
const dialogReadyHandler = (event, height) => {
|
||||
const windowResizeHandler = (event, height) => {
|
||||
// 获取当前窗口位置
|
||||
const bounds = UBrowser.getBounds();
|
||||
// 调整y坐标,保持窗口中心点不变
|
||||
@ -74,13 +74,13 @@ const createDialog = (config, customDialogOptions = {}) => {
|
||||
|
||||
// 监听子窗口返回的计算高度, 等待按钮有自己的计算逻辑
|
||||
config.type !== "wait-button" &&
|
||||
ipcRenderer.once("dialog-ready", dialogReadyHandler);
|
||||
ipcRenderer.once("window-resize", windowResizeHandler);
|
||||
|
||||
// 监听子窗口返回的返回值
|
||||
ipcRenderer.once("dialog-result", dialogResultHandler);
|
||||
ipcRenderer.once("window-response", windowResponseHandler);
|
||||
|
||||
// 发送配置到子窗口
|
||||
ipcRenderer.sendTo(UBrowser.webContents.id, "dialog-config", {
|
||||
ipcRenderer.sendTo(UBrowser.webContents.id, "window-config", {
|
||||
...config,
|
||||
isDark: utools.isDarkColors(),
|
||||
platform,
|
||||
@ -349,11 +349,11 @@ const showProcessBar = async (options = {}) => {
|
||||
},
|
||||
() => {
|
||||
const windowId = UBrowser.webContents.id;
|
||||
let dialogReadyHandler;
|
||||
let windowResizeHandler;
|
||||
let processPauseHandler;
|
||||
|
||||
// 创建事件处理器
|
||||
dialogReadyHandler = (event, height) => {
|
||||
windowResizeHandler = (event, height) => {
|
||||
if (event.senderId !== windowId) return;
|
||||
const bounds = UBrowser.getBounds();
|
||||
const y = Math.round(bounds.y - (height - bounds.height));
|
||||
@ -381,16 +381,16 @@ const showProcessBar = async (options = {}) => {
|
||||
}
|
||||
|
||||
// 监听子窗口返回的计算高度
|
||||
ipcRenderer.on("dialog-ready", dialogReadyHandler);
|
||||
ipcRenderer.on("window-resize", windowResizeHandler);
|
||||
|
||||
// 监听对话框结果
|
||||
ipcRenderer.once("dialog-result", (event, result) => {
|
||||
ipcRenderer.once("window-response", (event, result) => {
|
||||
if (event.senderId !== windowId) return;
|
||||
if (result === "close" && typeof onClose === "function") {
|
||||
onClose();
|
||||
}
|
||||
// 清理所有事件监听器
|
||||
ipcRenderer.removeListener("dialog-ready", dialogReadyHandler);
|
||||
ipcRenderer.removeListener("window-resize", windowResizeHandler);
|
||||
if (processPauseHandler) {
|
||||
ipcRenderer.removeListener("process-pause", processPauseHandler);
|
||||
}
|
||||
@ -399,7 +399,7 @@ const showProcessBar = async (options = {}) => {
|
||||
});
|
||||
|
||||
// 发送配置到子窗口
|
||||
ipcRenderer.sendTo(windowId, "dialog-config", {
|
||||
ipcRenderer.sendTo(windowId, "window-config", {
|
||||
type: "process",
|
||||
text,
|
||||
value: value === undefined ? 0 : value,
|
||||
@ -416,7 +416,7 @@ const showProcessBar = async (options = {}) => {
|
||||
onClose();
|
||||
}
|
||||
// 清理所有事件监听器
|
||||
ipcRenderer.removeListener("dialog-ready", dialogReadyHandler);
|
||||
ipcRenderer.removeListener("window-resize", windowResizeHandler);
|
||||
if (processPauseHandler) {
|
||||
ipcRenderer.removeListener("process-pause", processPauseHandler);
|
||||
}
|
||||
|
@ -606,6 +606,7 @@ textarea:focus {
|
||||
padding-right: 2px;
|
||||
width: calc(100% - 15px);
|
||||
box-sizing: border-box;
|
||||
/* 290 - 40 的 padding*/
|
||||
max-height: 250px;
|
||||
-webkit-app-region: no-drag;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user