Skip to content

Commit

Permalink
Fixes settings window on leatest macOS, also support running on older…
Browse files Browse the repository at this point in the history
… OS (#10)
  • Loading branch information
lkebin authored Dec 13, 2023
1 parent 710e840 commit 07c6c6d
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 40 deletions.
22 changes: 15 additions & 7 deletions GostX.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

/* Begin PBXBuildFile section */
B523FCA529E169180050578C /* HighlightedTextEditor in Frameworks */ = {isa = PBXBuildFile; productRef = B523FCA429E169180050578C /* HighlightedTextEditor */; };
B532A66A285B528900159BAC /* GostXApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = B532A669285B528900159BAC /* GostXApp.swift */; };
B532A66A285B528900159BAC /* main.swift in Sources */ = {isa = PBXBuildFile; fileRef = B532A669285B528900159BAC /* main.swift */; };
B532A66E285B528D00159BAC /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = B532A66D285B528D00159BAC /* Assets.xcassets */; };
B532A671285B528D00159BAC /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = B532A670285B528D00159BAC /* Preview Assets.xcassets */; };
B532A67C285B528D00159BAC /* GostXTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B532A67B285B528D00159BAC /* GostXTests.swift */; };
Expand Down Expand Up @@ -40,7 +40,7 @@

/* Begin PBXFileReference section */
B532A666285B528900159BAC /* GostX.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = GostX.app; sourceTree = BUILT_PRODUCTS_DIR; };
B532A669285B528900159BAC /* GostXApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GostXApp.swift; sourceTree = "<group>"; };
B532A669285B528900159BAC /* main.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = main.swift; sourceTree = "<group>"; };
B532A66D285B528D00159BAC /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
B532A670285B528D00159BAC /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = "<group>"; };
B532A672285B528D00159BAC /* GostX.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = GostX.entitlements; sourceTree = "<group>"; };
Expand Down Expand Up @@ -108,7 +108,7 @@
isa = PBXGroup;
children = (
B5C1CF1629DD6E7C008AA934 /* Localizable.stringsdict */,
B532A669285B528900159BAC /* GostXApp.swift */,
B532A669285B528900159BAC /* main.swift */,
B532A66D285B528D00159BAC /* Assets.xcassets */,
B532A672285B528D00159BAC /* GostX.entitlements */,
B532A66F285B528D00159BAC /* Preview Content */,
Expand Down Expand Up @@ -219,7 +219,7 @@
attributes = {
BuildIndependentTargetsInParallel = 1;
LastSwiftUpdateCheck = 1340;
LastUpgradeCheck = 1340;
LastUpgradeCheck = 1430;
TargetAttributes = {
B532A665285B528900159BAC = {
CreatedOnToolsVersion = 13.4.1;
Expand Down Expand Up @@ -294,7 +294,7 @@
B5AEDDB12864920800C09ED6 /* AppDelegate.swift in Sources */,
B5B0E07A285C63080035A6F2 /* SettingsView.swift in Sources */,
B5B0E074285B62B80035A6F2 /* MacExtrasConfigurator.swift in Sources */,
B532A66A285B528900159BAC /* GostXApp.swift in Sources */,
B532A66A285B528900159BAC /* main.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -377,6 +377,7 @@
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
COPY_PHASE_STRIP = NO;
DEAD_CODE_STRIPPING = YES;
DEBUG_INFORMATION_FORMAT = dwarf;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
Expand Down Expand Up @@ -438,6 +439,7 @@
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
COPY_PHASE_STRIP = NO;
DEAD_CODE_STRIPPING = YES;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
Expand Down Expand Up @@ -468,9 +470,10 @@
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 1;
DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_ASSET_PATHS = "\"GostX/Preview Content\"";
DEVELOPMENT_TEAM = "";
ENABLE_HARDENED_RUNTIME = YES;
ENABLE_HARDENED_RUNTIME = NO;
ENABLE_PREVIEWS = YES;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = GostX/Info.plist;
Expand Down Expand Up @@ -518,9 +521,10 @@
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 1;
DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_ASSET_PATHS = "\"GostX/Preview Content\"";
DEVELOPMENT_TEAM = "";
ENABLE_HARDENED_RUNTIME = YES;
ENABLE_HARDENED_RUNTIME = NO;
ENABLE_PREVIEWS = YES;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = GostX/Info.plist;
Expand Down Expand Up @@ -565,6 +569,7 @@
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "-";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_TEAM = "";
GENERATE_INFOPLIST_FILE = YES;
MACOSX_DEPLOYMENT_TARGET = 12.3;
Expand All @@ -584,6 +589,7 @@
BUNDLE_LOADER = "$(TEST_HOST)";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_TEAM = "";
GENERATE_INFOPLIST_FILE = YES;
MACOSX_DEPLOYMENT_TARGET = 12.3;
Expand All @@ -602,6 +608,7 @@
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_TEAM = "";
GENERATE_INFOPLIST_FILE = YES;
MARKETING_VERSION = 1.0;
Expand All @@ -619,6 +626,7 @@
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_TEAM = "";
GENERATE_INFOPLIST_FILE = YES;
MARKETING_VERSION = 1.0;
Expand Down
2 changes: 1 addition & 1 deletion GostX.xcodeproj/xcshareddata/xcschemes/GostX.xcscheme
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1340"
LastUpgradeVersion = "1430"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
5 changes: 5 additions & 0 deletions GostX/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//

import SwiftUI
import Cocoa
import os
import Gost

Expand All @@ -31,6 +32,10 @@ class AppDelegate: NSObject, NSApplicationDelegate {
return false
}

func applicationSupportsSecureRestorableState(_ app: NSApplication) -> Bool {
return true
}

func quit() {
NSApp.terminate(self)
}
Expand Down
2 changes: 0 additions & 2 deletions GostX/GostX.entitlements
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
<dict>
<key>com.apple.security.app-sandbox</key>
<true/>
<key>com.apple.security.files.user-selected.read-only</key>
<true/>
<key>com.apple.security.network.client</key>
<true/>
<key>com.apple.security.network.server</key>
Expand Down
19 changes: 0 additions & 19 deletions GostX/GostXApp.swift

This file was deleted.

16 changes: 9 additions & 7 deletions GostX/MacExtrasConfigurator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class MacExtrasConfigurator: NSObject, NSMenuDelegate {
private var menu: NSMenu = NSMenu()
private var activeImg: NSImage? = NSImage(named: "StatusBarActive")
private var inActiveImg: NSImage? = NSImage(named: "StatusBarInactive")
private var settingsHostingController: NSHostingController<SettingsView>?

init(delegate: AppDelegate) {
self.delegate = delegate
Expand Down Expand Up @@ -82,7 +83,7 @@ class MacExtrasConfigurator: NSObject, NSMenuDelegate {
menu.addItem(.separator())

let configMenuItem = NSMenuItem()
configMenuItem.title = NSLocalizedString("Preferences...", comment: "")
configMenuItem.title = NSLocalizedString("Settings...", comment: "")
configMenuItem.image = NSImage(systemSymbolName: "gear", accessibilityDescription: "")
configMenuItem.keyEquivalent = ","
configMenuItem.keyEquivalentModifierMask = .command
Expand Down Expand Up @@ -116,12 +117,13 @@ class MacExtrasConfigurator: NSObject, NSMenuDelegate {
@objc private func onConfigClick(_ sender: Any?) {
NSApp.activate(ignoringOtherApps: true)
NSApp.setActivationPolicy(.regular)

if #available(macOS 13.0, *) {
NSApp.sendAction(Selector(("showSettingsWindow:")), to: nil, from: nil)
} else {
NSApp.sendAction(Selector(("showPreferencesWindow:")), to: nil, from: nil)
}

settingsHostingController = NSHostingController(rootView: SettingsView())
let window = NSWindow(contentViewController: settingsHostingController!)
window.title = Bundle.main.object(forInfoDictionaryKey: "CFBundleName") as? String ?? "Settings Window"
window.setContentSize(NSSize(width: 800, height: 400))
window.makeKeyAndOrderFront(nil)
window.orderFrontRegardless()
}

@objc private func onQuitClick(_ sender: Any?) {
Expand Down
4 changes: 2 additions & 2 deletions GostX/en.lproj/Localizable.stringsdict
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
<string>Note: value saved automatically, line of start with # symbol is ignored.</string>
<key>Arguments</key>
<string>Arguments</string>
<key>Preferences...</key>
<string>Preferences...</string>
<key>Settings...</key>
<string>Settings...</string>
<key>Quit</key>
<string>Quit</string>
<key>Stop</key>
Expand Down
7 changes: 7 additions & 0 deletions GostX/main.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import Foundation
import AppKit

let app = NSApplication.shared
let appDelegate = AppDelegate()
app.delegate = appDelegate
app.run()
2 changes: 1 addition & 1 deletion GostX/zh-Hans.lproj/Localizable.stringsdict
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<string>备注:参数将自动保存,以 # 开头的行将被忽略</string>
<key>Arguments</key>
<string>参数</string>
<key>Preferences...</key>
<key>Settings...</key>
<string>设置...</string>
<key>Quit</key>
<string>退出</string>
Expand Down
2 changes: 1 addition & 1 deletion go/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
GO := ${PWD}/build/go/bin/go
GO := $(PWD)/build/go/bin/go
TARGET_ARM64 := arm64-apple-macos11
TARGET_AMD64 := x86_64-apple-macos11

Expand Down

0 comments on commit 07c6c6d

Please sign in to comment.