Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

コンパイル時の警告を減らす #224

Merged
merged 6 commits into from
Oct 13, 2024
Merged
6 changes: 1 addition & 5 deletions macSKK.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,7 @@
attributes = {
BuildIndependentTargetsInParallel = 1;
LastSwiftUpdateCheck = 1530;
LastUpgradeCheck = 1540;
LastUpgradeCheck = 1600;
TargetAttributes = {
CE5ECF312957034B00E7BE7D = {
CreatedOnToolsVersion = 14.2;
Expand Down Expand Up @@ -1035,7 +1035,6 @@
CE5ECF582957034D00E7BE7D /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CLANG_ENABLE_MODULES = YES;
Expand Down Expand Up @@ -1071,7 +1070,6 @@
CE5ECF592957034D00E7BE7D /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CLANG_ENABLE_MODULES = YES;
Expand Down Expand Up @@ -1107,7 +1105,6 @@
CE5ECF5B2957034D00E7BE7D /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
BUNDLE_LOADER = "$(TEST_HOST)";
CODE_SIGN_STYLE = Automatic;
DEAD_CODE_STRIPPING = YES;
Expand All @@ -1125,7 +1122,6 @@
CE5ECF5C2957034D00E7BE7D /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
BUNDLE_LOADER = "$(TEST_HOST)";
CODE_SIGN_STYLE = Automatic;
DEAD_CODE_STRIPPING = YES;
Expand Down
2 changes: 1 addition & 1 deletion macSKK.xcodeproj/xcshareddata/xcschemes/macSKK.xcscheme
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1540"
LastUpgradeVersion = "1600"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
14 changes: 7 additions & 7 deletions macSKK/InputController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class InputController: IMKInputController {
/// 最後にイベントを受け取ったときのウィンドウレベル + 1
private var windowLevel: NSWindow.Level = .floating

override init!(server: IMKServer!, delegate: Any!, client inputClient: Any!) {
@MainActor override init!(server: IMKServer!, delegate: Any!, client inputClient: Any!) {
super.init(server: server, delegate: delegate, client: inputClient)

guard let textInput = inputClient as? any IMKTextInput else {
Expand Down Expand Up @@ -195,7 +195,7 @@ class InputController: IMKInputController {
}.store(in: &cancellables)
}

override func handle(_ event: NSEvent!, client sender: Any!) -> Bool {
@MainActor override func handle(_ event: NSEvent!, client sender: Any!) -> Bool {
// 文字ビューアで入力した場合など、eventがnilの場合がありえる
if event == nil {
return false
Expand Down Expand Up @@ -225,7 +225,7 @@ class InputController: IMKInputController {
return stateMachine.handle(Action(keyBind: keyBind, event: event, cursorPosition: cursorPosition))
}

override func menu() -> NSMenu! {
@MainActor override func menu() -> NSMenu! {
let preferenceMenu = NSMenu()
preferenceMenu.addItem(
withTitle: String(localized: "MenuItemPreference", comment: "Preferences…"),
Expand Down Expand Up @@ -259,28 +259,28 @@ class InputController: IMKInputController {
}

// MARK: - IMKStateSetting
override func activateServer(_ sender: Any!) {
@MainActor override func activateServer(_ sender: Any!) {
if let textInput = sender as? any IMKTextInput {
setCustomInputSource(textInput: textInput)
} else {
logger.warning("activateServerの引数clientがIMKTextInputではありません")
}
}

override func deactivateServer(_ sender: Any!) {
@MainActor override func deactivateServer(_ sender: Any!) {
// 他の入力に切り替わるときには入力候補や補完候補は消す + 現在表示中の候補を確定させる
Global.candidatesPanel.orderOut(sender)
Global.completionPanel.orderOut(sender)
super.deactivateServer(sender)
}

/// クライアントが入力中状態を即座に確定してほしいときに呼ばれる
override func commitComposition(_ sender: Any!) {
@MainActor override func commitComposition(_ sender: Any!) {
// 現在未確定の入力を強制的に確定させて状態を入力前の状態にする
stateMachine.commitComposition()
}

override func setValue(_ value: Any!, forTag tag: Int, client sender: Any!) {
@MainActor override func setValue(_ value: Any!, forTag tag: Int, client sender: Any!) {
guard let value = value as? String else { return }
guard let inputMode = InputMode(rawValue: value) else { return }
logger.debug("入力モードが変更されました \(inputMode.rawValue)")
Expand Down
4 changes: 2 additions & 2 deletions macSKK/NumberEntry.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import Foundation
* 数値変換用のユーザーが入力した読み部分。"だい1" のような入力を受け取り、整数部分と非整数部分に分ける。
*/
struct NumberYomi {
static let pattern = /#([01234589])/
nonisolated(unsafe) static let pattern = /#([01234589])/

// TODO: Stringを作るコストをなくしyomiのSubstringでもっておく。Substringだとユニットテストが書きにくくなるしこれでもいいかも。
enum Element: Equatable {
Expand Down Expand Up @@ -84,7 +84,7 @@ struct NumberYomi {

// 数値入りの変換候補
struct NumberCandidate {
static let pattern = /#([01234589])/
nonisolated(unsafe) static let pattern = /#([01234589])/
static let kanjiFormatter: NumberFormatter = {
let formatter = NumberFormatter()
formatter.locale = Locale(identifier: "ja-JP")
Expand Down
2 changes: 1 addition & 1 deletion macSKK/Pasteboard.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import AppKit

/// クリップボード関係の処理。ユニットテスト実行時に実際のNSPasteboardを更新しなくていいようにしてある。
struct Pasteboard {
static var stringForTest: String? = nil
nonisolated(unsafe) static var stringForTest: String? = nil

static func getString() -> String? {
if isTest() {
Expand Down
4 changes: 1 addition & 3 deletions macSKK/ReleaseVersion.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ struct ReleaseVersion: Comparable, CustomStringConvertible, Sendable {
return "\(major).\(minor).\(patch)"
}

static let pattern = /([0-9]+)\.([0-9]+)\.([0-9]+)/

// Comparable
static func < (lhs: Self, rhs: Self) -> Bool {
if lhs.major != rhs.major {
Expand All @@ -34,7 +32,7 @@ struct ReleaseVersion: Comparable, CustomStringConvertible, Sendable {
}

init?(string: String) {
if let match = string.wholeMatch(of: Self.pattern) {
if let match = string.wholeMatch(of: /([0-9]+)\.([0-9]+)\.([0-9]+)/) {
if let major = Int(match.1), let minor = Int(match.2), let patch = Int(match.3) {
self.major = major
self.minor = minor
Expand Down
40 changes: 17 additions & 23 deletions macSKK/Settings/SettingsViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -556,36 +556,30 @@ final class SettingsViewModel: ObservableObject {
func setupNotification() {
assert(dictSettings.isEmpty, "dictSettingsが空の状態でsetupNotificationしようとしました。バグと思われます。")

Task {
for await notification in NotificationCenter.default.notifications(named: notificationNameDictFileDidAppear) {
if let url = notification.object as? URL {
await MainActor.run {
if self.dictSettings.allSatisfy({ $0.filename != url.lastPathComponent }) {
let type: FileDictType = if url.pathExtension == "json" {
.json
} else {
.traditional(.japaneseEUC)
}
self.dictSettings.append(DictSetting(filename: url.lastPathComponent,
enabled: false,
type: type))
NotificationCenter.default.publisher(for: notificationNameDictFileDidAppear).receive(on: RunLoop.main)
.sink { [weak self] notification in
if let self, let url = notification.object as? URL {
if self.dictSettings.allSatisfy({ $0.filename != url.lastPathComponent }) {
let type: FileDictType = if url.pathExtension == "json" {
.json
} else {
.traditional(.japaneseEUC)
}
self.dictSettings.append(DictSetting(filename: url.lastPathComponent,
enabled: false,
type: type))
}
}
}
}
}.store(in: &cancellables)

Task {
for await notification in NotificationCenter.default.notifications(named: notificationNameDictFileDidMove) {
if let url = notification.object as? URL {
NotificationCenter.default.publisher(for: notificationNameDictFileDidMove).receive(on: RunLoop.main)
.sink { [weak self] notification in
if let self, let url = notification.object as? URL {
// 辞書設定から移動したファイルを削除する
// FIXME: 削除ではなくリネームなら追従する
await MainActor.run {
self.dictSettings = self.dictSettings.filter({ $0.filename != url.lastPathComponent })
}
self.dictSettings = self.dictSettings.filter({ $0.filename != url.lastPathComponent })
}
}
}
}.store(in: &cancellables)
}

/**
Expand Down
2 changes: 1 addition & 1 deletion macSKK/macSKKApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import SwiftUI
import UserNotifications
import os

nonisolated(unsafe) let logger: Logger = Logger(subsystem: Bundle.main.bundleIdentifier!, category: "main")
let logger: Logger = Logger(subsystem: Bundle.main.bundleIdentifier!, category: "main")
// 直接入力モードを切り替えたいときに通知される通知の名前。
let notificationNameToggleDirectMode = Notification.Name("toggleDirectMode")
// 空文字挿入のワークアラウンドの有効無効を切り替えたいときに通知される通知の名前。
Expand Down