-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Rename action name. - Define Mac-specific action.
- Loading branch information
Showing
6 changed files
with
71 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 0 additions & 46 deletions
46
src/App/Views/Utils/EnvironmentValues+PresentSettingsSheetAction.swift
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
import class MonsterAnalyzerCore.Settings | ||
import SwiftUI | ||
|
||
struct SettingsEnvironmentKey: EnvironmentKey { | ||
private struct _SettingsEnvironmentKey: EnvironmentKey { | ||
static var defaultValue: MonsterAnalyzerCore.Settings? = nil | ||
} | ||
|
||
extension EnvironmentValues { | ||
var settings: MonsterAnalyzerCore.Settings? { | ||
get { self[SettingsEnvironmentKey.self] } | ||
set { self[SettingsEnvironmentKey.self] = newValue } | ||
get { self[_SettingsEnvironmentKey.self] } | ||
set { self[_SettingsEnvironmentKey.self] = newValue } | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
src/App/Views/Utils/EnvironmentValues+ShowSettingsAction.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import SwiftUI | ||
|
||
public protocol ShowSettingsAction { | ||
func callAsFunction() | ||
} | ||
|
||
#if os(macOS) | ||
|
||
private struct _MacShowSettingsAction: ShowSettingsAction { | ||
func callAsFunction() { | ||
if #available(macOS 13.0, *) { | ||
NSApp.sendAction(Selector(("showSettingsWindow:")), to: nil, from: nil) | ||
} else { | ||
NSApp.sendAction(Selector(("showPreferencesWindow:")), to: nil, from: nil) | ||
} | ||
} | ||
} | ||
|
||
#else | ||
|
||
private struct _ShowSettingsActionImpl: ShowSettingsAction { | ||
@Binding | ||
private(set) var isPresented: Bool | ||
|
||
func callAsFunction() { | ||
isPresented = true | ||
} | ||
} | ||
|
||
@available(macOS, unavailable) | ||
public extension View { | ||
func setShowSettings(isPresented: Binding<Bool>) -> some View { | ||
environment(\.showSettings, _ShowSettingsActionImpl(isPresented: isPresented)) | ||
} | ||
} | ||
|
||
private struct _ShowSettingsNoAction: ShowSettingsAction { | ||
func callAsFunction() {} | ||
} | ||
|
||
#endif | ||
|
||
private struct _ShowSettingsActionKey: EnvironmentKey { | ||
static var defaultValue: ShowSettingsAction { | ||
#if os(macOS) | ||
_MacShowSettingsAction() | ||
#else | ||
_ShowSettingsNoAction() | ||
#endif | ||
} | ||
} | ||
|
||
public extension EnvironmentValues { | ||
var showSettings: ShowSettingsAction { | ||
get { self[_ShowSettingsActionKey.self] } | ||
set { self[_ShowSettingsActionKey.self] = newValue } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters