Add a share extension to help to add user phrases from the Contacts app and selected app#821
Add a share extension to help to add user phrases from the Contacts app and selected app#821zonble wants to merge 6 commits intoopenvanilla:masterfrom
Conversation
…text. A new share extension is added, and contained in the host app McBopomofo. A user can unable the extension in the settings app. Once enabled, a "Add to McBopomofo" entry will appear in the share menu. The commit also extract the core of the text services from the ServiceProvider class. This may help to solve openvanilla#819.
There was a problem hiding this comment.
Code Review
This pull request introduces a new Share Extension (McBopomofoShare) that allows users to add phrases to their dictionary from text or contacts. It refactors the core transformation logic into a new McBopomofoService class and implements a custom URL scheme (mcbopomofo://add_phrase) for communication between the extension and the main app. Critical feedback includes addressing a path traversal vulnerability and potential OOM crashes in the URL handler, fixing a possible crash when processing empty strings in the service, and mitigating performance issues related to long input strings and main-thread blocking during phrase imports.
| let token = tokenTuple.0 | ||
| let type = tokenTuple.1 | ||
| if addSpace, let previousToken, let previousTokenType { | ||
| let lastChar = output[output.index(before: output.endIndex)] |
There was a problem hiding this comment.
This line will crash if output is empty because index(before:) is called on startIndex. While current callers might ensure non-empty output for the first token, it is a fragile assumption. For example, if the first token results in an empty string from the callbacks, the second iteration will trigger this crash when addSpace is true.
if addSpace, let previousToken, let previousTokenType, !output.isEmpty {…lHandler and McBopomofoService
The PR adds a share extension to be contained in McBopomofo's bundle.
A user can enable the extension after installing McBopomofo. After enabling the extension, the user can select multiople contacts in the Contacts app and select "share" to add the names to the user phrases. He or she can do this while selecting any text up to 8 characters in the share extension as well.
The PR uses a custom URL to let the share extension to notify the main bundle that a temporary file for the names is written and ask it to open it. Currently we are not using sandbox and app group, so the extension just write to the regular temporary folder.
The PR is for #819.