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