From 6ac55b8462ea865ec44d59144cfe8ed3d30cab48 Mon Sep 17 00:00:00 2001 From: yanue Date: Sat, 14 Oct 2023 19:17:23 +0800 Subject: [PATCH] makeToast --- V2rayU/ToastWindow.swift | 17 +++++++++-------- V2rayU/V2rayLaunch.swift | 1 + 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/V2rayU/ToastWindow.swift b/V2rayU/ToastWindow.swift index ede44a1..f08ed43 100644 --- a/V2rayU/ToastWindow.swift +++ b/V2rayU/ToastWindow.swift @@ -8,16 +8,17 @@ import Cocoa -var toastWindowCtrl = ToastWindowController() +var toastWindow = ToastWindowController() -func makeToast(message: String, displayDuration: Double? = 2) { +func makeToast(message: String, displayDuration: Double? = 3) { print("makeToast", message) - toastWindowCtrl.close() - toastWindowCtrl = ToastWindowController() - toastWindowCtrl.message = message - toastWindowCtrl.showWindow(nil) - toastWindowCtrl.becomeFirstResponder() - toastWindowCtrl.fadeInHud(displayDuration) + toastWindow.close() + toastWindow = ToastWindowController() + toastWindow.message = message + toastWindow.showWindow(Any.self) + toastWindow.fadeInHud(displayDuration) + + NSApp.activate(ignoringOtherApps: true) } func alertDialog(title: String, message: String) -> Bool { diff --git a/V2rayU/V2rayLaunch.swift b/V2rayU/V2rayLaunch.swift index b140cf2..e921a58 100644 --- a/V2rayU/V2rayLaunch.swift +++ b/V2rayU/V2rayLaunch.swift @@ -291,6 +291,7 @@ class V2rayLaunch: NSObject { return true } else { NSLog("Start v2ray-core failed.") + makeToast(message: "Start v2ray-core failed.") return false } }