Repository navigation
Migrate json configuration files #110
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
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,34 +1,37 @@ | ||
| [ | ||
| { | ||
| "serviceName": "Look Up in Dictionary", | ||
| "displayName": "Look Up in Dictionary" | ||
| }, | ||
| { | ||
| "serviceName": "Search With %WebSearchProvider@", | ||
| "displayName": "Search in Safari" | ||
| }, | ||
| { | ||
| "serviceName": "SEARCH_WITH_SPOTLIGHT", | ||
| "displayName": "Search with Spotlight" | ||
| }, | ||
| { | ||
| "serviceName": "Convert Text from Simplified to Traditional Chinese", | ||
| "displayName": "Convert to Traditional Chinese" | ||
| }, | ||
| { | ||
| "serviceName": "Convert Text from Traditional to Simplified Chinese", | ||
| "displayName": "Convert to Simplified Chinese" | ||
| }, | ||
| { | ||
| "serviceName": "New TextEdit Window Containing Selection", | ||
| "displayName": "New File in TextEdit" | ||
| }, | ||
| { | ||
| "serviceName": "Make Sticky", | ||
| "displayName": "Make New Sticky Note" | ||
| }, | ||
| { | ||
| "serviceName": "Summarize", | ||
| "displayName": "Summarize" | ||
| } | ||
| ] | ||
| { | ||
| "$schema": "https://raw.githubusercontent.com/TextGrabber2-app/schemas/main/services.json", | ||
| "items": [ | ||
| { | ||
| "serviceName": "Look Up in Dictionary", | ||
| "displayName": "Look Up in Dictionary" | ||
| }, | ||
| { | ||
| "serviceName": "Search With %WebSearchProvider@", | ||
| "displayName": "Search in Safari" | ||
| }, | ||
| { | ||
| "serviceName": "SEARCH_WITH_SPOTLIGHT", | ||
| "displayName": "Search with Spotlight" | ||
| }, | ||
| { | ||
| "serviceName": "Convert Text from Simplified to Traditional Chinese", | ||
| "displayName": "Convert to Traditional Chinese" | ||
| }, | ||
| { | ||
| "serviceName": "Convert Text from Traditional to Simplified Chinese", | ||
| "displayName": "Convert to Simplified Chinese" | ||
| }, | ||
| { | ||
| "serviceName": "New TextEdit Window Containing Selection", | ||
| "displayName": "New File in TextEdit" | ||
| }, | ||
| { | ||
| "serviceName": "Make Sticky", | ||
| "displayName": "Make New Sticky Note" | ||
| }, | ||
| { | ||
| "serviceName": "Summarize", | ||
| "displayName": "Summarize" | ||
| } | ||
| ] | ||
| } |
This file contains hidden or 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,34 +1,37 @@ | ||
| [ | ||
| { | ||
| "serviceName": "Look Up in Dictionary", | ||
| "displayName": "在词典中查询" | ||
| }, | ||
| { | ||
| "serviceName": "Search With %WebSearchProvider@", | ||
| "displayName": "在 Safari 中搜索" | ||
| }, | ||
| { | ||
| "serviceName": "SEARCH_WITH_SPOTLIGHT", | ||
| "displayName": "用 Spotlight 搜索" | ||
| }, | ||
| { | ||
| "serviceName": "Convert Text from Simplified to Traditional Chinese", | ||
| "displayName": "转换为繁体中文" | ||
| }, | ||
| { | ||
| "serviceName": "Convert Text from Traditional to Simplified Chinese", | ||
| "displayName": "转换为简体中文" | ||
| }, | ||
| { | ||
| "serviceName": "New TextEdit Window Containing Selection", | ||
| "displayName": "在 TextEdit 新建文件" | ||
| }, | ||
| { | ||
| "serviceName": "Make Sticky", | ||
| "displayName": "创建新便笺条" | ||
| }, | ||
| { | ||
| "serviceName": "Summarize", | ||
| "displayName": "摘要" | ||
| } | ||
| ] | ||
| { | ||
| "$schema": "https://raw.githubusercontent.com/TextGrabber2-app/schemas/main/services.json", | ||
| "items": [ | ||
| { | ||
| "serviceName": "Look Up in Dictionary", | ||
| "displayName": "在词典中查询" | ||
| }, | ||
| { | ||
| "serviceName": "Search With %WebSearchProvider@", | ||
| "displayName": "在 Safari 中搜索" | ||
| }, | ||
| { | ||
| "serviceName": "SEARCH_WITH_SPOTLIGHT", | ||
| "displayName": "用 Spotlight 搜索" | ||
| }, | ||
| { | ||
| "serviceName": "Convert Text from Simplified to Traditional Chinese", | ||
| "displayName": "转换为繁体中文" | ||
| }, | ||
| { | ||
| "serviceName": "Convert Text from Traditional to Simplified Chinese", | ||
| "displayName": "转换为简体中文" | ||
| }, | ||
| { | ||
| "serviceName": "New TextEdit Window Containing Selection", | ||
| "displayName": "在 TextEdit 新建文件" | ||
| }, | ||
| { | ||
| "serviceName": "Make Sticky", | ||
| "displayName": "创建新便笺条" | ||
| }, | ||
| { | ||
| "serviceName": "Summarize", | ||
| "displayName": "摘要" | ||
| } | ||
| ] | ||
| } |
This file contains hidden or 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,34 +1,37 @@ | ||
| [ | ||
| { | ||
| "serviceName": "Look Up in Dictionary", | ||
| "displayName": "在辭典中查詢" | ||
| }, | ||
| { | ||
| "serviceName": "Search With %WebSearchProvider@", | ||
| "displayName": "在 Safari 中搜尋" | ||
| }, | ||
| { | ||
| "serviceName": "SEARCH_WITH_SPOTLIGHT", | ||
| "displayName": "用 Spotlight 搜尋" | ||
| }, | ||
| { | ||
| "serviceName": "Convert Text from Simplified to Traditional Chinese", | ||
| "displayName": "轉換為繁體中文" | ||
| }, | ||
| { | ||
| "serviceName": "Convert Text from Traditional to Simplified Chinese", | ||
| "displayName": "轉換為簡體中文" | ||
| }, | ||
| { | ||
| "serviceName": "New TextEdit Window Containing Selection", | ||
| "displayName": "在 TextEdit 新建檔案" | ||
| }, | ||
| { | ||
| "serviceName": "Make Sticky", | ||
| "displayName": "建立新便條紙" | ||
| }, | ||
| { | ||
| "serviceName": "Summarize", | ||
| "displayName": "摘要" | ||
| } | ||
| ] | ||
| { | ||
| "$schema": "https://raw.githubusercontent.com/TextGrabber2-app/schemas/main/services.json", | ||
| "items": [ | ||
| { | ||
| "serviceName": "Look Up in Dictionary", | ||
| "displayName": "在辭典中查詢" | ||
| }, | ||
| { | ||
| "serviceName": "Search With %WebSearchProvider@", | ||
| "displayName": "在 Safari 中搜尋" | ||
| }, | ||
| { | ||
| "serviceName": "SEARCH_WITH_SPOTLIGHT", | ||
| "displayName": "用 Spotlight 搜尋" | ||
| }, | ||
| { | ||
| "serviceName": "Convert Text from Simplified to Traditional Chinese", | ||
| "displayName": "轉換為繁體中文" | ||
| }, | ||
| { | ||
| "serviceName": "Convert Text from Traditional to Simplified Chinese", | ||
| "displayName": "轉換為簡體中文" | ||
| }, | ||
| { | ||
| "serviceName": "New TextEdit Window Containing Selection", | ||
| "displayName": "在 TextEdit 新建檔案" | ||
| }, | ||
| { | ||
| "serviceName": "Make Sticky", | ||
| "displayName": "建立新便條紙" | ||
| }, | ||
| { | ||
| "serviceName": "Summarize", | ||
| "displayName": "摘要" | ||
| } | ||
| ] | ||
| } |
This file contains hidden or 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,46 @@ | ||
| // | ||
| // ConfigurationFile.swift | ||
| // TextGrabber2 | ||
| // | ||
| // Created by cyan on 2026/8/27. | ||
| // | ||
|
|
||
| import Foundation | ||
|
|
||
| enum SchemaURLs { | ||
| static let contentFilters = "https://raw.githubusercontent.com/TextGrabber2-app/schemas/main/content-filters.json" | ||
| static let keyBindings = "https://raw.githubusercontent.com/TextGrabber2-app/schemas/main/key-bindings.json" | ||
| static let services = "https://raw.githubusercontent.com/TextGrabber2-app/schemas/main/services.json" | ||
| } | ||
|
|
||
| struct ConfigurationFile<Item: Decodable>: Decodable { | ||
| let items: [Item] | ||
|
|
||
| init(from decoder: Decoder) throws { | ||
| if let items = try? decoder.singleValueContainer().decode([Item].self) { | ||
| self.items = items | ||
| return | ||
| } | ||
|
|
||
| let container = try decoder.container(keyedBy: CodingKeys.self) | ||
| items = try container.decode([Item].self, forKey: .items) | ||
| } | ||
|
|
||
| static func migrate(at fileURL: URL, schemaURL: String) throws { | ||
| let data = try Data(contentsOf: fileURL) | ||
| guard try JSONSerialization.jsonObject(with: data) is [Any], | ||
| let json = String(data: data, encoding: .utf8) else { | ||
| return | ||
| } | ||
|
|
||
| let items = json.trimmingCharacters(in: .whitespacesAndNewlines) | ||
| .replacingOccurrences(of: "\n", with: "\n ") | ||
| let migratedJSON = "{\n \"$schema\": \"\(schemaURL)\",\n \"items\": \(items)\n}\n" | ||
| let migratedData = Data(migratedJSON.utf8) | ||
| try migratedData.write(to: fileURL, options: .atomic) | ||
| } | ||
|
|
||
| private enum CodingKeys: String, CodingKey { | ||
| case items | ||
| } | ||
| } | ||
This file contains hidden or 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 hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.