Skip to content

Commit

Permalink
feat: plugin rebuild option for local plugins (#1150)
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
bajrangCoder authored Jan 18, 2025
1 parent edf3a30 commit 59d6654
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 14 deletions.
1 change: 1 addition & 0 deletions config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,5 @@
<hook type="before_prepare" src="hooks/modify-java-files.js" />
<hook type="after_prepare" src="hooks/post-process.js" />
</platform>
<preference name="AndroidBlacklistSecureSocketProtocols" value="SSLv3,TLSv1" />
</widget>
14 changes: 14 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@
"cordova-plugin-sdcard": {},
"cordova-plugin-browser": {},
"cordova-plugin-iap": {},
"cordova-plugin-system": {}
"cordova-plugin-system": {},
"cordova-plugin-advanced-http": {
"ANDROIDBLACKLISTSECURESOCKETPROTOCOLS": "SSLv3,TLSv1"
}
},
"platforms": [
"android"
Expand Down Expand Up @@ -59,6 +62,7 @@
"babel-loader": "^9.1.3",
"cordova-android": "^13.0.0",
"cordova-clipboard": "^1.3.0",
"cordova-plugin-advanced-http": "^3.3.1",
"cordova-plugin-browser": "file:src/plugins/browser",
"cordova-plugin-buildinfo": "^4.0.0",
"cordova-plugin-device": "^2.0.3",
Expand Down
39 changes: 32 additions & 7 deletions src/lib/installPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,39 @@ export default async function installPlugin(
try {
if (!isDependency) loaderDialog.show();

const plugin = await fsOperation(pluginUrl).readFile(
undefined,
(loaded, total) => {
loaderDialog.setMessage(
`${strings.loading} ${((loaded / total) * 100).toFixed(2)}%`,
let plugin;
if (
/^(https?:\/\/)?(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}|localhost)/.test(
pluginUrl,
)
) {
// cordova http plugin for IP addresses and localhost
plugin = await new Promise((resolve, reject) => {
cordova.plugin.http.sendRequest(
pluginUrl,
{
method: "GET",
responseType: "arraybuffer",
},
(response) => {
resolve(response.data);
loaderDialog.setMessage(`${strings.loading} 100%`);
},
(error) => {
reject(error);
},
);
},
);
});
} else {
plugin = await fsOperation(pluginUrl).readFile(
undefined,
(loaded, total) => {
loaderDialog.setMessage(
`${strings.loading} ${((loaded / total) * 100).toFixed(2)}%`,
);
},
);
}

if (plugin) {
const zip = new JSZip();
Expand Down
30 changes: 24 additions & 6 deletions src/sidebarApps/extensions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ function initApp(el) {
if (!$installed) {
$installed = collapsableList(strings["installed"]);
$installed.ontoggle = loadInstalled;
$installed.expand();
//$installed.expand();
container.append($installed);
}

Expand Down Expand Up @@ -339,7 +339,7 @@ function getLocalRes(id, name) {
return Url.join(PLUGIN_DIR, id, name);
}

function ListItem({ icon, name, id, version, downloads, installed }) {
function ListItem({ icon, name, id, version, downloads, installed, source }) {
if (installed === undefined) {
installed = !!installedPlugins.find(({ id: _id }) => _id === id);
}
Expand All @@ -353,10 +353,15 @@ function ListItem({ icon, name, id, version, downloads, installed }) {
{name}
</span>
{installed ? (
<span
className="icon more_vert"
data-action="more-plugin-action"
></span>
<>
{source ? (
<span className="icon replay" data-action="rebuild-plugin"></span>
) : null}
<span
className="icon more_vert"
data-action="more-plugin-action"
></span>
</>
) : (
<button className="install-btn" data-action="install-plugin">
<span className="icon file_downloadget_app"></span>
Expand All @@ -372,6 +377,9 @@ function ListItem({ icon, name, id, version, downloads, installed }) {
const installPluginBtn = event.target.closest(
'[data-action="install-plugin"]',
);
const rebuildPluginBtn = event.target.closest(
'[data-action="rebuild-plugin"]',
);
if (morePluginActionButton) {
more_plugin_action(id, name);
return;
Expand Down Expand Up @@ -416,6 +424,16 @@ function ListItem({ icon, name, id, version, downloads, installed }) {
window.toast(helpers.errorMessage(err), 3000);
}
return;
} else if (rebuildPluginBtn) {
try {
const { default: installPlugin } = await import("lib/installPlugin");
await installPlugin(source);
window.toast(strings["success"], 3000);
} catch (err) {
console.error(err);
window.toast(helpers.errorMessage(err), 3000);
}
return;
}

plugin(
Expand Down
11 changes: 11 additions & 0 deletions src/sidebarApps/extensions/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,17 @@
background-color: var(--active-icon-color);
}
}
.replay {
display: flex;
align-items: center;
cursor: pointer;
justify-content: center;
transition: background-color 0.3s ease;

&:hover {
background-color: var(--active-icon-color);
}
}

.install-btn {
background: none;
Expand Down

0 comments on commit 59d6654

Please sign in to comment.