Skip to content

Commit

Permalink
Merge pull request #1017 from bajrangCoder/main
Browse files Browse the repository at this point in the history
feat: Add more action menu in sidebar plugin
  • Loading branch information
bajrangCoder authored Aug 26, 2024
2 parents 4235988 + b60c6d2 commit 7d9c66d
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 1 deletion.
67 changes: 66 additions & 1 deletion src/sidebarApps/extensions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Sidebar from "components/sidebar";
import select from "dialogs/select";
import fsOperation from "fileSystem";
import constants from "lib/constants";
import settings from "lib/settings";
import plugin from "pages/plugin";
import Url from "utils/Url";
import helpers from "utils/helpers";
Expand Down Expand Up @@ -295,10 +296,26 @@ function ListItem({ icon, name, id, version, downloads, installed }) {
>
{name}
</span>
{installed ? (
<span
className="icon more_vert"
data-action="more-plugin-action"
></span>
) : (
""
)}
</div>
);

$el.onclick = () => {
$el.onclick = (event) => {
const morePluginActionButton = event.target.closest(
'[data-action="more-plugin-action"]',
);
if (morePluginActionButton) {
more_plugin_action(id, name);
return;
}

plugin(
{ id, installed },
() => {
Expand Down Expand Up @@ -326,3 +343,51 @@ function ListItem({ icon, name, id, version, downloads, installed }) {

return $el;
}

async function loadAd(el) {
if (!IS_FREE_VERSION) return;
try {
if (!(await window.iad?.isLoaded())) {
const oldText = el.textContent;
el.textContent = strings["loading..."];
await window.iad.load();
el.textContent = oldText;
}
} catch (error) {}
}

async function uninstall(id) {
try {
const pluginDir = Url.join(PLUGIN_DIR, id);
await Promise.all([loadAd(this), fsOperation(pluginDir).delete()]);
acode.unmountPlugin(id);
if (!IS_FREE_VERSION && (await window.iad?.isLoaded())) {
window.iad.show();
}
} catch (err) {
helpers.error(err);
}
}

async function more_plugin_action(id, pluginName) {
let actions;
let pluginSettings = settings.uiSettings[`plugin-${id}`];
if (pluginSettings) {
actions = [strings.settings, strings.uninstall];
} else {
actions = [strings.uninstall];
}
let action = await select("Action", actions);
if (!action) return;
switch (action) {
case strings.settings:
pluginSettings.setTitle(pluginName);
pluginSettings.show();
break;
case strings.uninstall:
await uninstall(id);
const $plugin = $installed.querySelector(`[data-plugin-id="${id}"]`);
$plugin.remove();
break;
}
}
14 changes: 14 additions & 0 deletions src/sidebarApps/extensions/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@
}

.tile {
display: flex;
justify-content: space-between;
align-items: center;

.text {
&.sub-text {
font-size: 0.8rem;
Expand All @@ -64,5 +68,15 @@
}
}
}
.more_vert {
display: flex;
align-items: center;
cursor: pointer;
transition: background-color 0.3s ease;

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

0 comments on commit 7d9c66d

Please sign in to comment.