@michengai/dsh-archive-manager 1.3.0 → 1.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +18 -0
- package/CHANGELOG.zh-CN.md +18 -0
- package/README.de.md +4 -10
- package/README.en.md +3 -9
- package/README.es.md +4 -10
- package/README.fr.md +4 -10
- package/README.ja.md +3 -9
- package/README.md +3 -9
- package/README.pt.md +4 -10
- package/README.ru.md +3 -9
- package/README.zh-CN.md +3 -9
- package/lib/client.js +5 -5
- package/lib/index.js +82 -67
- package/lib/plugin-settings.js +31 -28
- package/lib/sidebar-entry.js +90 -61
- package/package.json +27 -26
- package/lib/plugin-updater.js +0 -446
- package/lib/release-age.js +0 -164
package/lib/index.js
CHANGED
|
@@ -1,13 +1,65 @@
|
|
|
1
|
-
import { getEntryLocation,
|
|
2
|
-
import {
|
|
1
|
+
import { getEntryLocation, getSidebarFavoriteStarMode, setEntryLocation, setSidebarFavoriteStarMode } from "./plugin-settings.js";
|
|
2
|
+
import { symbols } from "@deepseek-ai/cordis";
|
|
3
3
|
import { apply as installHost, inject as hostInject } from "./host-install.js";
|
|
4
4
|
import { authorizeExplorerPath } from "./explorer-path-policy.js";
|
|
5
5
|
import { revealPathInSystem } from "./native-explorer.js";
|
|
6
6
|
const inject = ["webServer", ...hostInject];
|
|
7
7
|
const SIDEBAR_ENTRY_ENDPOINT = "/api/michengai/dsh-archive-manager/sidebar-entry";
|
|
8
|
-
const ONLINE_UPDATE_ENDPOINT = "/api/michengai/dsh-archive-manager/online-update";
|
|
9
8
|
const SIDEBAR_FAVORITE_STAR_ENDPOINT = "/api/michengai/dsh-archive-manager/sidebar-favorite-star";
|
|
10
9
|
const OPEN_IN_EXPLORER_ENDPOINT = "/api/michengai/dsh-archive-manager/open-in-explorer";
|
|
10
|
+
const TRUSTED_MUTATION_HEADER = "x-michengai-archive-settings";
|
|
11
|
+
function header(request, name) {
|
|
12
|
+
const value = request.headers?.[name];
|
|
13
|
+
return Array.isArray(value) ? value[0] : value;
|
|
14
|
+
}
|
|
15
|
+
function isLoopbackAddress(value) {
|
|
16
|
+
const address = value?.toLowerCase().replace(/^\[|\]$/g, "");
|
|
17
|
+
return address === "localhost" || address === "localhost." || address === "::1" || address?.startsWith("127.") === true || address?.startsWith("::ffff:127.") === true;
|
|
18
|
+
}
|
|
19
|
+
function isTrustedLocalRequest(request) {
|
|
20
|
+
if (header(request, TRUSTED_MUTATION_HEADER) !== "1") return false;
|
|
21
|
+
if (!isLoopbackAddress(request.socket?.remoteAddress)) return false;
|
|
22
|
+
const site = header(request, "sec-fetch-site");
|
|
23
|
+
if (site !== void 0 && site !== "same-origin") return false;
|
|
24
|
+
const host = header(request, "host");
|
|
25
|
+
if (host === void 0 || host === "") return false;
|
|
26
|
+
const origin = header(request, "origin");
|
|
27
|
+
if (origin === void 0 || origin === "") {
|
|
28
|
+
try {
|
|
29
|
+
return isLoopbackAddress(new URL(`http://${host}`).hostname);
|
|
30
|
+
} catch {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
try {
|
|
35
|
+
const url = new URL(origin);
|
|
36
|
+
return (url.protocol === "http:" || url.protocol === "https:") && isLoopbackAddress(url.hostname) && url.host === host;
|
|
37
|
+
} catch {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
const managedRoutes = Symbol.for("dsh-archive-manager.managed-routes");
|
|
42
|
+
function managedRouteBag(server) {
|
|
43
|
+
const owner = server;
|
|
44
|
+
return owner[managedRoutes] ?? (owner[managedRoutes] = /* @__PURE__ */ new Map());
|
|
45
|
+
}
|
|
46
|
+
function rawService(service) {
|
|
47
|
+
const original = Reflect.get(service, symbols.original);
|
|
48
|
+
return original !== null && typeof original === "object" ? original : service;
|
|
49
|
+
}
|
|
50
|
+
function releaseManagedRoute(server, path) {
|
|
51
|
+
const raw = rawService(server);
|
|
52
|
+
const bag = managedRouteBag(raw);
|
|
53
|
+
const owned = bag.get(path);
|
|
54
|
+
if (owned !== void 0) {
|
|
55
|
+
bag.delete(path);
|
|
56
|
+
owned();
|
|
57
|
+
}
|
|
58
|
+
for (const key of ["exact", "prefixes"]) {
|
|
59
|
+
const table = Reflect.get(raw, key);
|
|
60
|
+
if (table instanceof Map && table.has(path)) table.delete(path);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
11
63
|
function sendJson(response, statusCode, value) {
|
|
12
64
|
response.writeHead(statusCode, { "content-type": "application/json; charset=utf-8", "cache-control": "no-store" });
|
|
13
65
|
response.end(JSON.stringify(value));
|
|
@@ -34,12 +86,11 @@ function readJsonBody(request) {
|
|
|
34
86
|
request.on("error", () => resolve(null));
|
|
35
87
|
});
|
|
36
88
|
}
|
|
37
|
-
function registerSettingsRoutes(ctx
|
|
89
|
+
function registerSettingsRoutes(ctx) {
|
|
38
90
|
const server = rawService(ctx.webServer);
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
releaseUpdateRoute(server, OPEN_IN_EXPLORER_ENDPOINT);
|
|
91
|
+
releaseManagedRoute(server, SIDEBAR_ENTRY_ENDPOINT);
|
|
92
|
+
releaseManagedRoute(server, SIDEBAR_FAVORITE_STAR_ENDPOINT);
|
|
93
|
+
releaseManagedRoute(server, OPEN_IN_EXPLORER_ENDPOINT);
|
|
43
94
|
const disposeSidebar = ctx.webServer.register({
|
|
44
95
|
kind: "exact",
|
|
45
96
|
path: SIDEBAR_ENTRY_ENDPOINT,
|
|
@@ -50,7 +101,7 @@ function registerSettingsRoutes(ctx, hostUpdateDisabled) {
|
|
|
50
101
|
return;
|
|
51
102
|
}
|
|
52
103
|
if (request.method === "POST") {
|
|
53
|
-
if (!
|
|
104
|
+
if (!isTrustedLocalRequest(request)) {
|
|
54
105
|
sendJson(response, 403, { ok: false, error: "\u5DF2\u62D2\u7EDD\u975E\u672C\u673A\u540C\u6E90\u8BF7\u6C42\u3002" });
|
|
55
106
|
return;
|
|
56
107
|
}
|
|
@@ -85,53 +136,35 @@ function registerSettingsRoutes(ctx, hostUpdateDisabled) {
|
|
|
85
136
|
path: SIDEBAR_FAVORITE_STAR_ENDPOINT,
|
|
86
137
|
handler: async (request, response) => {
|
|
87
138
|
if (request.method === "GET" || request.method === "HEAD") {
|
|
88
|
-
const
|
|
89
|
-
sendJson(response, 200, { ok: true, enabled });
|
|
139
|
+
const mode = await getSidebarFavoriteStarMode();
|
|
140
|
+
sendJson(response, 200, { ok: true, mode, enabled: mode !== "none" });
|
|
90
141
|
return;
|
|
91
142
|
}
|
|
92
143
|
if (request.method === "POST") {
|
|
93
|
-
if (!
|
|
144
|
+
if (!isTrustedLocalRequest(request)) {
|
|
94
145
|
sendJson(response, 403, { ok: false, error: "\u5DF2\u62D2\u7EDD\u975E\u672C\u673A\u540C\u6E90\u8BF7\u6C42\u3002" });
|
|
95
146
|
return;
|
|
96
147
|
}
|
|
97
148
|
const body = await readJsonBody(request);
|
|
98
|
-
if (!body
|
|
99
|
-
sendJson(response, 400, { ok: false, error: "
|
|
100
|
-
return;
|
|
101
|
-
}
|
|
102
|
-
const enabled = await setSidebarFavoriteStar(body.enabled);
|
|
103
|
-
sendJson(response, 200, { ok: true, enabled });
|
|
104
|
-
return;
|
|
105
|
-
}
|
|
106
|
-
response.writeHead(405, { allow: "GET, HEAD, POST" });
|
|
107
|
-
response.end();
|
|
108
|
-
}
|
|
109
|
-
});
|
|
110
|
-
const disposeUpdate = ctx.webServer.register({
|
|
111
|
-
kind: "exact",
|
|
112
|
-
path: ONLINE_UPDATE_ENDPOINT,
|
|
113
|
-
handler: async (request, response) => {
|
|
114
|
-
if (request.method === "GET" || request.method === "HEAD") {
|
|
115
|
-
const enabled = !hostUpdateDisabled && await getOnlineUpdate();
|
|
116
|
-
sendJson(response, 200, { ok: true, enabled, locked: hostUpdateDisabled });
|
|
117
|
-
return;
|
|
118
|
-
}
|
|
119
|
-
if (request.method === "POST") {
|
|
120
|
-
if (!isTrustedUpdateRequest(request)) {
|
|
121
|
-
sendJson(response, 403, { ok: false, error: "\u5DF2\u62D2\u7EDD\u975E\u672C\u673A\u540C\u6E90\u8BF7\u6C42\u3002" });
|
|
122
|
-
return;
|
|
123
|
-
}
|
|
124
|
-
if (hostUpdateDisabled) {
|
|
125
|
-
sendJson(response, 403, { ok: false, error: "\u5728\u7EBF\u66F4\u65B0\u5DF2\u88AB\u5BBF\u4E3B\u914D\u7F6E\u9501\u5B9A\u7981\u7528" });
|
|
149
|
+
if (!body) {
|
|
150
|
+
sendJson(response, 400, { ok: false, error: "\u8BF7\u6C42\u4F53\u4E0D\u80FD\u4E3A\u7A7A" });
|
|
126
151
|
return;
|
|
127
152
|
}
|
|
128
|
-
|
|
129
|
-
if (
|
|
130
|
-
|
|
153
|
+
let targetMode;
|
|
154
|
+
if (typeof body.mode === "string") {
|
|
155
|
+
if (body.mode !== "all" && body.mode !== "favorites" && body.mode !== "none") {
|
|
156
|
+
sendJson(response, 400, { ok: false, error: "mode \u5FC5\u987B\u662F all\u3001favorites \u6216 none" });
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
targetMode = body.mode;
|
|
160
|
+
} else if (typeof body.enabled === "boolean") {
|
|
161
|
+
targetMode = body.enabled ? "all" : "none";
|
|
162
|
+
} else {
|
|
163
|
+
sendJson(response, 400, { ok: false, error: "\u7F3A\u5C11\u5408\u6CD5\u7684 mode \u6216 enabled \u53C2\u6570" });
|
|
131
164
|
return;
|
|
132
165
|
}
|
|
133
|
-
const
|
|
134
|
-
sendJson(response, 200, { ok: true, enabled });
|
|
166
|
+
const mode = await setSidebarFavoriteStarMode(targetMode);
|
|
167
|
+
sendJson(response, 200, { ok: true, mode, enabled: mode !== "none" });
|
|
135
168
|
return;
|
|
136
169
|
}
|
|
137
170
|
response.writeHead(405, { allow: "GET, HEAD, POST" });
|
|
@@ -147,7 +180,7 @@ function registerSettingsRoutes(ctx, hostUpdateDisabled) {
|
|
|
147
180
|
response.end();
|
|
148
181
|
return;
|
|
149
182
|
}
|
|
150
|
-
if (!
|
|
183
|
+
if (!isTrustedLocalRequest(request)) {
|
|
151
184
|
sendJson(response, 403, { ok: false, error: "\u5DF2\u62D2\u7EDD\u975E\u672C\u673A\u540C\u6E90\u8BF7\u6C42\u3002" });
|
|
152
185
|
return;
|
|
153
186
|
}
|
|
@@ -178,48 +211,29 @@ function registerSettingsRoutes(ctx, hostUpdateDisabled) {
|
|
|
178
211
|
disposeFavoriteStar();
|
|
179
212
|
} catch {
|
|
180
213
|
}
|
|
181
|
-
try {
|
|
182
|
-
disposeUpdate();
|
|
183
|
-
} catch {
|
|
184
|
-
}
|
|
185
214
|
try {
|
|
186
215
|
disposeOpenExplorer();
|
|
187
216
|
} catch {
|
|
188
217
|
}
|
|
189
218
|
};
|
|
190
219
|
}
|
|
191
|
-
async function apply(ctx,
|
|
192
|
-
const hostUpdateDisabled = config?.updater === false || config?.onlineUpdate === false;
|
|
193
|
-
let disposeUpdater = () => {
|
|
194
|
-
};
|
|
220
|
+
async function apply(ctx, _config) {
|
|
195
221
|
let disposeSettingsRoutes = () => {
|
|
196
222
|
};
|
|
197
223
|
try {
|
|
198
|
-
disposeSettingsRoutes = registerSettingsRoutes(ctx
|
|
224
|
+
disposeSettingsRoutes = registerSettingsRoutes(ctx);
|
|
199
225
|
} catch (error) {
|
|
200
226
|
ctx.logger?.warn?.(`archive-manager: settings routes skipped: ${String(error)}`);
|
|
201
227
|
}
|
|
202
|
-
try {
|
|
203
|
-
disposeUpdater = registerPluginUpdater(ctx, {
|
|
204
|
-
endpoint: "/api/michengai/dsh-archive-manager/update",
|
|
205
|
-
packageName: "@michengai/dsh-archive-manager",
|
|
206
|
-
manifestUrl: new URL("../package.json", import.meta.url),
|
|
207
|
-
isEnabled: async () => !hostUpdateDisabled && await getOnlineUpdate()
|
|
208
|
-
});
|
|
209
|
-
} catch (error) {
|
|
210
|
-
ctx.logger?.warn?.(`archive-manager: update route skipped: ${String(error)}`);
|
|
211
|
-
}
|
|
212
228
|
let disposeHost;
|
|
213
229
|
try {
|
|
214
230
|
disposeHost = await installHost(ctx);
|
|
215
231
|
} catch (error) {
|
|
216
|
-
disposeUpdater();
|
|
217
232
|
disposeSettingsRoutes();
|
|
218
233
|
throw error;
|
|
219
234
|
}
|
|
220
235
|
return async () => {
|
|
221
236
|
try {
|
|
222
|
-
disposeUpdater();
|
|
223
237
|
disposeSettingsRoutes();
|
|
224
238
|
} finally {
|
|
225
239
|
await disposeHost();
|
|
@@ -231,5 +245,6 @@ export {
|
|
|
231
245
|
SIDEBAR_FAVORITE_STAR_ENDPOINT,
|
|
232
246
|
apply,
|
|
233
247
|
inject,
|
|
248
|
+
isTrustedLocalRequest,
|
|
234
249
|
registerSettingsRoutes
|
|
235
250
|
};
|
package/lib/plugin-settings.js
CHANGED
|
@@ -3,6 +3,11 @@ import { existsSync, mkdirSync } from "node:fs";
|
|
|
3
3
|
import { readFile, rename, unlink, writeFile } from "node:fs/promises";
|
|
4
4
|
import { homedir } from "node:os";
|
|
5
5
|
import { dirname, join } from "node:path";
|
|
6
|
+
function normalizeFavoriteStarMode(value) {
|
|
7
|
+
if (value === "all" || value === "favorites" || value === "none") return value;
|
|
8
|
+
if (value === false) return "none";
|
|
9
|
+
return "all";
|
|
10
|
+
}
|
|
6
11
|
function resolveDshHome() {
|
|
7
12
|
const custom = process.env.DSH_HOME;
|
|
8
13
|
if (typeof custom === "string" && custom.trim() !== "") {
|
|
@@ -61,8 +66,7 @@ async function readSettings() {
|
|
|
61
66
|
const defaultSettings = {
|
|
62
67
|
entryLocation: "settings",
|
|
63
68
|
sidebarEntry: false,
|
|
64
|
-
|
|
65
|
-
sidebarFavoriteStar: true
|
|
69
|
+
sidebarFavoriteStar: "all"
|
|
66
70
|
};
|
|
67
71
|
if (!existsSync(path)) {
|
|
68
72
|
return defaultSettings;
|
|
@@ -85,8 +89,7 @@ async function readSettings() {
|
|
|
85
89
|
return {
|
|
86
90
|
entryLocation,
|
|
87
91
|
sidebarEntry: entryLocation !== "settings",
|
|
88
|
-
|
|
89
|
-
sidebarFavoriteStar: typeof item.sidebarFavoriteStar === "boolean" ? item.sidebarFavoriteStar : true
|
|
92
|
+
sidebarFavoriteStar: normalizeFavoriteStarMode(item.sidebarFavoriteStar)
|
|
90
93
|
};
|
|
91
94
|
} catch {
|
|
92
95
|
return defaultSettings;
|
|
@@ -98,8 +101,7 @@ async function writeSettings(next) {
|
|
|
98
101
|
const normalized = {
|
|
99
102
|
entryLocation: location,
|
|
100
103
|
sidebarEntry: location !== "settings",
|
|
101
|
-
|
|
102
|
-
sidebarFavoriteStar: next.sidebarFavoriteStar !== false
|
|
104
|
+
sidebarFavoriteStar: normalizeFavoriteStarMode(next.sidebarFavoriteStar)
|
|
103
105
|
};
|
|
104
106
|
const serialized = `${JSON.stringify(normalized, null, 2)}
|
|
105
107
|
`;
|
|
@@ -123,61 +125,62 @@ async function setEntryLocation(location) {
|
|
|
123
125
|
}
|
|
124
126
|
async function getSidebarEntry() {
|
|
125
127
|
const current = await readSettings();
|
|
126
|
-
return current.entryLocation !== "settings";
|
|
128
|
+
return current.sidebarEntry ?? current.entryLocation !== "settings";
|
|
127
129
|
}
|
|
128
130
|
async function setSidebarEntry(enabled) {
|
|
129
131
|
if (typeof enabled !== "boolean") {
|
|
130
132
|
throw new TypeError("sidebarEntry must be a boolean");
|
|
131
133
|
}
|
|
132
134
|
return enqueueWrite(async () => {
|
|
133
|
-
const location = enabled ? "both" : "settings";
|
|
134
135
|
const current = await readSettings();
|
|
136
|
+
const location = enabled ? current.entryLocation === "settings" ? "both" : current.entryLocation ?? "both" : "settings";
|
|
135
137
|
current.entryLocation = location;
|
|
136
138
|
current.sidebarEntry = enabled;
|
|
137
139
|
await writeSettings(current);
|
|
138
140
|
return enabled;
|
|
139
141
|
});
|
|
140
142
|
}
|
|
141
|
-
async function
|
|
143
|
+
async function getSidebarFavoriteStarMode() {
|
|
142
144
|
const current = await readSettings();
|
|
143
|
-
return current.
|
|
145
|
+
return normalizeFavoriteStarMode(current.sidebarFavoriteStar);
|
|
144
146
|
}
|
|
145
|
-
async function
|
|
146
|
-
if (
|
|
147
|
-
throw new TypeError("
|
|
147
|
+
async function setSidebarFavoriteStarMode(mode) {
|
|
148
|
+
if (mode !== "all" && mode !== "favorites" && mode !== "none") {
|
|
149
|
+
throw new TypeError("sidebarFavoriteStar mode must be 'all', 'favorites', or 'none'");
|
|
148
150
|
}
|
|
149
151
|
return enqueueWrite(async () => {
|
|
150
152
|
const current = await readSettings();
|
|
151
|
-
current.
|
|
153
|
+
current.sidebarFavoriteStar = mode;
|
|
152
154
|
await writeSettings(current);
|
|
153
|
-
return
|
|
155
|
+
return mode;
|
|
154
156
|
});
|
|
155
157
|
}
|
|
156
158
|
async function getSidebarFavoriteStar() {
|
|
157
|
-
const
|
|
158
|
-
return
|
|
159
|
+
const mode = await getSidebarFavoriteStarMode();
|
|
160
|
+
return mode !== "none";
|
|
159
161
|
}
|
|
160
|
-
async function setSidebarFavoriteStar(
|
|
161
|
-
if (typeof
|
|
162
|
-
throw new TypeError("sidebarFavoriteStar must be a boolean");
|
|
162
|
+
async function setSidebarFavoriteStar(value) {
|
|
163
|
+
if (typeof value !== "boolean" && value !== "all" && value !== "favorites" && value !== "none") {
|
|
164
|
+
throw new TypeError("sidebarFavoriteStar must be 'all', 'favorites', 'none', or a boolean");
|
|
163
165
|
}
|
|
164
|
-
|
|
165
|
-
const
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
166
|
+
if (typeof value === "boolean") {
|
|
167
|
+
const mode = value ? "all" : "none";
|
|
168
|
+
await setSidebarFavoriteStarMode(mode);
|
|
169
|
+
return value;
|
|
170
|
+
}
|
|
171
|
+
return setSidebarFavoriteStarMode(value);
|
|
170
172
|
}
|
|
171
173
|
export {
|
|
172
174
|
getEntryLocation,
|
|
173
|
-
getOnlineUpdate,
|
|
174
175
|
getSidebarEntry,
|
|
175
176
|
getSidebarFavoriteStar,
|
|
177
|
+
getSidebarFavoriteStarMode,
|
|
176
178
|
managerSettingsPath,
|
|
179
|
+
normalizeFavoriteStarMode,
|
|
177
180
|
readSettings,
|
|
178
181
|
setEntryLocation,
|
|
179
|
-
setOnlineUpdate,
|
|
180
182
|
setSidebarEntry,
|
|
181
183
|
setSidebarFavoriteStar,
|
|
184
|
+
setSidebarFavoriteStarMode,
|
|
182
185
|
writeSettings
|
|
183
186
|
};
|
package/lib/sidebar-entry.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
-
import { IconArchiveOutlineMedium, SegmentedControl
|
|
2
|
+
import { IconArchiveOutlineMedium, SegmentedControl } from "@deepseek-ai/dsh-client-ui-primitives";
|
|
3
3
|
const h = React.createElement;
|
|
4
4
|
const BUNDLE_KEY = "@michengai/dsh-archive-manager";
|
|
5
5
|
const SIDEBAR_PANEL_ID = "archived-sessions";
|
|
@@ -37,15 +37,14 @@ function ArchiveBundleConfigCard(props) {
|
|
|
37
37
|
enabled = false,
|
|
38
38
|
onToggle,
|
|
39
39
|
disabled,
|
|
40
|
-
onlineUpdateEnabled = true,
|
|
41
|
-
onToggleOnlineUpdate,
|
|
42
|
-
onlineUpdateDisabled,
|
|
43
|
-
onlineUpdateLocked = false,
|
|
44
40
|
sidebarFavoriteStarEnabled = true,
|
|
45
41
|
onToggleSidebarFavoriteStar,
|
|
46
|
-
sidebarFavoriteStarDisabled
|
|
42
|
+
sidebarFavoriteStarDisabled,
|
|
43
|
+
sidebarFavoriteStarMode: propStarMode,
|
|
44
|
+
onSidebarFavoriteStarModeChange
|
|
47
45
|
} = props;
|
|
48
46
|
const effectiveLocation = propLocation ?? (enabled ? "both" : "settings");
|
|
47
|
+
const effectiveStarMode = propStarMode ?? (sidebarFavoriteStarEnabled === false ? "none" : "all");
|
|
49
48
|
const handleLocationChange = (next) => {
|
|
50
49
|
if (next === "both" || next === "sidebar" || next === "settings") {
|
|
51
50
|
if (typeof onLocationChange === "function") {
|
|
@@ -55,6 +54,15 @@ function ArchiveBundleConfigCard(props) {
|
|
|
55
54
|
}
|
|
56
55
|
}
|
|
57
56
|
};
|
|
57
|
+
const handleStarModeChange = (next) => {
|
|
58
|
+
if (next === "all" || next === "favorites" || next === "none") {
|
|
59
|
+
if (typeof onSidebarFavoriteStarModeChange === "function") {
|
|
60
|
+
onSidebarFavoriteStarModeChange(next);
|
|
61
|
+
} else if (typeof onToggleSidebarFavoriteStar === "function") {
|
|
62
|
+
onToggleSidebarFavoriteStar(next !== "none");
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
};
|
|
58
66
|
const rows = [
|
|
59
67
|
h(
|
|
60
68
|
"div",
|
|
@@ -80,7 +88,7 @@ function ArchiveBundleConfigCard(props) {
|
|
|
80
88
|
})
|
|
81
89
|
)
|
|
82
90
|
];
|
|
83
|
-
if (typeof onToggleSidebarFavoriteStar === "function") {
|
|
91
|
+
if (typeof onSidebarFavoriteStarModeChange === "function" || typeof onToggleSidebarFavoriteStar === "function") {
|
|
84
92
|
rows.push(
|
|
85
93
|
h(
|
|
86
94
|
"div",
|
|
@@ -91,11 +99,17 @@ function ArchiveBundleConfigCard(props) {
|
|
|
91
99
|
h("span", { className: "dsham_bundle_title" }, t("sidebar.favoriteStar.title")),
|
|
92
100
|
h("span", { className: "dsham_bundle_desc" }, t("sidebar.favoriteStar.desc"))
|
|
93
101
|
),
|
|
94
|
-
h(
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
102
|
+
h(SegmentedControl, {
|
|
103
|
+
id: "dsham-bundle-favorite-star-mode",
|
|
104
|
+
value: effectiveStarMode,
|
|
105
|
+
onChange: handleStarModeChange,
|
|
106
|
+
label: t("sidebar.favoriteStar.title"),
|
|
107
|
+
disabled: sidebarFavoriteStarDisabled ?? disabled,
|
|
108
|
+
options: [
|
|
109
|
+
{ value: "all", label: t("sidebar.favoriteStar.all") },
|
|
110
|
+
{ value: "favorites", label: t("sidebar.favoriteStar.favorites") },
|
|
111
|
+
{ value: "none", label: t("sidebar.favoriteStar.none") }
|
|
112
|
+
]
|
|
99
113
|
})
|
|
100
114
|
)
|
|
101
115
|
);
|
|
@@ -104,7 +118,12 @@ function ArchiveBundleConfigCard(props) {
|
|
|
104
118
|
}
|
|
105
119
|
function ArchiveBundleConfigCardWrapper(props) {
|
|
106
120
|
const [location, setLocation] = React.useState(props.getLocation);
|
|
107
|
-
const
|
|
121
|
+
const resolveInitialStarMode = () => {
|
|
122
|
+
if (props.getSidebarFavoriteStarMode) return props.getSidebarFavoriteStarMode();
|
|
123
|
+
if (props.getSidebarFavoriteStarEnabled) return props.getSidebarFavoriteStarEnabled() ? "all" : "none";
|
|
124
|
+
return "all";
|
|
125
|
+
};
|
|
126
|
+
const [sidebarFavoriteStarMode, setSidebarFavoriteStarMode] = React.useState(resolveInitialStarMode);
|
|
108
127
|
const [saveError, setSaveError] = React.useState(null);
|
|
109
128
|
const [savingLocation, setSavingLocation] = React.useState(false);
|
|
110
129
|
const [savingFavoriteStar, setSavingFavoriteStar] = React.useState(false);
|
|
@@ -112,8 +131,10 @@ function ArchiveBundleConfigCardWrapper(props) {
|
|
|
112
131
|
const syncState = () => {
|
|
113
132
|
setLocation(props.getLocation());
|
|
114
133
|
setSaveError(null);
|
|
115
|
-
if (props.
|
|
116
|
-
|
|
134
|
+
if (props.getSidebarFavoriteStarMode) {
|
|
135
|
+
setSidebarFavoriteStarMode(props.getSidebarFavoriteStarMode());
|
|
136
|
+
} else if (props.getSidebarFavoriteStarEnabled) {
|
|
137
|
+
setSidebarFavoriteStarMode(props.getSidebarFavoriteStarEnabled() ? "all" : "none");
|
|
117
138
|
}
|
|
118
139
|
};
|
|
119
140
|
syncState();
|
|
@@ -131,13 +152,12 @@ function ArchiveBundleConfigCardWrapper(props) {
|
|
|
131
152
|
setSavingLocation(false);
|
|
132
153
|
});
|
|
133
154
|
};
|
|
134
|
-
const
|
|
155
|
+
const onSidebarFavoriteStarModeChange = props.setSidebarFavoriteStarMode || props.setSidebarFavoriteStar ? (next) => {
|
|
135
156
|
setSavingFavoriteStar(true);
|
|
136
|
-
|
|
137
|
-
props.
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
}
|
|
157
|
+
setSidebarFavoriteStarMode(next);
|
|
158
|
+
const savePromise = props.setSidebarFavoriteStarMode ? props.setSidebarFavoriteStarMode(next) : props.setSidebarFavoriteStar(next !== "none");
|
|
159
|
+
savePromise.catch(() => {
|
|
160
|
+
setSidebarFavoriteStarMode(resolveInitialStarMode());
|
|
141
161
|
}).finally(() => {
|
|
142
162
|
setSavingFavoriteStar(false);
|
|
143
163
|
});
|
|
@@ -148,9 +168,11 @@ function ArchiveBundleConfigCardWrapper(props) {
|
|
|
148
168
|
errorMessage: saveError,
|
|
149
169
|
disabled: savingLocation,
|
|
150
170
|
onLocationChange,
|
|
151
|
-
|
|
171
|
+
sidebarFavoriteStarMode,
|
|
172
|
+
sidebarFavoriteStarEnabled: sidebarFavoriteStarMode !== "none",
|
|
152
173
|
sidebarFavoriteStarDisabled: savingFavoriteStar,
|
|
153
|
-
|
|
174
|
+
onSidebarFavoriteStarModeChange,
|
|
175
|
+
onToggleSidebarFavoriteStar: onSidebarFavoriteStarModeChange ? (enabled) => onSidebarFavoriteStarModeChange(enabled ? "all" : "none") : void 0
|
|
154
176
|
});
|
|
155
177
|
}
|
|
156
178
|
function setupSidebarEntry(ctx, options) {
|
|
@@ -163,11 +185,10 @@ function setupSidebarEntry(ctx, options) {
|
|
|
163
185
|
isEnabled: () => false,
|
|
164
186
|
isSupported: () => false,
|
|
165
187
|
setEnabled: async () => false,
|
|
166
|
-
isOnlineUpdateEnabled: () => true,
|
|
167
|
-
isOnlineUpdateLocked: () => false,
|
|
168
|
-
setOnlineUpdate: async () => false,
|
|
169
188
|
isSidebarFavoriteStarEnabled: () => true,
|
|
170
189
|
setSidebarFavoriteStar: async () => false,
|
|
190
|
+
getSidebarFavoriteStarMode: () => "all",
|
|
191
|
+
setSidebarFavoriteStarMode: async () => "all",
|
|
171
192
|
destroy: () => {
|
|
172
193
|
}
|
|
173
194
|
};
|
|
@@ -294,30 +315,22 @@ function setupSidebarEntry(ctx, options) {
|
|
|
294
315
|
await setLocation(next ? "both" : "settings");
|
|
295
316
|
return isSidebarEnabled();
|
|
296
317
|
};
|
|
297
|
-
let
|
|
298
|
-
let
|
|
299
|
-
const
|
|
300
|
-
if (destroyed
|
|
301
|
-
|
|
318
|
+
let sidebarFavoriteStarMode = "all";
|
|
319
|
+
let favoriteStarEpoch = 0;
|
|
320
|
+
const setSidebarFavoriteStarMode = async (next) => {
|
|
321
|
+
if (destroyed) return sidebarFavoriteStarMode;
|
|
322
|
+
const currentEpoch = ++favoriteStarEpoch;
|
|
323
|
+
const previous = sidebarFavoriteStarMode;
|
|
324
|
+
sidebarFavoriteStarMode = next;
|
|
302
325
|
notify();
|
|
303
|
-
if (typeof options.
|
|
326
|
+
if (typeof options.onSidebarFavoriteStarModeChange === "function") {
|
|
304
327
|
try {
|
|
305
|
-
options.
|
|
328
|
+
options.onSidebarFavoriteStarModeChange(next);
|
|
306
329
|
} catch {
|
|
307
330
|
}
|
|
308
|
-
}
|
|
309
|
-
return next;
|
|
310
|
-
};
|
|
311
|
-
let sidebarFavoriteStarEnabled = true;
|
|
312
|
-
let favoriteStarEpoch = 0;
|
|
313
|
-
const setSidebarFavoriteStar = async (next) => {
|
|
314
|
-
if (destroyed) return sidebarFavoriteStarEnabled;
|
|
315
|
-
const currentEpoch = ++favoriteStarEpoch;
|
|
316
|
-
sidebarFavoriteStarEnabled = next;
|
|
317
|
-
notify();
|
|
318
|
-
if (typeof options.onSidebarFavoriteStarChange === "function") {
|
|
331
|
+
} else if (typeof options.onSidebarFavoriteStarChange === "function") {
|
|
319
332
|
try {
|
|
320
|
-
options.onSidebarFavoriteStarChange(next);
|
|
333
|
+
options.onSidebarFavoriteStarChange(next !== "none");
|
|
321
334
|
} catch {
|
|
322
335
|
}
|
|
323
336
|
}
|
|
@@ -325,16 +338,21 @@ function setupSidebarEntry(ctx, options) {
|
|
|
325
338
|
await callApi("/sidebar-favorite-star", {
|
|
326
339
|
method: "POST",
|
|
327
340
|
headers: { "content-type": "application/json" },
|
|
328
|
-
body: JSON.stringify({ enabled: next })
|
|
341
|
+
body: JSON.stringify({ mode: next, enabled: next !== "none" })
|
|
329
342
|
});
|
|
330
343
|
return next;
|
|
331
344
|
} catch (err) {
|
|
332
345
|
if (currentEpoch === favoriteStarEpoch) {
|
|
333
|
-
|
|
346
|
+
sidebarFavoriteStarMode = previous;
|
|
334
347
|
notify();
|
|
335
|
-
if (typeof options.
|
|
348
|
+
if (typeof options.onSidebarFavoriteStarModeChange === "function") {
|
|
349
|
+
try {
|
|
350
|
+
options.onSidebarFavoriteStarModeChange(previous);
|
|
351
|
+
} catch {
|
|
352
|
+
}
|
|
353
|
+
} else if (typeof options.onSidebarFavoriteStarChange === "function") {
|
|
336
354
|
try {
|
|
337
|
-
options.onSidebarFavoriteStarChange(
|
|
355
|
+
options.onSidebarFavoriteStarChange(previous !== "none");
|
|
338
356
|
} catch {
|
|
339
357
|
}
|
|
340
358
|
}
|
|
@@ -342,6 +360,10 @@ function setupSidebarEntry(ctx, options) {
|
|
|
342
360
|
throw err;
|
|
343
361
|
}
|
|
344
362
|
};
|
|
363
|
+
const setSidebarFavoriteStar = async (next) => {
|
|
364
|
+
const res = await setSidebarFavoriteStarMode(next ? "all" : "none");
|
|
365
|
+
return res !== "none";
|
|
366
|
+
};
|
|
345
367
|
const loadEpoch = epoch;
|
|
346
368
|
callApi("/sidebar-entry").then((res) => {
|
|
347
369
|
if (!destroyed && epoch === loadEpoch && res) {
|
|
@@ -363,12 +385,21 @@ function setupSidebarEntry(ctx, options) {
|
|
|
363
385
|
});
|
|
364
386
|
const loadFavoriteStarEpoch = favoriteStarEpoch;
|
|
365
387
|
callApi("/sidebar-favorite-star").then((res) => {
|
|
366
|
-
if (!destroyed && favoriteStarEpoch === loadFavoriteStarEpoch && res
|
|
367
|
-
|
|
388
|
+
if (!destroyed && favoriteStarEpoch === loadFavoriteStarEpoch && res) {
|
|
389
|
+
if (res.mode === "all" || res.mode === "favorites" || res.mode === "none") {
|
|
390
|
+
sidebarFavoriteStarMode = res.mode;
|
|
391
|
+
} else if (typeof res.enabled === "boolean") {
|
|
392
|
+
sidebarFavoriteStarMode = res.enabled ? "all" : "none";
|
|
393
|
+
}
|
|
368
394
|
notify();
|
|
369
|
-
if (typeof options.
|
|
395
|
+
if (typeof options.onSidebarFavoriteStarModeChange === "function") {
|
|
396
|
+
try {
|
|
397
|
+
options.onSidebarFavoriteStarModeChange(sidebarFavoriteStarMode);
|
|
398
|
+
} catch {
|
|
399
|
+
}
|
|
400
|
+
} else if (typeof options.onSidebarFavoriteStarChange === "function") {
|
|
370
401
|
try {
|
|
371
|
-
options.onSidebarFavoriteStarChange(
|
|
402
|
+
options.onSidebarFavoriteStarChange(sidebarFavoriteStarMode !== "none");
|
|
372
403
|
} catch {
|
|
373
404
|
}
|
|
374
405
|
}
|
|
@@ -413,11 +444,10 @@ function setupSidebarEntry(ctx, options) {
|
|
|
413
444
|
setLocation,
|
|
414
445
|
getEnabled: () => isSidebarEnabled(),
|
|
415
446
|
setSidebar: setEnabled,
|
|
416
|
-
|
|
417
|
-
setOnlineUpdate,
|
|
418
|
-
getOnlineUpdateLocked: () => onlineUpdateLocked,
|
|
419
|
-
getSidebarFavoriteStarEnabled: () => sidebarFavoriteStarEnabled,
|
|
447
|
+
getSidebarFavoriteStarEnabled: () => sidebarFavoriteStarMode !== "none",
|
|
420
448
|
setSidebarFavoriteStar,
|
|
449
|
+
getSidebarFavoriteStarMode: () => sidebarFavoriteStarMode,
|
|
450
|
+
setSidebarFavoriteStarMode,
|
|
421
451
|
subscribe: (fn) => {
|
|
422
452
|
listeners.add(fn);
|
|
423
453
|
return () => {
|
|
@@ -434,11 +464,10 @@ function setupSidebarEntry(ctx, options) {
|
|
|
434
464
|
isEnabled: () => isSidebarEnabled(),
|
|
435
465
|
isSupported: () => sidebarSupported,
|
|
436
466
|
setEnabled,
|
|
437
|
-
|
|
438
|
-
isOnlineUpdateLocked: () => onlineUpdateLocked,
|
|
439
|
-
setOnlineUpdate,
|
|
440
|
-
isSidebarFavoriteStarEnabled: () => sidebarFavoriteStarEnabled,
|
|
467
|
+
isSidebarFavoriteStarEnabled: () => sidebarFavoriteStarMode !== "none",
|
|
441
468
|
setSidebarFavoriteStar,
|
|
469
|
+
getSidebarFavoriteStarMode: () => sidebarFavoriteStarMode,
|
|
470
|
+
setSidebarFavoriteStarMode,
|
|
442
471
|
destroy: () => {
|
|
443
472
|
if (destroyed) return;
|
|
444
473
|
destroyed = true;
|