mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2026-01-28 15:32:50 -05:00
launcher v2: ability to toggle visibility in modal
This commit is contained in:
223
quickshell/Modals/DankLauncherV2/ItemTransformers.js
Normal file
223
quickshell/Modals/DankLauncherV2/ItemTransformers.js
Normal file
@@ -0,0 +1,223 @@
|
||||
.pragma library
|
||||
|
||||
.import "ControllerUtils.js" as Utils
|
||||
|
||||
function transformApp(app, override, defaultActions, primaryActionLabel) {
|
||||
var appId = app.id || app.execString || app.exec || "";
|
||||
|
||||
var actions = [];
|
||||
if (app.actions && app.actions.length > 0) {
|
||||
for (var i = 0; i < app.actions.length; i++) {
|
||||
actions.push({
|
||||
name: app.actions[i].name,
|
||||
icon: "play_arrow",
|
||||
actionData: app.actions[i]
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
id: appId,
|
||||
type: "app",
|
||||
name: override?.name || app.name || "",
|
||||
subtitle: override?.comment || app.comment || "",
|
||||
icon: override?.icon || app.icon || "application-x-executable",
|
||||
iconType: "image",
|
||||
section: "apps",
|
||||
data: app,
|
||||
keywords: app.keywords || [],
|
||||
actions: actions,
|
||||
primaryAction: {
|
||||
name: primaryActionLabel,
|
||||
icon: "open_in_new",
|
||||
action: "launch"
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function transformCoreApp(app, openLabel) {
|
||||
var iconName = "apps";
|
||||
var iconType = "material";
|
||||
|
||||
if (app.icon) {
|
||||
if (app.icon.startsWith("svg+corner:")) {
|
||||
iconType = "composite";
|
||||
} else if (app.icon.startsWith("material:")) {
|
||||
iconName = app.icon.substring(9);
|
||||
} else {
|
||||
iconName = app.icon;
|
||||
iconType = "image";
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
id: app.builtInPluginId || app.action || "",
|
||||
type: "app",
|
||||
name: app.name || "",
|
||||
subtitle: app.comment || "",
|
||||
icon: iconName,
|
||||
iconType: iconType,
|
||||
iconFull: app.icon,
|
||||
section: "apps",
|
||||
data: app,
|
||||
isCore: true,
|
||||
actions: [],
|
||||
primaryAction: {
|
||||
name: openLabel,
|
||||
icon: "open_in_new",
|
||||
action: "launch"
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function transformBuiltInLauncherItem(item, pluginId, openLabel) {
|
||||
var rawIcon = item.icon || "extension";
|
||||
var icon = Utils.stripIconPrefix(rawIcon);
|
||||
var iconType = item.iconType;
|
||||
if (!iconType) {
|
||||
if (rawIcon.startsWith("material:"))
|
||||
iconType = "material";
|
||||
else if (rawIcon.startsWith("unicode:"))
|
||||
iconType = "unicode";
|
||||
else
|
||||
iconType = "image";
|
||||
}
|
||||
|
||||
return {
|
||||
id: item.action || "",
|
||||
type: "plugin",
|
||||
name: item.name || "",
|
||||
subtitle: item.comment || "",
|
||||
icon: icon,
|
||||
iconType: iconType,
|
||||
section: "plugin_" + pluginId,
|
||||
data: item,
|
||||
pluginId: pluginId,
|
||||
isBuiltInLauncher: true,
|
||||
keywords: item.keywords || [],
|
||||
actions: [],
|
||||
primaryAction: {
|
||||
name: openLabel,
|
||||
icon: "open_in_new",
|
||||
action: "execute"
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function transformFileResult(file, openLabel, openFolderLabel, copyPathLabel) {
|
||||
var filename = file.path ? file.path.split("/").pop() : "";
|
||||
var dirname = file.path ? file.path.substring(0, file.path.lastIndexOf("/")) : "";
|
||||
|
||||
return {
|
||||
id: file.path || "",
|
||||
type: "file",
|
||||
name: filename,
|
||||
subtitle: dirname,
|
||||
icon: Utils.getFileIcon(filename),
|
||||
iconType: "material",
|
||||
section: "files",
|
||||
data: file,
|
||||
actions: [
|
||||
{
|
||||
name: openFolderLabel,
|
||||
icon: "folder_open",
|
||||
action: "open_folder"
|
||||
},
|
||||
{
|
||||
name: copyPathLabel,
|
||||
icon: "content_copy",
|
||||
action: "copy_path"
|
||||
}
|
||||
],
|
||||
primaryAction: {
|
||||
name: openLabel,
|
||||
icon: "open_in_new",
|
||||
action: "open"
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function transformPluginItem(item, pluginId, selectLabel) {
|
||||
var rawIcon = item.icon || "extension";
|
||||
var icon = Utils.stripIconPrefix(rawIcon);
|
||||
var iconType = item.iconType;
|
||||
if (!iconType) {
|
||||
if (rawIcon.startsWith("material:"))
|
||||
iconType = "material";
|
||||
else if (rawIcon.startsWith("unicode:"))
|
||||
iconType = "unicode";
|
||||
else
|
||||
iconType = "image";
|
||||
}
|
||||
|
||||
return {
|
||||
id: item.id || item.name || "",
|
||||
type: "plugin",
|
||||
name: item.name || "",
|
||||
subtitle: item.comment || item.description || "",
|
||||
icon: icon,
|
||||
iconType: iconType,
|
||||
section: "plugin_" + pluginId,
|
||||
data: item,
|
||||
pluginId: pluginId,
|
||||
keywords: item.keywords || [],
|
||||
actions: item.actions || [],
|
||||
primaryAction: item.primaryAction || {
|
||||
name: selectLabel,
|
||||
icon: "check",
|
||||
action: "execute"
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function createCalculatorItem(calc, query, copyLabel) {
|
||||
return {
|
||||
id: "calculator_result",
|
||||
type: "calculator",
|
||||
name: calc.displayResult,
|
||||
subtitle: query + " =",
|
||||
icon: "calculate",
|
||||
iconType: "material",
|
||||
section: "calculator",
|
||||
data: {
|
||||
expression: calc.expression,
|
||||
result: calc.result
|
||||
},
|
||||
actions: [],
|
||||
primaryAction: {
|
||||
name: copyLabel,
|
||||
icon: "content_copy",
|
||||
action: "copy"
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function createPluginBrowseItem(pluginId, plugin, trigger, isBuiltIn, isAllowed, browseLabel, triggerLabel, noTriggerLabel) {
|
||||
var rawIcon = isBuiltIn ? (plugin.cornerIcon || "extension") : (plugin.icon || "extension");
|
||||
return {
|
||||
id: "browse_" + pluginId,
|
||||
type: "plugin_browse",
|
||||
name: plugin.name || pluginId,
|
||||
subtitle: trigger ? triggerLabel.replace("%1", trigger) : noTriggerLabel,
|
||||
icon: isBuiltIn ? rawIcon : Utils.stripIconPrefix(rawIcon),
|
||||
iconType: isBuiltIn ? "material" : Utils.detectIconType(rawIcon),
|
||||
section: "browse_plugins",
|
||||
data: {
|
||||
pluginId: pluginId,
|
||||
plugin: plugin,
|
||||
isBuiltIn: isBuiltIn
|
||||
},
|
||||
actions: [
|
||||
{
|
||||
name: "All",
|
||||
icon: isAllowed ? "visibility" : "visibility_off",
|
||||
action: "toggle_all_visibility"
|
||||
}
|
||||
],
|
||||
primaryAction: {
|
||||
name: browseLabel,
|
||||
icon: "arrow_forward",
|
||||
action: "browse_plugin"
|
||||
}
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user