Skip to content

Add a share extension to help to add user phrases from the Contacts app and selected app#821

Closed
zonble wants to merge 6 commits intoopenvanilla:masterfrom
zonble:share_extension
Closed

Add a share extension to help to add user phrases from the Contacts app and selected app#821
zonble wants to merge 6 commits intoopenvanilla:masterfrom
zonble:share_extension

Conversation

@zonble
Copy link
Copy Markdown
Contributor

@zonble zonble commented Apr 19, 2026

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.

zonble added 4 commits April 19, 2026 20:15
…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.
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread Source/CustomUrlHandler.swift
Comment thread Source/CustomUrlHandler.swift
Comment thread Source/McBopomofoService.swift
let token = tokenTuple.0
let type = tokenTuple.1
if addSpace, let previousToken, let previousTokenType {
let lastChar = output[output.index(before: output.endIndex)]
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

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 {

Comment thread Source/CustomUrlHandler.swift Outdated
@zonble zonble requested a review from lukhnos April 25, 2026 18:22
@zonble zonble closed this Apr 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant