Skip to content

Commit

Permalink
fix: settings window fails to appear front in SwiftUI
Browse files Browse the repository at this point in the history
  • Loading branch information
phlpsong committed Feb 3, 2024
1 parent b559959 commit 6117800
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
17 changes: 17 additions & 0 deletions Easydict.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand Down Expand Up @@ -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 */,
Expand Down Expand Up @@ -2463,6 +2465,7 @@
EA3B81FB2B52555C004C0E8B /* Defaults */,
967712E92B5B913600105E0F /* KeyHolder */,
03022F182B3591AE00B63209 /* GoogleGenerativeAI */,
0AC8A84E2B6DFDD4006DA5CC /* SettingsAccess */,
);
productName = Bob;
productReference = C99EEB182385796700FEE666 /* Easydict-debug.app */;
Expand Down Expand Up @@ -2524,6 +2527,7 @@
EA3B81FA2B52555C004C0E8B /* XCRemoteSwiftPackageReference "Defaults" */,
967712E82B5B913600105E0F /* XCRemoteSwiftPackageReference "KeyHolder" */,
03022F172B3591AE00B63209 /* XCRemoteSwiftPackageReference "generative-ai-swift" */,
0AC8A84D2B6DFDD4006DA5CC /* XCRemoteSwiftPackageReference "SettingsAccess" */,
);
productRefGroup = C99EEB192385796700FEE666 /* Products */;
projectDirPath = "";
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -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" */;
Expand Down
9 changes: 9 additions & 0 deletions Easydict.xcworkspace/xcshareddata/swiftpm/Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
10 changes: 9 additions & 1 deletion Easydict/NewApp/View/MenuItemView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
// Copyright © 2023 izual. All rights reserved.
//

import SettingsAccess
import Sparkle
import SwiftUI
import ZipArchive
Expand All @@ -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 等还是能正常显示的。
Expand Down Expand Up @@ -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("打开设置")
Expand Down

0 comments on commit 6117800

Please sign in to comment.