Omit verbose @MainActor

This commit is contained in:
1024jp 2024-06-12 09:15:23 +09:00
parent b180902ab1
commit b19699294b
21 changed files with 43 additions and 49 deletions

View File

@ -114,9 +114,7 @@ private struct ColorCodePanelAccessory: View {
if let colorCode, let color = NSColor(colorCode: colorCode, type: &type), let type {
self.colorCode = colorCode
self.type = type.rawValue
Task { @MainActor in
panel.color = color
}
panel.color = color
}
}
@ -165,7 +163,7 @@ private struct ColorCodePanelAccessory: View {
// MARK: Private Methods
/// Inserts the color code to the selection of the frontmost document.
@MainActor private func submit() {
private func submit() {
self.apply(colorCode: self.colorCode)
@ -179,7 +177,7 @@ private struct ColorCodePanelAccessory: View {
/// Sets the color representing the given code to the color panel and selects the corresponding color code type.
///
/// - Parameter colorCode: The color code of the color to set.
@MainActor private func apply(colorCode: String) {
private func apply(colorCode: String) {
var type: ColorCodeType?
guard
@ -195,7 +193,7 @@ private struct ColorCodePanelAccessory: View {
/// Converts the color code to the specified code type.
///
/// - Parameter rawValue: The rawValue of ColorCodeType.
@MainActor private func apply(type rawValue: Int) {
private func apply(type rawValue: Int) {
guard
let type = ColorCodeType(rawValue: rawValue),

View File

@ -146,7 +146,7 @@ struct CommandBarView: View {
/// Performs the selected command and closes the view.
@MainActor private func perform() {
private func perform() {
// first close the command bar and then take the action
// so that the action is delivered to the correct (first) responder.

View File

@ -92,7 +92,7 @@ struct CustomSurroundView: View {
// MARK: Private Methods
/// Submits the current input.
@MainActor private func submit() {
private func submit() {
self.parent?.commitEditing()

View File

@ -73,7 +73,7 @@ struct CustomTabWidthView: View {
// MARK: Private Methods
/// Submits the current input.
@MainActor private func submit() {
private func submit() {
self.completionHandler(self.value)
self.parent?.dismiss(nil)

View File

@ -26,7 +26,7 @@
import SwiftUI
import StoreKit
@MainActor struct DonationSettingsView: View {
struct DonationSettingsView: View {
#if SPARKLE
var isInAppPurchaseAvailable = false
@ -210,7 +210,7 @@ private struct OnetimeProductViewStyle: ProductViewStyle {
.accessibilityLabel(String(localized: "Quantity", table: "DonationSettings", comment: "accessibility label for item quantity stepper"))
Spacer()
Button((product.price * Decimal(self.quantity)).formatted(product.priceFormatStyle)) {
Task { @MainActor in
Task {
do {
_ = try await self.purchase(product, options: [.quantity(self.quantity)])
} catch {

View File

@ -8,7 +8,7 @@
//
// ---------------------------------------------------------------------------
//
// © 2022-2023 1024jp
// © 2022-2024 1024jp
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@ -130,7 +130,7 @@ final class DraggableHostingView<Content>: NSHostingView<Content> where Content:
// MARK: Private Methods
/// The area the receiver located in the superview.
@MainActor private var preferredEdge: Edge? {
private var preferredEdge: Edge? {
self.superview.flatMap { superview in
Edge(horizontal: superview.frame.width/2 < self.frame.midX ? .right : .left,
@ -140,7 +140,7 @@ final class DraggableHostingView<Content>: NSHostingView<Content> where Content:
/// Keeps position to be inside of the parent frame.
@MainActor private func adjustPosition() {
private func adjustPosition() {
guard let superFrame = self.superview?.frame else { return assertionFailure() }

View File

@ -159,9 +159,7 @@ final class EditorTextViewController: NSViewController, NSServicesMenuRequestor,
super.restoreState(with: coder)
if coder.decodeBool(forKey: SerializationKey.showsAdvancedCounter) {
Task { @MainActor in
self.showAdvancedCharacterCounter()
}
self.showAdvancedCharacterCounter()
}
}

View File

@ -79,7 +79,7 @@ struct FindPanelButtonView: View {
/// Send a text finder action message to the legacy responder-chain.
///
/// - Parameter action: The `TextFinder.Action` to perform.
@MainActor private func performAction(_ action: TextFinder.Action) {
private func performAction(_ action: TextFinder.Action) {
// create a dummy sender for tag
let sender = NSControl()

View File

@ -240,7 +240,7 @@ final class FindPanelFieldViewController: NSViewController, NSTextViewDelegate {
/// Updates the result count in the input fields.
///
/// - Parameter result: The find/replace result or `nil` to clear.
@MainActor private func update(result: TextFindResult?) {
private func update(result: TextFindResult?) {
switch result {
case .found:
@ -257,14 +257,14 @@ final class FindPanelFieldViewController: NSViewController, NSTextViewDelegate {
/// Updates the find history menu.
@MainActor private func updateFindHistoryMenu() {
private func updateFindHistoryMenu() {
self.buildHistoryMenu(self.findHistoryMenu!, defaultsKey: .findHistory, action: #selector(selectFindHistory))
}
/// Updates the replace history menu.
@MainActor private func updateReplaceHistoryMenu() {
private func updateReplaceHistoryMenu() {
self.buildHistoryMenu(self.replaceHistoryMenu!, defaultsKey: .replaceHistory, action: #selector(selectReplaceHistory))
}
@ -276,7 +276,7 @@ final class FindPanelFieldViewController: NSViewController, NSTextViewDelegate {
/// - menu: The menu to update the content.
/// - key: The default key for the history.
/// - action: The action selector for menu items.
@MainActor private func buildHistoryMenu(_ menu: NSMenu, defaultsKey key: DefaultKey<[String]>, action: Selector) {
private func buildHistoryMenu(_ menu: NSMenu, defaultsKey key: DefaultKey<[String]>, action: Selector) {
assert(Thread.isMainThread)
@ -299,7 +299,7 @@ final class FindPanelFieldViewController: NSViewController, NSTextViewDelegate {
/// Updates the find result message on the input field.
///
/// - Parameter message: The message to display in the input field, or `nil` to clear.
@MainActor private func updateFoundMessage(_ message: String?) {
private func updateFoundMessage(_ message: String?) {
self.applyResult(message: message, textField: self.findResultField!, textView: self.findTextView!)
}
@ -308,7 +308,7 @@ final class FindPanelFieldViewController: NSViewController, NSTextViewDelegate {
/// Updates the replacement result message on the input field.
///
/// - Parameter message: The message to display in the input field, or `nil` to clear.
@MainActor private func updateReplacedMessage(_ message: String?) {
private func updateReplacedMessage(_ message: String?) {
self.applyResult(message: message, textField: self.replacementResultField!, textView: self.replacementTextView!)
}
@ -320,7 +320,7 @@ final class FindPanelFieldViewController: NSViewController, NSTextViewDelegate {
/// - message: The localized message to display.
/// - textField: The text field displaying the message.
/// - textView: The input text view where shows the message.
@MainActor private func applyResult(message: String?, textField: NSTextField, textView: NSTextView) {
private func applyResult(message: String?, textField: NSTextField, textView: NSTextView) {
textField.isHidden = (message == nil)
textField.stringValue = message ?? ""

View File

@ -38,7 +38,7 @@ final class FindPanelResultViewController: NSHostingController<FindPanelResultVi
}
@MainActor required dynamic init?(coder: NSCoder) {
required dynamic init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
@ -156,7 +156,7 @@ struct FindPanelResultView: View {
// MARK: Private Methods
@MainActor private var message: String {
private var message: String {
let documentName = self.model.target?.documentName ?? "Unknown" // This should never be nil.
@ -171,7 +171,7 @@ struct FindPanelResultView: View {
/// Selects the match in the target text view.
///
/// - Parameter id: The identifier of the match to select.
@MainActor private func selectMatch(_ id: Match.ID?) {
private func selectMatch(_ id: Match.ID?) {
// abandon if text becomes shorter than range to select
guard

View File

@ -69,7 +69,7 @@ struct GoToLineView: View {
// MARK: Private Methods
/// Submits the current input.
@MainActor private func submit() {
private func submit() {
guard
self.completionHandler(self.lineRange)

View File

@ -182,7 +182,7 @@ private extension IncompatibleCharactersView.Model {
///
/// - Returns: An array of Item.
/// - Throws: `CancellationError`
@MainActor private func scan() async throws -> [ValueRange<IncompatibleCharacter>] {
private func scan() async throws -> [ValueRange<IncompatibleCharacter>] {
assert(Thread.isMainThread)
@ -205,7 +205,7 @@ private extension IncompatibleCharactersView.Model {
/// Update markup in the editors.
///
/// - Parameter items: The new incompatible characters.
@MainActor private func updateMarkup(_ items: [ValueRange<IncompatibleCharacter>]) {
private func updateMarkup(_ items: [ValueRange<IncompatibleCharacter>]) {
if !self.items.isEmpty {
self.document?.textStorage.clearAllMarkup()

View File

@ -102,7 +102,7 @@ struct InconsistentLineEndingsView: View {
/// Selects correspondence range of the item in the editor.
///
/// - Parameter id: The `id` of the item to select.
@MainActor private func selectItem(id: Item.ID?) {
private func selectItem(id: Item.ID?) {
guard
let item = self.items[id: id],

View File

@ -35,7 +35,7 @@ extension NSTextView {
/// - inSelection: Whether find string only in selectedRanges.
/// - Returns: A result message.
/// - Throws: `CancellationError`
@MainActor final func highlight(_ definition: MultipleReplace, inSelection: Bool) async throws -> String {
final func highlight(_ definition: MultipleReplace, inSelection: Bool) async throws -> String {
self.isEditable = false
defer { self.isEditable = true }
@ -92,7 +92,7 @@ extension NSTextView {
/// - inSelection: Whether find string only in selectedRanges.
/// - Returns: A result message.
/// - Throws: `CancellationError`
@MainActor final func replaceAll(_ definition: MultipleReplace, inSelection: Bool) async throws -> String {
final func replaceAll(_ definition: MultipleReplace, inSelection: Bool) async throws -> String {
self.isEditable = false
defer { self.isEditable = true }

View File

@ -8,7 +8,7 @@
//
// ---------------------------------------------------------------------------
//
// © 2018-2023 1024jp
// © 2018-2024 1024jp
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@ -34,7 +34,7 @@ extension NSTextView {
/// - enabled: If true, parse and highlight, otherwise just remove the current highlight.
/// - Returns: Whether the content is not invalid.
@discardableResult
@MainActor final func highlightAsRegularExpressionPattern(mode: RegularExpressionParseMode, enabled: Bool = true) -> Bool {
final func highlightAsRegularExpressionPattern(mode: RegularExpressionParseMode, enabled: Bool = true) -> Bool {
guard
let layoutManager = self.textLayoutManager
@ -71,7 +71,7 @@ extension NSTextView {
/// - mode: Parse mode of regular expression.
/// - enabled: If true, parse and highlight, otherwise just remove the current highlight.
/// - Returns: Whether the content is not invalid.
@MainActor private func highlightAsRegularExpressionPatternWithLegacyTextKit(mode: RegularExpressionParseMode, enabled: Bool = true) -> Bool {
private func highlightAsRegularExpressionPatternWithLegacyTextKit(mode: RegularExpressionParseMode, enabled: Bool = true) -> Bool {
guard let layoutManager = self.layoutManager else { assertionFailure(); return false }

View File

@ -144,7 +144,7 @@ private struct OutlineNavigationView: View {
// MARK: Private Methods
@ViewBuilder @MainActor private func previousButton(systemImage: String) -> some View {
@ViewBuilder private func previousButton(systemImage: String) -> some View {
Button {
self.navigator.selectPreviousItem()
@ -161,7 +161,7 @@ private struct OutlineNavigationView: View {
}
@ViewBuilder @MainActor private func nextButton(systemImage: String) -> some View {
@ViewBuilder private func nextButton(systemImage: String) -> some View {
Button {
self.navigator.selectNextItem()

View File

@ -168,7 +168,7 @@ struct PatternSortView: View {
/// Submits the current input.
@MainActor private func submit() {
private func submit() {
guard
self.parent?.commitEditing() == true

View File

@ -64,7 +64,7 @@ struct SyntaxEditView: View {
weak var parent: NSHostingController<Self>?
@MainActor private static var viewSize = CGSize(width: 680, height: 525)
private static var viewSize = CGSize(width: 680, height: 525)
@State private var name: String = ""
@State private var message: String?
@ -228,7 +228,7 @@ struct SyntaxEditView: View {
// MARK: Private Methods
/// Submits the syntax if it is valid.
@MainActor private func submit() {
private func submit() {
// syntax name validation
self.name = self.name.trimmingCharacters(in: .whitespacesAndNewlines)
@ -257,7 +257,7 @@ struct SyntaxEditView: View {
/// Restores the current settings in editor to the user default.
@MainActor private func restore() {
private func restore() {
guard
self.isBundled,

View File

@ -373,7 +373,7 @@ struct TextFindAllResult {
/// Performs multiple replacement with a specific replacement definition.
///
/// - Parameter name: The name of the multiple replacement definition.
@MainActor private func multiReplaceAll(name: String) {
private func multiReplaceAll(name: String) {
guard let definition = try? ReplacementManager.shared.setting(name: name) else { return assertionFailure() }

View File

@ -115,7 +115,7 @@ struct UnicodeInputView: View {
/// Inputs Unicode character to the parent text view.
@MainActor private func submit() {
private func submit() {
guard let character = self.character else { return NSSound.beep() }

View File

@ -167,7 +167,7 @@ private enum NewFeature: CaseIterable {
}
@ViewBuilder var supplementalView: some View {
@MainActor @ViewBuilder var supplementalView: some View {
switch self {
case .donation:
@ -178,9 +178,7 @@ private enum NewFeature: CaseIterable {
.fixedSize()
#else
Button(String(localized: "Open Donation Settings", table: "WhatsNew")) {
Task { @MainActor in
SettingsWindowController.shared.openPane(.donation)
}
SettingsWindowController.shared.openPane(.donation)
}
.buttonStyle(.capsule)
#endif