Skip to content
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

feat: Add more action menu in sidebar plugin #1017

Merged
merged 1 commit into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}
}
}