Skip to content

Commit 59d6654

Browse files
authored
feat: plugin rebuild option for local plugins (#1150)
- add cordova http plugin to do http requests without any cors issue - add rebuild icon in sidebar for local plugin to easily reinstall it - fixed remote plugin installation with ip
1 parent edf3a30 commit 59d6654

File tree

6 files changed

+87
-14
lines changed

6 files changed

+87
-14
lines changed

config.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,5 @@
7878
<hook type="before_prepare" src="hooks/modify-java-files.js" />
7979
<hook type="after_prepare" src="hooks/post-process.js" />
8080
</platform>
81+
<preference name="AndroidBlacklistSecureSocketProtocols" value="SSLv3,TLSv1" />
8182
</widget>

package-lock.json

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@
3131
"cordova-plugin-sdcard": {},
3232
"cordova-plugin-browser": {},
3333
"cordova-plugin-iap": {},
34-
"cordova-plugin-system": {}
34+
"cordova-plugin-system": {},
35+
"cordova-plugin-advanced-http": {
36+
"ANDROIDBLACKLISTSECURESOCKETPROTOCOLS": "SSLv3,TLSv1"
37+
}
3538
},
3639
"platforms": [
3740
"android"
@@ -59,6 +62,7 @@
5962
"babel-loader": "^9.1.3",
6063
"cordova-android": "^13.0.0",
6164
"cordova-clipboard": "^1.3.0",
65+
"cordova-plugin-advanced-http": "^3.3.1",
6266
"cordova-plugin-browser": "file:src/plugins/browser",
6367
"cordova-plugin-buildinfo": "^4.0.0",
6468
"cordova-plugin-device": "^2.0.3",

src/lib/installPlugin.js

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,39 @@ export default async function installPlugin(
6464
try {
6565
if (!isDependency) loaderDialog.show();
6666

67-
const plugin = await fsOperation(pluginUrl).readFile(
68-
undefined,
69-
(loaded, total) => {
70-
loaderDialog.setMessage(
71-
`${strings.loading} ${((loaded / total) * 100).toFixed(2)}%`,
67+
let plugin;
68+
if (
69+
/^(https?:\/\/)?(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}|localhost)/.test(
70+
pluginUrl,
71+
)
72+
) {
73+
// cordova http plugin for IP addresses and localhost
74+
plugin = await new Promise((resolve, reject) => {
75+
cordova.plugin.http.sendRequest(
76+
pluginUrl,
77+
{
78+
method: "GET",
79+
responseType: "arraybuffer",
80+
},
81+
(response) => {
82+
resolve(response.data);
83+
loaderDialog.setMessage(`${strings.loading} 100%`);
84+
},
85+
(error) => {
86+
reject(error);
87+
},
7288
);
73-
},
74-
);
89+
});
90+
} else {
91+
plugin = await fsOperation(pluginUrl).readFile(
92+
undefined,
93+
(loaded, total) => {
94+
loaderDialog.setMessage(
95+
`${strings.loading} ${((loaded / total) * 100).toFixed(2)}%`,
96+
);
97+
},
98+
);
99+
}
75100

76101
if (plugin) {
77102
const zip = new JSZip();

src/sidebarApps/extensions/index.js

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ function initApp(el) {
8989
if (!$installed) {
9090
$installed = collapsableList(strings["installed"]);
9191
$installed.ontoggle = loadInstalled;
92-
$installed.expand();
92+
//$installed.expand();
9393
container.append($installed);
9494
}
9595

@@ -339,7 +339,7 @@ function getLocalRes(id, name) {
339339
return Url.join(PLUGIN_DIR, id, name);
340340
}
341341

342-
function ListItem({ icon, name, id, version, downloads, installed }) {
342+
function ListItem({ icon, name, id, version, downloads, installed, source }) {
343343
if (installed === undefined) {
344344
installed = !!installedPlugins.find(({ id: _id }) => _id === id);
345345
}
@@ -353,10 +353,15 @@ function ListItem({ icon, name, id, version, downloads, installed }) {
353353
{name}
354354
</span>
355355
{installed ? (
356-
<span
357-
className="icon more_vert"
358-
data-action="more-plugin-action"
359-
></span>
356+
<>
357+
{source ? (
358+
<span className="icon replay" data-action="rebuild-plugin"></span>
359+
) : null}
360+
<span
361+
className="icon more_vert"
362+
data-action="more-plugin-action"
363+
></span>
364+
</>
360365
) : (
361366
<button className="install-btn" data-action="install-plugin">
362367
<span className="icon file_downloadget_app"></span>
@@ -372,6 +377,9 @@ function ListItem({ icon, name, id, version, downloads, installed }) {
372377
const installPluginBtn = event.target.closest(
373378
'[data-action="install-plugin"]',
374379
);
380+
const rebuildPluginBtn = event.target.closest(
381+
'[data-action="rebuild-plugin"]',
382+
);
375383
if (morePluginActionButton) {
376384
more_plugin_action(id, name);
377385
return;
@@ -416,6 +424,16 @@ function ListItem({ icon, name, id, version, downloads, installed }) {
416424
window.toast(helpers.errorMessage(err), 3000);
417425
}
418426
return;
427+
} else if (rebuildPluginBtn) {
428+
try {
429+
const { default: installPlugin } = await import("lib/installPlugin");
430+
await installPlugin(source);
431+
window.toast(strings["success"], 3000);
432+
} catch (err) {
433+
console.error(err);
434+
window.toast(helpers.errorMessage(err), 3000);
435+
}
436+
return;
419437
}
420438

421439
plugin(

src/sidebarApps/extensions/style.scss

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,17 @@
8080
background-color: var(--active-icon-color);
8181
}
8282
}
83+
.replay {
84+
display: flex;
85+
align-items: center;
86+
cursor: pointer;
87+
justify-content: center;
88+
transition: background-color 0.3s ease;
89+
90+
&:hover {
91+
background-color: var(--active-icon-color);
92+
}
93+
}
8394

8495
.install-btn {
8596
background: none;

0 commit comments

Comments
 (0)