From 6117800b4c45789c73b431c9d59d86210754594f Mon Sep 17 00:00:00 2001 From: phlpsong Date: Sat, 3 Feb 2024 13:29:53 +0800 Subject: [PATCH] fix: settings window fails to appear front in SwiftUI --- Easydict.xcodeproj/project.pbxproj | 17 +++++++++++++++++ .../xcshareddata/swiftpm/Package.resolved | 9 +++++++++ Easydict/NewApp/View/MenuItemView.swift | 10 +++++++++- 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/Easydict.xcodeproj/project.pbxproj b/Easydict.xcodeproj/project.pbxproj index 9e8730358..12acca6f2 100644 --- a/Easydict.xcodeproj/project.pbxproj +++ b/Easydict.xcodeproj/project.pbxproj @@ -238,6 +238,7 @@ 0A8685C82B552A590022534F /* DisabledAppTab.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A8685C72B552A590022534F /* DisabledAppTab.swift */; }; 0AC11B222B4D16A500F07198 /* WindowAccessor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0AC11B212B4D16A500F07198 /* WindowAccessor.swift */; }; 0AC11B242B4E46B300F07198 /* TapHandlerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0AC11B232B4E46B300F07198 /* TapHandlerView.swift */; }; + 0AC8A84F2B6DFDD4006DA5CC /* SettingsAccess in Frameworks */ = {isa = PBXBuildFile; productRef = 0AC8A84E2B6DFDD4006DA5CC /* SettingsAccess */; }; 17BCAEF72B0DFF9000A7D372 /* EZNiuTransTranslateResponse.m in Sources */ = {isa = PBXBuildFile; fileRef = 17BCAEF52B0DFF9000A7D372 /* EZNiuTransTranslateResponse.m */; }; 17BCAEF82B0DFF9000A7D372 /* EZNiuTransTranslate.m in Sources */ = {isa = PBXBuildFile; fileRef = 17BCAEF62B0DFF9000A7D372 /* EZNiuTransTranslate.m */; }; 2721E4D02AFE920700A059AC /* Alamofire in Frameworks */ = {isa = PBXBuildFile; productRef = 2721E4CF2AFE920700A059AC /* Alamofire */; }; @@ -826,6 +827,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + 0AC8A84F2B6DFDD4006DA5CC /* SettingsAccess in Frameworks */, 03022F192B3591AE00B63209 /* GoogleGenerativeAI in Frameworks */, 2721E4D02AFE920700A059AC /* Alamofire in Frameworks */, 03022F1F2B36CF3100B63209 /* SwiftShell in Frameworks */, @@ -2463,6 +2465,7 @@ EA3B81FB2B52555C004C0E8B /* Defaults */, 967712E92B5B913600105E0F /* KeyHolder */, 03022F182B3591AE00B63209 /* GoogleGenerativeAI */, + 0AC8A84E2B6DFDD4006DA5CC /* SettingsAccess */, ); productName = Bob; productReference = C99EEB182385796700FEE666 /* Easydict-debug.app */; @@ -2524,6 +2527,7 @@ EA3B81FA2B52555C004C0E8B /* XCRemoteSwiftPackageReference "Defaults" */, 967712E82B5B913600105E0F /* XCRemoteSwiftPackageReference "KeyHolder" */, 03022F172B3591AE00B63209 /* XCRemoteSwiftPackageReference "generative-ai-swift" */, + 0AC8A84D2B6DFDD4006DA5CC /* XCRemoteSwiftPackageReference "SettingsAccess" */, ); productRefGroup = C99EEB192385796700FEE666 /* Products */; projectDirPath = ""; @@ -3512,6 +3516,14 @@ minimumVersion = 1.8.0; }; }; + 0AC8A84D2B6DFDD4006DA5CC /* XCRemoteSwiftPackageReference "SettingsAccess" */ = { + isa = XCRemoteSwiftPackageReference; + repositoryURL = "https://github.com/orchetect/SettingsAccess"; + requirement = { + kind = upToNextMajorVersion; + minimumVersion = 1.4.0; + }; + }; 2721E4CE2AFE920700A059AC /* XCRemoteSwiftPackageReference "Alamofire" */ = { isa = XCRemoteSwiftPackageReference; repositoryURL = "https://github.com/Alamofire/Alamofire.git"; @@ -3614,6 +3626,11 @@ package = 03FD68B92B1DC59600FD388E /* XCRemoteSwiftPackageReference "CryptoSwift" */; productName = CryptoSwift; }; + 0AC8A84E2B6DFDD4006DA5CC /* SettingsAccess */ = { + isa = XCSwiftPackageProductDependency; + package = 0AC8A84D2B6DFDD4006DA5CC /* XCRemoteSwiftPackageReference "SettingsAccess" */; + productName = SettingsAccess; + }; 2721E4CF2AFE920700A059AC /* Alamofire */ = { isa = XCSwiftPackageProductDependency; package = 2721E4CE2AFE920700A059AC /* XCRemoteSwiftPackageReference "Alamofire" */; diff --git a/Easydict.xcworkspace/xcshareddata/swiftpm/Package.resolved b/Easydict.xcworkspace/xcshareddata/swiftpm/Package.resolved index 0d2cecd07..6e22eb216 100644 --- a/Easydict.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/Easydict.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -234,6 +234,15 @@ "version" : "2.4.0" } }, + { + "identity" : "settingsaccess", + "kind" : "remoteSourceControl", + "location" : "https://github.com/orchetect/SettingsAccess", + "state" : { + "revision" : "0fd73c8b5892e88acb13adb7f36a4ba9293a0061", + "version" : "1.4.0" + } + }, { "identity" : "snapkit", "kind" : "remoteSourceControl", diff --git a/Easydict/NewApp/View/MenuItemView.swift b/Easydict/NewApp/View/MenuItemView.swift index 2c5a6aca4..1c61b366a 100644 --- a/Easydict/NewApp/View/MenuItemView.swift +++ b/Easydict/NewApp/View/MenuItemView.swift @@ -6,6 +6,7 @@ // Copyright © 2023 izual. All rights reserved. // +import SettingsAccess import Sparkle import SwiftUI import ZipArchive @@ -24,6 +25,7 @@ final class MenuItemStore: ObservableObject { @available(macOS 13, *) struct MenuItemView: View { @ObservedObject private var store = MenuItemStore() + @Environment(\.openSettings) private var openSettings var body: some View { // ️.menuBarExtraStyle为 .menu 时某些控件可能会失效 ,只能显示内容(按照菜单项高度、图像以 template 方式渲染)无法交互 ,比如 Stepper、Slider 等,像基本的 Button、Text、Divider、Image 等还是能正常显示的。 @@ -92,7 +94,13 @@ struct MenuItemView: View { @ViewBuilder private var settingItem: some View { if #available(macOS 14.0, *) { - SettingsLink() + SettingsLink { + Text("Settings...") + } preAction: { + NSApp.activate(ignoringOtherApps: true) + } postAction: { + // nothing to do + } } else { Button("Settings...") { NSLog("打开设置")