mirror of
https://github.com/fanchenio/DawnLauncher.git
synced 2025-07-13 12:52:10 +08:00
优化窗口失去焦点隐藏、停靠在桌面边缘时自动隐藏功能,在弹出对话框时应不隐藏窗口。
This commit is contained in:
parent
8228495918
commit
e1f896e963
@ -1,4 +1,4 @@
|
||||
import { Menu, MenuItem, ipcMain, dialog } from "electron";
|
||||
import { Menu, MenuItem, ipcMain } from "electron";
|
||||
import { Classification } from "../../../types/classification";
|
||||
import {
|
||||
createAddEditWindow,
|
||||
@ -27,7 +27,12 @@ import {
|
||||
batchUpdateFixed,
|
||||
} from "./data";
|
||||
import { setShortcutKey } from "../setting";
|
||||
import { closeWindow, getDot, sendToWebContent } from "../commons/index";
|
||||
import {
|
||||
closeWindow,
|
||||
getDot,
|
||||
sendToWebContent,
|
||||
showMessageBoxSync,
|
||||
} from "../commons/index";
|
||||
|
||||
export default function () {
|
||||
// 获取分类列表
|
||||
@ -248,13 +253,12 @@ export default function () {
|
||||
new MenuItem({
|
||||
label: global.language.delete,
|
||||
click: () => {
|
||||
let res = dialog.showMessageBoxSync(global.mainWindow, {
|
||||
message: global.language.deleteClassificationPrompt,
|
||||
buttons: [global.language.ok, global.language.cancel],
|
||||
type: "question",
|
||||
noLink: true,
|
||||
cancelId: 1,
|
||||
});
|
||||
let res = showMessageBoxSync(
|
||||
"mainWindow",
|
||||
global.language.deleteClassificationPrompt,
|
||||
"question",
|
||||
[global.language.ok, global.language.cancel]
|
||||
);
|
||||
if (res === 0) {
|
||||
// 删除数据
|
||||
if (del(classification.id)) {
|
||||
|
@ -9,6 +9,8 @@ import { isAbsolutePath } from "../../../commons/utils/common";
|
||||
import {
|
||||
BrowserWindow,
|
||||
Display,
|
||||
OpenDialogOptions,
|
||||
SaveDialogOptions,
|
||||
app,
|
||||
dialog,
|
||||
nativeImage,
|
||||
@ -428,20 +430,6 @@ function openAfterHideWindow(type: string) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 错误提示框
|
||||
* @param windowName
|
||||
* @param message
|
||||
*/
|
||||
function showErrorMessageBox(windowName: string, message: string) {
|
||||
dialog.showMessageBoxSync(getWindow(windowName), {
|
||||
message: message,
|
||||
buttons: [global.language.ok],
|
||||
type: "error",
|
||||
noLink: true,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 重启
|
||||
*/
|
||||
@ -500,6 +488,73 @@ function getWindowInScreen(window: BrowserWindow) {
|
||||
return inDisplays;
|
||||
}
|
||||
|
||||
/**
|
||||
* 通用对话框
|
||||
*/
|
||||
function showMessageBoxSync(
|
||||
windowName: string,
|
||||
message: string,
|
||||
type: "error" | "question" | "info",
|
||||
buttons: Array<string> | null
|
||||
) {
|
||||
// 记录状态
|
||||
if (windowName === "mainWindow") {
|
||||
global.mainWindowShowDialog = true;
|
||||
}
|
||||
let res = dialog.showMessageBoxSync(getWindow(windowName), {
|
||||
title: "Dawn Launcher",
|
||||
message: message,
|
||||
buttons: buttons,
|
||||
type: type,
|
||||
noLink: true,
|
||||
cancelId: 1,
|
||||
});
|
||||
// 删除状态
|
||||
if (windowName === "mainWindow") {
|
||||
global.mainWindowShowDialog = false;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* 错误对话框
|
||||
*/
|
||||
function showErrorMessageBox(windowName: string, message: string) {
|
||||
showMessageBoxSync(windowName, message, "error", [global.language.ok]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 文件保存对话框
|
||||
*/
|
||||
function showSaveDialogSync(windowName: string, options: SaveDialogOptions) {
|
||||
// 记录状态
|
||||
if (windowName === "mainWindow") {
|
||||
global.mainWindowShowDialog = true;
|
||||
}
|
||||
let path = dialog.showSaveDialogSync(getWindow(windowName), options);
|
||||
// 删除状态
|
||||
if (windowName === "mainWindow") {
|
||||
global.mainWindowShowDialog = false;
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
||||
/**
|
||||
* 选择文件/文件夹对话框
|
||||
*/
|
||||
function showOpenDialogSync(windowName: string, options: OpenDialogOptions) {
|
||||
// 记录状态
|
||||
if (windowName === "mainWindow") {
|
||||
global.mainWindowShowDialog = true;
|
||||
}
|
||||
let pathList = dialog.showOpenDialogSync(getWindow(windowName), options);
|
||||
// 删除状态
|
||||
if (windowName === "mainWindow") {
|
||||
global.mainWindowShowDialog = false;
|
||||
}
|
||||
return pathList;
|
||||
}
|
||||
|
||||
export {
|
||||
downloadImage,
|
||||
getURLInfo,
|
||||
@ -511,9 +566,12 @@ export {
|
||||
sendToWebContent,
|
||||
closeAllChildProcess,
|
||||
openAfterHideWindow,
|
||||
showErrorMessageBox,
|
||||
relaunch,
|
||||
getUserDataPath,
|
||||
getMainBackgorunColor,
|
||||
getWindowInScreen,
|
||||
showMessageBoxSync,
|
||||
showErrorMessageBox,
|
||||
showSaveDialogSync,
|
||||
showOpenDialogSync,
|
||||
};
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { app, dialog, ipcMain, OpenDialogSyncOptions, shell } from "electron";
|
||||
import { app, ipcMain, OpenDialogSyncOptions, shell } from "electron";
|
||||
import { getFileIcon } from "../../commons/utils";
|
||||
import mime from "mime";
|
||||
import { ShortcutInfo } from "../../../types/common";
|
||||
@ -8,9 +8,10 @@ import {
|
||||
getURLInfo,
|
||||
sendToWebContent,
|
||||
showErrorMessageBox,
|
||||
showMessageBoxSync,
|
||||
showOpenDialogSync,
|
||||
} from ".";
|
||||
import { statSync } from "node:fs";
|
||||
import { getWindow } from "../commons/index";
|
||||
|
||||
export default function () {
|
||||
// emit
|
||||
@ -23,23 +24,17 @@ export default function () {
|
||||
});
|
||||
// 信息提示框
|
||||
ipcMain.on("showInfoMessageBox", (event, args) => {
|
||||
dialog.showMessageBoxSync(getWindow(args.windowName), {
|
||||
message: args.message,
|
||||
buttons: [global.language.ok],
|
||||
type: "info",
|
||||
noLink: true,
|
||||
});
|
||||
showMessageBoxSync(args.windowName, args.message, "info", [
|
||||
global.language.ok,
|
||||
]);
|
||||
});
|
||||
// 对话框
|
||||
ipcMain.on("showConfirmBox", (event, args) => {
|
||||
// 弹出对话框
|
||||
let res = dialog.showMessageBoxSync(getWindow(args.windowName), {
|
||||
message: args.message,
|
||||
buttons: [global.language.ok, global.language.cancel],
|
||||
type: "question",
|
||||
noLink: true,
|
||||
cancelId: 1,
|
||||
});
|
||||
let res = showMessageBoxSync(args.windowName, args.message, "question", [
|
||||
global.language.ok,
|
||||
global.language.cancel,
|
||||
]);
|
||||
event.returnValue = res === 0;
|
||||
});
|
||||
// 选择文件
|
||||
@ -57,10 +52,7 @@ export default function () {
|
||||
} else {
|
||||
options.defaultPath = app.getPath("desktop");
|
||||
}
|
||||
let filePathList = dialog.showOpenDialogSync(
|
||||
getWindow(windowName),
|
||||
options
|
||||
);
|
||||
let filePathList = showOpenDialogSync(windowName, options);
|
||||
if (filePathList && filePathList.length > 0) {
|
||||
let filePath = filePathList[0];
|
||||
if (target) {
|
||||
@ -94,7 +86,7 @@ export default function () {
|
||||
} else {
|
||||
options.defaultPath = app.getPath("desktop");
|
||||
}
|
||||
let dirPathList = dialog.showOpenDialogSync(getWindow(windowName), options);
|
||||
let dirPathList = showOpenDialogSync(windowName, options);
|
||||
if (dirPathList && dirPathList.length > 0) {
|
||||
let dirPath = dirPathList[0];
|
||||
event.returnValue = dirPath;
|
||||
|
@ -1,6 +1,12 @@
|
||||
import { dialog, ipcMain } from "electron";
|
||||
import { ipcMain } from "electron";
|
||||
import { backupData, createBackupRestoreDataWindow } from ".";
|
||||
import { closeWindow, relaunch, showErrorMessageBox } from "../commons";
|
||||
import {
|
||||
closeWindow,
|
||||
relaunch,
|
||||
showErrorMessageBox,
|
||||
showOpenDialogSync,
|
||||
showSaveDialogSync,
|
||||
} from "../commons";
|
||||
import { restore } from "./data";
|
||||
import { rmSync } from "node:fs";
|
||||
|
||||
@ -22,7 +28,7 @@ export default function () {
|
||||
// 备份数据
|
||||
ipcMain.on("backupData", () => {
|
||||
try {
|
||||
let filePath = dialog.showSaveDialogSync(global.backupRestoreDataWindow, {
|
||||
let filePath = showSaveDialogSync("backupRestoreDataWindow", {
|
||||
defaultPath: "Data",
|
||||
filters: [{ name: "DB", extensions: ["db"] }],
|
||||
});
|
||||
@ -48,12 +54,9 @@ export default function () {
|
||||
// 恢复数据
|
||||
ipcMain.on("restoreData", () => {
|
||||
try {
|
||||
let filePathList = dialog.showOpenDialogSync(
|
||||
global.backupRestoreDataWindow,
|
||||
{
|
||||
filters: [{ name: "Data", extensions: ["db", "json"] }],
|
||||
}
|
||||
);
|
||||
let filePathList = showOpenDialogSync("backupRestoreDataWindow", {
|
||||
filters: [{ name: "Data", extensions: ["db", "json"] }],
|
||||
});
|
||||
if (filePathList && filePathList.length > 0) {
|
||||
let filePath = filePathList[0];
|
||||
if (restore(filePath)) {
|
||||
|
@ -1,5 +1,4 @@
|
||||
import { app, BrowserWindow, dialog } from "electron";
|
||||
import { release } from "node:os";
|
||||
import { join, dirname, basename } from "node:path";
|
||||
import indexIpcEvent from "./main/ipcEvent";
|
||||
import classificationIpcEvent from "./classification/ipcEvent";
|
||||
@ -74,7 +73,7 @@ app.whenReady().then(() => {
|
||||
arg.indexOf("--inspect") !== -1 ||
|
||||
arg.indexOf("--remote-debugging-port") !== -1
|
||||
) {
|
||||
dialog.showMessageBoxSync(null, {
|
||||
dialog.showMessageBoxSync({
|
||||
message: "达咩呦达咩达咩~",
|
||||
buttons: [global.language.ok],
|
||||
type: "error",
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { BrowserWindow, shell, dialog, app } from "electron";
|
||||
import { BrowserWindow, shell, app } from "electron";
|
||||
import { join } from "node:path";
|
||||
import { parsePath, getURLParams } from "../../commons/utils";
|
||||
import { Item } from "../../../types/item";
|
||||
@ -25,6 +25,8 @@ import {
|
||||
convertPath,
|
||||
getMainBackgorunColor,
|
||||
sendToWebContent,
|
||||
showMessageBoxSync,
|
||||
showSaveDialogSync,
|
||||
} from "../commons/index";
|
||||
import { fork } from "../../commons/utilityProcessUtils";
|
||||
|
||||
@ -352,13 +354,9 @@ function run(
|
||||
message = global.language.notFoundFolder;
|
||||
}
|
||||
message += '"' + item.data.target + '"';
|
||||
dialog.showMessageBox(global.mainWindow, {
|
||||
title: "Dawn Launcher",
|
||||
message: message,
|
||||
buttons: [global.language.ok],
|
||||
type: "error",
|
||||
noLink: true,
|
||||
});
|
||||
showMessageBoxSync("mainWindow", message, "error", [
|
||||
global.language.ok,
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -429,7 +427,7 @@ function exportIcon(item: Item) {
|
||||
}
|
||||
// 弹出文件对话框保存
|
||||
if (extensionName && content) {
|
||||
let path = dialog.showSaveDialogSync(global.mainWindow, {
|
||||
let path = showSaveDialogSync("mainWindow", {
|
||||
defaultPath: "icon",
|
||||
filters: [
|
||||
{
|
||||
|
@ -1,7 +1,6 @@
|
||||
import {
|
||||
Menu,
|
||||
MenuItem,
|
||||
dialog,
|
||||
ipcMain,
|
||||
clipboard,
|
||||
MenuItemConstructorOptions,
|
||||
@ -51,6 +50,7 @@ import {
|
||||
closeWindow,
|
||||
openAfterHideWindow,
|
||||
sendToWebContent,
|
||||
showMessageBoxSync,
|
||||
} from "../commons/index";
|
||||
|
||||
/**
|
||||
@ -411,13 +411,12 @@ export default function () {
|
||||
new MenuItem({
|
||||
label: global.language.delete,
|
||||
click: () => {
|
||||
let res = dialog.showMessageBoxSync(global.mainWindow, {
|
||||
message: global.language.deleteItemPrompt,
|
||||
buttons: [global.language.ok, global.language.cancel],
|
||||
type: "question",
|
||||
noLink: true,
|
||||
cancelId: 1,
|
||||
});
|
||||
let res = showMessageBoxSync(
|
||||
"mainWindow",
|
||||
global.language.deleteItemPrompt,
|
||||
"question",
|
||||
[global.language.ok, global.language.cancel]
|
||||
);
|
||||
if (res === 0) {
|
||||
// 删除数据
|
||||
del(item.id);
|
||||
@ -553,13 +552,12 @@ export default function () {
|
||||
new MenuItem({
|
||||
label: global.language.batchDelete,
|
||||
click: () => {
|
||||
let res = dialog.showMessageBoxSync(global.mainWindow, {
|
||||
message: global.language.batchDeletePrompt,
|
||||
buttons: [global.language.ok, global.language.cancel],
|
||||
type: "question",
|
||||
noLink: true,
|
||||
cancelId: 1,
|
||||
});
|
||||
let res = showMessageBoxSync(
|
||||
"mainWindow",
|
||||
global.language.batchDeletePrompt,
|
||||
"question",
|
||||
[global.language.ok, global.language.cancel]
|
||||
);
|
||||
if (res === 0) {
|
||||
for (const id of batchSelectedIdList) {
|
||||
// 删除数据
|
||||
|
@ -121,7 +121,10 @@ function createMainWindow() {
|
||||
!global.setting.general.alwaysTop
|
||||
) {
|
||||
// 如果当前还有打开的子窗口就不执行失去焦点隐藏
|
||||
if (mainWindow.getChildWindows().length === 0) {
|
||||
if (
|
||||
mainWindow.getChildWindows().length === 0 &&
|
||||
!global.mainWindowShowDialog
|
||||
) {
|
||||
hideMainWindow();
|
||||
}
|
||||
}
|
||||
@ -472,7 +475,7 @@ function autoHide(size: number, timer: boolean) {
|
||||
return;
|
||||
}
|
||||
// 当有子窗口时不自动隐藏
|
||||
if (mainWindow.getChildWindows().length > 0) {
|
||||
if (mainWindow.getChildWindows().length > 0 || global.mainWindowShowDialog) {
|
||||
return;
|
||||
}
|
||||
let x = screen.getCursorScreenPoint().x;
|
||||
|
@ -1,9 +1,10 @@
|
||||
import { app, dialog, ipcMain } from "electron";
|
||||
import { app, ipcMain } from "electron";
|
||||
import {
|
||||
closeWindow,
|
||||
getUserDataPath,
|
||||
relaunch,
|
||||
sendToWebContent,
|
||||
showOpenDialogSync,
|
||||
} from "../commons/index";
|
||||
import { createSettingWindow, setFixedPosition, setShortcutKey } from ".";
|
||||
import { add, select, update } from "./data";
|
||||
@ -114,7 +115,7 @@ export default function () {
|
||||
// 上传背景图
|
||||
ipcMain.on("uploadBackgrounImage", (event, args) => {
|
||||
// 打开文件对话框
|
||||
let filePathList = dialog.showOpenDialogSync(global.settingWindow, {
|
||||
let filePathList = showOpenDialogSync("settingWindow", {
|
||||
filters: [
|
||||
{
|
||||
name: "Images",
|
||||
|
2
electron/types/global.d.ts
vendored
2
electron/types/global.d.ts
vendored
@ -57,6 +57,8 @@ declare global {
|
||||
var classificationRightMenu: boolean | null;
|
||||
// 项目右键菜单显示
|
||||
var itemRightMenu: boolean | null;
|
||||
// 存储主窗口当前是否有弹出对话框
|
||||
var mainWindowShowDialog: boolean;
|
||||
}
|
||||
|
||||
export interface ChildProcessInfo {
|
||||
|
Loading…
Reference in New Issue
Block a user