-
Notifications
You must be signed in to change notification settings - Fork 804
PluginContext #1867
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
base: main
Are you sure you want to change the base?
PluginContext #1867
Conversation
Greptile OverviewGreptile SummaryThis PR introduces a new local Cordova plugin ( Key issues to address before merge:
Other already-noted threads cover the plugin.xml name mismatch, lockfile extraneous entry, and the JS->native JSON argument type contract. Confidence Score: 3/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant LP as loadPlugin.js
participant PC as window.PluginContext
participant CX as cordova.exec
participant T as Android Tee (CordovaPlugin)
participant IP as acode.initPlugin
LP->>LP: read plugin.json
LP->>PC: generate(pluginId, JSON.stringify(pluginJson))
PC->>CX: exec("Tee","requestToken",[pluginId, pluginJsonStr])
CX->>T: execute("requestToken", args)
T-->>CX: callback.success(token) / error
CX-->>PC: resolve(token)
PC-->>LP: return ctx (_PluginContext)
LP->>IP: initPlugin(..., { ctx })
Note over PC,T: ctx methods call Tee to query permissions
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
8 files reviewed, 4 comments
| generate: async function (pluginId, pluginJson) { | ||
| try { | ||
| function requestToken(pluginId) { | ||
| return new Promise((resolve, reject) => { | ||
| exec(resolve, reject, "Tee", "requestToken", [ | ||
| pluginId, | ||
| pluginJson, | ||
| ]); | ||
| }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Native expects string JSON
On Android, Tee.java reads args.getString(1) and then new JSONObject(pluginJson), so the second argument must be a JSON string. Here pluginJson is passed directly (it’s an object in loadPlugin.js), which will arrive natively as a non-JSON value and trigger INVALID_PLUGIN_JSON, causing generate() to return null.
| generate: async function (pluginId, pluginJson) { | |
| try { | |
| function requestToken(pluginId) { | |
| return new Promise((resolve, reject) => { | |
| exec(resolve, reject, "Tee", "requestToken", [ | |
| pluginId, | |
| pluginJson, | |
| ]); | |
| }); | |
| exec(resolve, reject, "Tee", "requestToken", [ | |
| pluginId, | |
| JSON.stringify(pluginJson), | |
| ]); |
| <plugin xmlns="http://apache.org/cordova/ns/plugins/1.0" xmlns:android="http://schemas.android.com/apk/res/android" id="com.foxdebug.acode.rk.plugin.plugincontext" version="1.0.0"> | ||
| <name>Gatekeeper</name> | ||
|
|
||
|
|
||
| <js-module name="PluginContext" src="www/PluginContext.js"> | ||
| <clobbers target="window.PluginContext" /> | ||
| </js-module> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Plugin metadata mismatch
This plugin is plugincontext but the <name> is set to Gatekeeper, which will surface as the wrong plugin name in Cordova tooling/plugins list. This looks like a copy/paste error and should be renamed to match the actual plugin.
| <plugin xmlns="http://apache.org/cordova/ns/plugins/1.0" xmlns:android="http://schemas.android.com/apk/res/android" id="com.foxdebug.acode.rk.plugin.plugincontext" version="1.0.0"> | |
| <name>Gatekeeper</name> | |
| <js-module name="PluginContext" src="www/PluginContext.js"> | |
| <clobbers target="window.PluginContext" /> | |
| </js-module> | |
| <name>PluginContext</name> |
| "src/plugins/gatekeeper": { | ||
| "name": "com.foxdebug.acode.rk.plugin.gatekeeper", | ||
| "version": "1.0.0", | ||
| "extraneous": true, | ||
| "license": "MIT" | ||
| }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unrelated extraneous lockfile entry
This PR introduces an extraneous entry for src/plugins/gatekeeper, but there’s no corresponding dependency/plugin added in package.json. This will make installs non-reproducible across environments and should be removed from the lockfile (regenerate package-lock.json from a clean install) so only intentional dependencies are recorded.
Additional Comments (1)
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
8 files reviewed, 2 comments
| "com.foxdebug.acode.rk.exec.proot": {}, | ||
| "com.foxdebug.acode.rk.exec.terminal": {}, | ||
| "com.foxdebug.acode.rk.customtabs": {}, | ||
| "com.foxdebug.acode.rk.auth": {} | ||
| "com.foxdebug.acode.rk.plugin.plugincontext": {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Plugin list inconsistency
cordova.plugins dropped the auth plugin entry while devDependencies still includes the local auth package. This makes the Cordova plugin list inconsistent with what gets installed, and can remove auth functionality unexpectedly. If auth is still required, add it back under cordova.plugins; otherwise remove the local auth dependency and update any consumers accordingly.
| private static final Map<String, String> tokenStore = new HashMap<>(); | ||
| private static final HashSet<String> disclosed = new HashSet<>(); | ||
| private static final Map<String, List<String>> permissionStore = new HashMap<>(); | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Global static stores leak
tokenStore, disclosed, and permissionStore are static and never cleared. In a Cordova WebView, plugins can be installed/uninstalled or reloaded without a full process restart; these maps will retain old pluginIds/tokens/permissions and can cause TOKEN_ALREADY_ISSUED or stale permission results for later sessions. Consider scoping these stores to the plugin instance/lifecycle or providing a reset path tied to app/plugin reload.
No description provided.