mirror of
https://github.com/fanchenio/DawnLauncher.git
synced 2025-07-13 21:02:10 +08:00
修复程序在某些情况崩溃的问题。
This commit is contained in:
parent
d4520eef0c
commit
018bd91931
@ -561,6 +561,13 @@ function showOpenDialogSync(windowName: string, options: OpenDialogOptions) {
|
|||||||
return pathList;
|
return pathList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 窗口是否存在
|
||||||
|
*/
|
||||||
|
function mainWindowExist() {
|
||||||
|
return global.mainWindow && !global.mainWindow.isDestroyed();
|
||||||
|
}
|
||||||
|
|
||||||
export {
|
export {
|
||||||
downloadImage,
|
downloadImage,
|
||||||
getURLInfo,
|
getURLInfo,
|
||||||
@ -580,4 +587,5 @@ export {
|
|||||||
showErrorMessageBox,
|
showErrorMessageBox,
|
||||||
showSaveDialogSync,
|
showSaveDialogSync,
|
||||||
showOpenDialogSync,
|
showOpenDialogSync,
|
||||||
|
mainWindowExist,
|
||||||
};
|
};
|
||||||
|
@ -13,6 +13,7 @@ import cacheData from "../commons/cacheData";
|
|||||||
import {
|
import {
|
||||||
getMainBackgorunColor,
|
getMainBackgorunColor,
|
||||||
getWindowInScreen,
|
getWindowInScreen,
|
||||||
|
mainWindowExist,
|
||||||
sendToWebContent,
|
sendToWebContent,
|
||||||
} from "../commons";
|
} from "../commons";
|
||||||
import { release } from "node:os";
|
import { release } from "node:os";
|
||||||
@ -236,12 +237,13 @@ function createMainWindow() {
|
|||||||
*/
|
*/
|
||||||
function onBlurHide() {
|
function onBlurHide() {
|
||||||
if (
|
if (
|
||||||
mainWindow.isVisible() &&
|
mainWindowExist() &&
|
||||||
|
global.mainWindow.isVisible() &&
|
||||||
global.setting.general.hideLoseFocus &&
|
global.setting.general.hideLoseFocus &&
|
||||||
!global.setting.general.alwaysTop &&
|
!global.setting.general.alwaysTop &&
|
||||||
mainWindow.getChildWindows().length === 0 &&
|
global.mainWindow.getChildWindows().length === 0 &&
|
||||||
!global.mainWindowShowDialog &&
|
!global.mainWindowShowDialog &&
|
||||||
!hasCursorPosWindow(mainWindow)
|
!hasCursorPosWindow(global.mainWindow)
|
||||||
) {
|
) {
|
||||||
// 隐藏窗口
|
// 隐藏窗口
|
||||||
hideMainWindow();
|
hideMainWindow();
|
||||||
@ -299,6 +301,9 @@ function showMainWindowBefore(
|
|||||||
* @param autoHide
|
* @param autoHide
|
||||||
*/
|
*/
|
||||||
function showMainWindow(blurHide: boolean, autoHide = false) {
|
function showMainWindow(blurHide: boolean, autoHide = false) {
|
||||||
|
if (!mainWindowExist()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
// flag
|
// flag
|
||||||
let flag = true;
|
let flag = true;
|
||||||
// 是否开启勿扰模式
|
// 是否开启勿扰模式
|
||||||
@ -313,12 +318,12 @@ function showMainWindow(blurHide: boolean, autoHide = false) {
|
|||||||
}
|
}
|
||||||
if (flag) {
|
if (flag) {
|
||||||
if (!global.setting.general.alwaysTop) {
|
if (!global.setting.general.alwaysTop) {
|
||||||
mainWindow.setAlwaysOnTop(true, "screen-saver");
|
global.mainWindow.setAlwaysOnTop(true, "screen-saver");
|
||||||
}
|
}
|
||||||
global.mainWindow.show();
|
global.mainWindow.show();
|
||||||
global.mainWindow.focus();
|
global.mainWindow.focus();
|
||||||
if (!global.setting.general.alwaysTop) {
|
if (!global.setting.general.alwaysTop) {
|
||||||
mainWindow.setAlwaysOnTop(false);
|
global.mainWindow.setAlwaysOnTop(false);
|
||||||
}
|
}
|
||||||
global.blurHide = blurHide;
|
global.blurHide = blurHide;
|
||||||
}
|
}
|
||||||
@ -328,7 +333,7 @@ function showMainWindow(blurHide: boolean, autoHide = false) {
|
|||||||
* 隐藏窗口
|
* 隐藏窗口
|
||||||
*/
|
*/
|
||||||
function hideMainWindow() {
|
function hideMainWindow() {
|
||||||
if (global.mainWindow.isVisible()) {
|
if (mainWindowExist() && global.mainWindow.isVisible()) {
|
||||||
global.mainWindow.hide();
|
global.mainWindow.hide();
|
||||||
global.blurHide = false;
|
global.blurHide = false;
|
||||||
}
|
}
|
||||||
@ -389,10 +394,13 @@ function createTray(show: boolean) {
|
|||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
function edgeAdsorb(display: Display | null, workArea = false) {
|
function edgeAdsorb(display: Display | null, workArea = false) {
|
||||||
|
if (!mainWindowExist()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
// 如果勾选停靠在桌面边缘时自动隐藏,放行
|
// 如果勾选停靠在桌面边缘时自动隐藏,放行
|
||||||
if (
|
if (
|
||||||
global.mainWindow.isDestroyed() ||
|
!global.setting.general.edgeAdsorb &&
|
||||||
(!global.setting.general.edgeAdsorb && !global.setting.general.edgeAutoHide)
|
!global.setting.general.edgeAutoHide
|
||||||
) {
|
) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -400,7 +408,7 @@ function edgeAdsorb(display: Display | null, workArea = false) {
|
|||||||
// 清空方向
|
// 清空方向
|
||||||
global.mainWindowDirection = null;
|
global.mainWindowDirection = null;
|
||||||
// 屏幕
|
// 屏幕
|
||||||
let displays = display ? [display] : getWindowInScreen(mainWindow);
|
let displays = display ? [display] : getWindowInScreen(global.mainWindow);
|
||||||
if (displays.length > 1 || displays.length === 0) {
|
if (displays.length > 1 || displays.length === 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -489,6 +497,9 @@ function edgeAdsorb(display: Display | null, workArea = false) {
|
|||||||
* 显示时跟随鼠标位置
|
* 显示时跟随鼠标位置
|
||||||
*/
|
*/
|
||||||
function showFollowMousePosition() {
|
function showFollowMousePosition() {
|
||||||
|
if (!mainWindowExist()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
// 当永远居中、固定位置勾选后不能使用显示时跟随鼠标位置
|
// 当永远居中、固定位置勾选后不能使用显示时跟随鼠标位置
|
||||||
if (
|
if (
|
||||||
!global.setting.general.alwaysCenter &&
|
!global.setting.general.alwaysCenter &&
|
||||||
@ -519,6 +530,9 @@ function showFollowMousePosition() {
|
|||||||
* 中间单击显示/隐藏窗口
|
* 中间单击显示/隐藏窗口
|
||||||
*/
|
*/
|
||||||
function showHideMouseWheelClick() {
|
function showHideMouseWheelClick() {
|
||||||
|
if (!mainWindowExist()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (global.setting.general.showHideMouseWheelClick) {
|
if (global.setting.general.showHideMouseWheelClick) {
|
||||||
if (global.mainWindow.isVisible()) {
|
if (global.mainWindow.isVisible()) {
|
||||||
hideMainWindow();
|
hideMainWindow();
|
||||||
@ -532,8 +546,11 @@ function showHideMouseWheelClick() {
|
|||||||
* 永远居中
|
* 永远居中
|
||||||
*/
|
*/
|
||||||
function alwaysCenter() {
|
function alwaysCenter() {
|
||||||
|
if (!mainWindowExist()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (global.setting.general.alwaysCenter) {
|
if (global.setting.general.alwaysCenter) {
|
||||||
mainWindow.center();
|
global.mainWindow.center();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -544,26 +561,32 @@ function alwaysCenter() {
|
|||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
function autoHide(size: number, timer: boolean) {
|
function autoHide(size: number, timer: boolean) {
|
||||||
if (global.mainWindow.isDestroyed() || !global.setting.general.edgeAutoHide) {
|
if (!mainWindowExist()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!global.setting.general.edgeAutoHide) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// 当有子窗口时不自动隐藏
|
// 当有子窗口时不自动隐藏
|
||||||
if (mainWindow.getChildWindows().length > 0 || global.mainWindowShowDialog) {
|
if (
|
||||||
|
global.mainWindow.getChildWindows().length > 0 ||
|
||||||
|
global.mainWindowShowDialog
|
||||||
|
) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let x = screen.getCursorScreenPoint().x;
|
let x = screen.getCursorScreenPoint().x;
|
||||||
let y = screen.getCursorScreenPoint().y;
|
let y = screen.getCursorScreenPoint().y;
|
||||||
try {
|
try {
|
||||||
// 屏幕
|
// 屏幕
|
||||||
let displays = getWindowInScreen(mainWindow);
|
let displays = getWindowInScreen(global.mainWindow);
|
||||||
if (displays.length > 1 || displays.length === 0) {
|
if (displays.length > 1 || displays.length === 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// 屏幕区域
|
// 屏幕区域
|
||||||
let displayBounds = displays[0].bounds;
|
let displayBounds = displays[0].bounds;
|
||||||
// 窗口位置信息
|
// 窗口位置信息
|
||||||
let bounds = mainWindow.getBounds();
|
let bounds = global.mainWindow.getBounds();
|
||||||
if (mainWindow.isVisible()) {
|
if (global.mainWindow.isVisible()) {
|
||||||
let flag = false;
|
let flag = false;
|
||||||
if (bounds.x === displayBounds.x && bounds.y === displayBounds.y) {
|
if (bounds.x === displayBounds.x && bounds.y === displayBounds.y) {
|
||||||
// 左上角
|
// 左上角
|
||||||
@ -738,12 +761,15 @@ function doubleClickTaskbar(
|
|||||||
mousedownClassName: string | null,
|
mousedownClassName: string | null,
|
||||||
className: string | null
|
className: string | null
|
||||||
) {
|
) {
|
||||||
|
if (!mainWindowExist()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
// 必须开启设置
|
// 必须开启设置
|
||||||
if (!global.setting.general.showHideDoubleClickTaskbar) {
|
if (!global.setting.general.showHideDoubleClickTaskbar) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// 获取屏幕
|
// 获取屏幕
|
||||||
let displays = getWindowInScreen(mainWindow);
|
let displays = getWindowInScreen(global.mainWindow);
|
||||||
if (
|
if (
|
||||||
displays.length > 1 ||
|
displays.length > 1 ||
|
||||||
displays.length === 0 ||
|
displays.length === 0 ||
|
||||||
@ -779,7 +805,7 @@ function doubleClickTaskbar(
|
|||||||
// 清空计数
|
// 清空计数
|
||||||
global.doubleClickTaskbarCounter = 0;
|
global.doubleClickTaskbarCounter = 0;
|
||||||
// 显示或隐藏
|
// 显示或隐藏
|
||||||
if (mainWindow.isVisible()) {
|
if (global.mainWindow.isVisible()) {
|
||||||
hideMainWindow();
|
hideMainWindow();
|
||||||
} else {
|
} else {
|
||||||
showMainWindowBefore(false);
|
showMainWindowBefore(false);
|
||||||
|
@ -5,7 +5,11 @@ import { hideMainWindow, showMainWindowBefore } from "../main/index";
|
|||||||
import { list as selectClassificationList } from "../classification/data";
|
import { list as selectClassificationList } from "../classification/data";
|
||||||
import { list as selectItemList } from "../item/data";
|
import { list as selectItemList } from "../item/data";
|
||||||
import { run } from "../item";
|
import { run } from "../item";
|
||||||
import { closeWindow, getMainBackgorunColor } from "../commons/index";
|
import {
|
||||||
|
closeWindow,
|
||||||
|
getMainBackgorunColor,
|
||||||
|
mainWindowExist,
|
||||||
|
} from "../commons/index";
|
||||||
import {
|
import {
|
||||||
createQuickSearchWindow,
|
createQuickSearchWindow,
|
||||||
hideQuickSearchWindow,
|
hideQuickSearchWindow,
|
||||||
@ -83,10 +87,12 @@ function setShortcutKey(setting: Setting = global.setting) {
|
|||||||
globalShortcut.register(
|
globalShortcut.register(
|
||||||
setting.general.showHideShortcutKey.replace("Win", "Super"),
|
setting.general.showHideShortcutKey.replace("Win", "Super"),
|
||||||
() => {
|
() => {
|
||||||
if (global.mainWindow.isVisible()) {
|
if (mainWindowExist()) {
|
||||||
hideMainWindow();
|
if (global.mainWindow.isVisible()) {
|
||||||
} else {
|
hideMainWindow();
|
||||||
showMainWindowBefore(true);
|
} else {
|
||||||
|
showMainWindowBefore(true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@ -104,8 +110,10 @@ function setShortcutKey(setting: Setting = global.setting) {
|
|||||||
globalShortcut.register(
|
globalShortcut.register(
|
||||||
classification.shortcutKey.replace("Win", "Super"),
|
classification.shortcutKey.replace("Win", "Super"),
|
||||||
() => {
|
() => {
|
||||||
// 分类
|
if (mainWindowExist()) {
|
||||||
showMainWindowBefore(true, false, classification.id);
|
// 分类
|
||||||
|
showMainWindowBefore(true, false, classification.id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@ -123,17 +131,19 @@ function setShortcutKey(setting: Setting = global.setting) {
|
|||||||
globalShortcut.register(
|
globalShortcut.register(
|
||||||
item.shortcutKey.replace("Win", "Super"),
|
item.shortcutKey.replace("Win", "Super"),
|
||||||
() => {
|
() => {
|
||||||
// flag
|
if (mainWindowExist()) {
|
||||||
let flag = true;
|
// flag
|
||||||
// 是否开启勿扰模式
|
let flag = true;
|
||||||
if (global.setting.general.notDisturb) {
|
// 是否开启勿扰模式
|
||||||
if (global.addon.isFullscreen()) {
|
if (global.setting.general.notDisturb) {
|
||||||
flag = false;
|
if (global.addon.isFullscreen()) {
|
||||||
|
flag = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (flag) {
|
||||||
|
// 项目
|
||||||
|
run("main", "open", item);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if (flag) {
|
|
||||||
// 项目
|
|
||||||
run("main", "open", item);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
Loading…
Reference in New Issue
Block a user