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