-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathPaletteViewModel.js
More file actions
162 lines (153 loc) · 5.4 KB
/
Copy pathPaletteViewModel.js
File metadata and controls
162 lines (153 loc) · 5.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
function settingsResult() {
return {
mode: "settings",
results: [
{
name: "Plugin settings",
description: "Edit channels and tray defaults",
settingsAction: "plugin"
},
{
name: "Keybindings",
description: "Edit the user-owned Plugin Control shortcut",
settingsAction: "keybindings"
},
{
name: "Cleanly remove Plugin Control and user data",
description: "Remove the plugin with optional user-data cleanup",
settingsAction: "remove-self",
separatorBefore: true,
dangerous: true
},
{
name: "Cancel / Back",
description: "Return to the plugin list",
settingsAction: "cancel"
}
]
}
}
function displayWarning(value) {
var warning = String(value || "").trim()
if (!warning) return ""
if (warning === "Upstream changed"
|| warning === "Validation unknown"
|| warning === "Validation failed"
|| warning === "Unlisted") return warning
if (warning === "Validation unreachable") return "Check unreachable"
if (warning.indexOf("Validation ") === 0) return "Check status"
if (warning.indexOf("Unlisted - ") === 0) {
var review = warning.indexOf("security-review-required") >= 0
var fixes = warning.indexOf("security-needs-fixes") >= 0
if (review && fixes) return "Unlisted: issues"
if (review) return "Unlisted: review"
if (fixes) return "Unlisted: fixes"
return "Unlisted warning"
}
return "Warning"
}
function versionWarningTooltip(record) {
var value = record || {}
if (value.marketplaceListed !== true || value.builtIn === true
|| String(value.verificationStatus || "") === "verified") return ""
if (String(value.verificationCoverage || "") === "update-unverified") {
return "Manifest version reported by Omarchy Plugins. The latest upstream "
+ "commit differs from the verified snapshot."
}
return "Manifest version reported by Omarchy Plugins. The latest upstream "
+ "commit is not covered by marketplace verification."
}
function displayRecord(record) {
var value = record || {}
var versionTooltip = versionWarningTooltip(value)
return {
pluginName: String(value.name || value.id || ""),
pluginId: String(value.id || ""),
description: String(value.description || ""),
author: String(value.author || "Unknown"),
kind: String(value.kind || value.category || "Plugin"),
stateLabel: String(value.stateLabel || "Browse only"),
sourceLabel: String(value.sourceLabel || value.sourceName || "Unknown"),
warning: String(value.warning || ""),
warningLabel: displayWarning(value.warning),
version: String(value.version || ""),
installedVersion: String(value.installedVersion || ""),
versionWarning: versionTooltip !== "",
versionWarningTooltip: versionTooltip,
repository: String(value.repository || ""),
separatorBefore: value.separatorBefore === true,
dangerous: value.dangerous === true
}
}
function updateOption(record) {
var status = String(record && record.updateStatus || "unknown")
var unavailable = ["manual", "dirty", "ahead", "diverged", "unsupported",
"error"]
.indexOf(status) >= 0
return {
operation: "update",
label: "Update",
available: !unavailable,
reason: unavailable ? String(record.updateReason
|| "This plugin cannot be updated safely.") : ""
}
}
function actionOptions(record, readOnly) {
if (readOnly === true)
return [{ operation: "close", label: "Close", available: true }]
var options = [
{ operation: "cancel", label: "Cancel", available: true }
]
if (!record || !record.id) return options
var present = record.builtIn === true || record.installed === true
if (record.fullBar === true) {
if (present && record.enabled === false)
options.push({ operation: "enable", label: "Enable", available: true })
return options
}
if (record.builtIn === true) {
if (record.canDisable === true) {
options.push(record.enabled === false
? { operation: "enable", label: "Enable", available: true }
: { operation: "disable", label: "Disable", available: true })
}
return options
}
if (record.installed === true) {
options.push(updateOption(record))
if (record.canDisable === true) {
options.push(record.enabled === false
? { operation: "enable", label: "Enable", available: true }
: { operation: "disable", label: "Disable", available: true })
}
if (record.removable === true) {
options.push({ operation: "remove", label: "Remove",
available: record.dirty !== true,
reason: record.dirty === true
? "Removal is blocked because this Git checkout has local changes."
: "", dangerous: true })
}
return options
}
if (record.installable === true)
options.push({ operation: "add", label: "Add", available: true })
return options
}
function removableRecord(records, id) {
var values = Array.isArray(records) ? records : []
for (var i = 0; i < values.length; i++) {
var record = values[i]
if (record && record.id === id && record.installed === true
&& record.removable === true) return record
}
return null
}
if (typeof module !== "undefined") {
module.exports = {
actionOptions: actionOptions,
displayRecord: displayRecord,
removableRecord: removableRecord,
settingsResult: settingsResult,
versionWarningTooltip: versionWarningTooltip
}
}