Skip to content

Commit 9a54016

Browse files
committed
Swift 6
1 parent e6b8f07 commit 9a54016

8 files changed

Lines changed: 24 additions & 5 deletions

File tree

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ set(CMAKE_TOOLCHAIN_FILE "${CMAKE_CURRENT_LIST_DIR}/ios-cmake/ios.toolchain.cmak
99

1010
project(fcitx5-ios VERSION 0.1.0 LANGUAGES CXX Swift)
1111
set(CMAKE_XCODE_ATTRIBUTE_CODE_SIGNING_ALLOWED YES) # Need it for AppGroup even for simulator.
12-
set(CMAKE_Swift_LANGUAGE_VERSION 5.9)
12+
set(CMAKE_Swift_LANGUAGE_VERSION 6)
1313
set(CMAKE_CXX_STANDARD 20)
1414

1515
set(BUNDLE_IDENTIFIER "org.fcitx.Fcitx5")

iosfrontend/iosfrontend.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import FcitxProtocol
22
import Foundation
33

4+
@MainActor
45
private var client: FcitxProtocol!
56

7+
@MainActor
68
public func setClient(_ cli: FcitxProtocol) {
79
client = cli
810
}

keyboard/KeyboardViewController.swift

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,17 @@ private func syncLocale() -> String {
2323
return getLocale()
2424
}
2525

26+
@MainActor
2627
class KeyboardViewController: UIInputViewController, FcitxProtocol {
2728
var id: UInt64!
2829
var hostingController: UIHostingController<VirtualKeyboardView>!
2930
var removedBySlide = ""
3031
static private var clipboardText = ""
3132

33+
nonisolated(unsafe) private func getId() -> UInt64 {
34+
return UInt64(Int(bitPattern: Unmanaged.passUnretained(self).toOpaque()))
35+
}
36+
3237
private func updateTextIsEmpty() {
3338
let text =
3439
(textDocumentProxy.documentContextBeforeInput ?? "")
@@ -44,7 +49,7 @@ class KeyboardViewController: UIInputViewController, FcitxProtocol {
4449
}
4550

4651
override func viewDidLoad() {
47-
id = UInt64(Int(bitPattern: Unmanaged.passUnretained(self).toOpaque()))
52+
id = getId()
4853
logger.info("viewDidLoad \(self.id)")
4954
super.viewDidLoad()
5055
redirectStderr()
@@ -104,8 +109,7 @@ class KeyboardViewController: UIInputViewController, FcitxProtocol {
104109
}
105110

106111
deinit {
107-
logger.info("deinit \(self.id)")
108-
hostingController = nil
112+
logger.info("deinit \(self.getId())")
109113
}
110114

111115
override func viewWillLayoutSubviews() {

protocol/FcitxProtocol.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
@MainActor
12
public protocol FcitxProtocol {
23
func keyPressed(_ key: String, _ code: String)
34
func forwardKey(_ key: String, _ code: String)

uipanel/KeyModifier.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ private func getNStep(_ start: CGFloat, _ end: CGFloat, _ step: CGFloat) -> Int
2626
return (start < end ? 1 : -1) * Int(floor(abs(end - start) / step))
2727
}
2828

29+
@MainActor
2930
private func clearBubble() {
3031
virtualKeyboardView.setBubble(0, 0, 0, 0, .clear, .light, .clear, nil, [], 0, 0)
3132
}
@@ -274,6 +275,7 @@ extension View {
274275
}
275276
}
276277

278+
@MainActor
277279
func executeActions(_ actions: [[String: String]]) {
278280
for action in actions {
279281
if let type = action["type"] {

uipanel/VirtualKeyboard.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,18 @@ public enum DisplayMode {
1010
case symbol
1111
}
1212

13+
@MainActor
1314
var client: FcitxProtocol!
1415

16+
@MainActor
1517
public func setClient(_ cli: FcitxProtocol) {
1618
client = cli
1719
}
1820

21+
@MainActor
1922
let vm = ViewModel()
2023

24+
@MainActor
2125
class ViewModel: ObservableObject {
2226
@Published var mode: DisplayMode = .initial
2327
@Published var returnMode: DisplayMode = .initial // or .candidates
@@ -279,8 +283,10 @@ public struct VirtualKeyboardView: View {
279283
}
280284
}
281285

286+
@MainActor
282287
public var virtualKeyboardView: VirtualKeyboardView!
283288

289+
@MainActor
284290
public func newVirtualKeyboardView() -> VirtualKeyboardView {
285291
virtualKeyboardView = VirtualKeyboardView()
286292
return virtualKeyboardView

uipanel/height.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,17 @@ enum KeyboardState {
1717
case floating
1818
}
1919

20+
@MainActor
2021
private var isFloating = false
2122

23+
@MainActor
2224
func setFloating(_ width: CGFloat) {
2325
isFloating =
2426
(UIScreen.main.bounds.width >= 1000 || UIScreen.main.bounds.height > 1000)
2527
&& width < UIScreen.main.bounds.width && width < UIScreen.main.bounds.height
2628
}
2729

30+
@MainActor
2831
func getKeyboardState() -> KeyboardState {
2932
if isFloating {
3033
return .floating
@@ -35,6 +38,7 @@ func getKeyboardState() -> KeyboardState {
3538
return .landscape
3639
}
3740

41+
@MainActor
3842
func getDefaultTotalHeight() -> CGFloat {
3943
switch getKeyboardState() {
4044
case .portrait:

uipanel/keyboardui.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public func scrollAsync(_ candidates: [String], _ end: Bool) {
1919
}
2020
}
2121

22-
public struct StatusAreaAction: Identifiable {
22+
public struct StatusAreaAction: Identifiable, Sendable {
2323
public let id: Int32
2424
let desc: String
2525
let icon: String

0 commit comments

Comments
 (0)