@@ -65,6 +65,10 @@ struct ConfigWindow: View {
6565 }
6666
6767 private var azooKeyApplicationSupportDirectoryURL : URL {
68+ AppGroup . applicationSupportDirectoryURL ( )
69+ }
70+
71+ private var legacyAzooKeyApplicationSupportDirectoryURL : URL {
6872 if #available( macOS 13 , * ) {
6973 URL . applicationSupportDirectory
7074 . appending ( path: " azooKey " , directoryHint: . isDirectory)
@@ -80,6 +84,12 @@ struct ConfigWindow: View {
8084 )
8185 }
8286
87+ private var legacyDebugTypoCorrectionModelDirectoryURL : URL {
88+ DebugTypoCorrectionWeights . modelDirectoryURL (
89+ azooKeyApplicationSupportDirectoryURL: self . legacyAzooKeyApplicationSupportDirectoryURL
90+ )
91+ }
92+
8393 private var debugTypoCorrectionStatusText : String {
8494 if self . debugTypoCorrectionDownloadInProgress {
8595 return " ダウンロード中... "
@@ -97,8 +107,13 @@ struct ConfigWindow: View {
97107 @MainActor
98108 private func refreshDebugTypoCorrectionState( ) async {
99109 let modelDirectoryURL = self . debugTypoCorrectionModelDirectoryURL
100- let state = await Task . detached ( priority: . utility) {
101- DebugTypoCorrectionWeights . state ( modelDirectoryURL: modelDirectoryURL)
110+ let legacyModelDirectoryURL = self . legacyDebugTypoCorrectionModelDirectoryURL
111+ let state = await Task . detached ( priority: . utility) { ( ) -> DebugTypoCorrectionState in
112+ Self . migrateLegacyDebugTypoCorrectionWeightsIfNeeded (
113+ from: legacyModelDirectoryURL,
114+ to: modelDirectoryURL
115+ )
116+ return DebugTypoCorrectionWeights . state ( modelDirectoryURL: modelDirectoryURL)
102117 } . value
103118 self . debugTypoCorrectionState = state
104119 if state != . failed {
@@ -136,6 +151,29 @@ struct ConfigWindow: View {
136151 }
137152 }
138153
154+ nonisolated private static func migrateLegacyDebugTypoCorrectionWeightsIfNeeded( from sourceURL: URL , to targetURL: URL ) {
155+ guard sourceURL. standardizedFileURL != targetURL. standardizedFileURL else {
156+ return
157+ }
158+ guard !DebugTypoCorrectionWeights. hasRequiredWeightFiles ( modelDirectoryURL: targetURL) ,
159+ DebugTypoCorrectionWeights . hasRequiredWeightFiles ( modelDirectoryURL: sourceURL) else {
160+ return
161+ }
162+ do {
163+ let fileManager = FileManager . default
164+ try fileManager. createDirectory (
165+ at: targetURL. deletingLastPathComponent ( ) ,
166+ withIntermediateDirectories: true
167+ )
168+ if fileManager. fileExists ( atPath: targetURL. path) {
169+ try fileManager. removeItem ( at: targetURL)
170+ }
171+ try fileManager. copyItem ( at: sourceURL, to: targetURL)
172+ } catch {
173+ // The status check below will surface a notDownloaded/failed state.
174+ }
175+ }
176+
139177 private func openAzooKeyDataDirectoryInFinder( ) {
140178 do {
141179 try FileManager . default. createDirectory (
0 commit comments