mirror of
https://github.com/yexi-by/dsh-unrestricted.git
synced 2026-11-28 02:30:22 +08:00
修复 Minimal 子代理与预览并发并发布 0.2.4
This commit is contained in:
1 parent
58adb081b9
commit
7beb2d2546
13 files changed
+375
-142
No files matched your search
+61
-63
@@ -30,6 +30,9 @@ window.__ModuleLoader__.load({
|
||||
busy: false
|
||||
};
|
||||
const listeners = /* @__PURE__ */ new Set();
|
||||
const previewRequests = /* @__PURE__ */ new Map();
|
||||
let statusGeneration = 0;
|
||||
let pendingOperations = 0;
|
||||
const view = {
|
||||
getSnapshot: () => snapshot,
|
||||
subscribe: (listener) => {
|
||||
@@ -39,89 +42,80 @@ window.__ModuleLoader__.load({
|
||||
};
|
||||
function publish() {
|
||||
const settingsSnapshot = settings.getSnapshot();
|
||||
const enabled = settingsSnapshot.value?.enabled === true;
|
||||
if (enabled !== snapshot.enabled) invalidatePreviews();
|
||||
snapshot = {
|
||||
enabled: settingsSnapshot.value?.enabled === true,
|
||||
enabled,
|
||||
writable: settingsSnapshot.writable,
|
||||
settingsStatus: settingsSnapshot.status,
|
||||
status: snapshot.status,
|
||||
previews: snapshot.previews,
|
||||
busy: snapshot.busy,
|
||||
busy: pendingOperations > 0,
|
||||
message: snapshot.message
|
||||
};
|
||||
for (const listener of listeners) listener();
|
||||
}
|
||||
function invalidatePreviews() {
|
||||
previewRequests.clear();
|
||||
snapshot = {
|
||||
...snapshot,
|
||||
previews: {}
|
||||
};
|
||||
}
|
||||
async function call(endpoint, payload) {
|
||||
const result = await connection.rpc.call(RPC_CHANNEL, endpoint, payload);
|
||||
if (!result.ok) throw new Error(result.error.message);
|
||||
return result.value;
|
||||
}
|
||||
async function refresh(invalidatePreviews = false) {
|
||||
snapshot = {
|
||||
...snapshot,
|
||||
busy: true
|
||||
};
|
||||
async function whileBusy(action) {
|
||||
pendingOperations++;
|
||||
publish();
|
||||
try {
|
||||
const status = await call("status", {});
|
||||
snapshot = {
|
||||
...snapshot,
|
||||
status,
|
||||
previews: invalidatePreviews ? {} : snapshot.previews,
|
||||
busy: false,
|
||||
message: void 0
|
||||
};
|
||||
publish();
|
||||
} catch (error) {
|
||||
snapshot = {
|
||||
...snapshot,
|
||||
busy: false,
|
||||
message: messageOf(error)
|
||||
};
|
||||
await action();
|
||||
} finally {
|
||||
pendingOperations--;
|
||||
publish();
|
||||
}
|
||||
}
|
||||
async function setEnabled(enabled) {
|
||||
snapshot = {
|
||||
...snapshot,
|
||||
busy: true
|
||||
};
|
||||
publish();
|
||||
try {
|
||||
await settings.set("enabled", enabled);
|
||||
await refresh(true);
|
||||
} catch (error) {
|
||||
snapshot = {
|
||||
...snapshot,
|
||||
busy: false,
|
||||
message: messageOf(error)
|
||||
};
|
||||
publish();
|
||||
}
|
||||
function readStatus(endpoint, clearPreviews) {
|
||||
const generation = ++statusGeneration;
|
||||
return whileBusy(async () => {
|
||||
try {
|
||||
const status = await call(endpoint, {});
|
||||
if (generation !== statusGeneration) return;
|
||||
if (clearPreviews) invalidatePreviews();
|
||||
snapshot = {
|
||||
...snapshot,
|
||||
status,
|
||||
message: void 0
|
||||
};
|
||||
} catch (error) {
|
||||
if (generation !== statusGeneration) return;
|
||||
snapshot = {
|
||||
...snapshot,
|
||||
message: messageOf(error)
|
||||
};
|
||||
}
|
||||
});
|
||||
}
|
||||
async function recheck() {
|
||||
snapshot = {
|
||||
...snapshot,
|
||||
busy: true
|
||||
};
|
||||
publish();
|
||||
try {
|
||||
const status = await call("recheck", {});
|
||||
snapshot = {
|
||||
...snapshot,
|
||||
status,
|
||||
previews: {},
|
||||
busy: false,
|
||||
message: void 0
|
||||
};
|
||||
publish();
|
||||
} catch (error) {
|
||||
snapshot = {
|
||||
...snapshot,
|
||||
busy: false,
|
||||
message: messageOf(error)
|
||||
};
|
||||
publish();
|
||||
}
|
||||
function refresh(clearPreviews = false) {
|
||||
return readStatus("status", clearPreviews);
|
||||
}
|
||||
function setEnabled(enabled) {
|
||||
return whileBusy(async () => {
|
||||
try {
|
||||
await settings.set("enabled", enabled);
|
||||
await refresh(true);
|
||||
} catch (error) {
|
||||
snapshot = {
|
||||
...snapshot,
|
||||
message: messageOf(error)
|
||||
};
|
||||
}
|
||||
});
|
||||
}
|
||||
function recheck() {
|
||||
return readStatus("recheck", true);
|
||||
}
|
||||
/**
|
||||
* Fetch one preset's deploy preview. The card renders the raw fused prompt,
|
||||
@@ -129,6 +123,8 @@ window.__ModuleLoader__.load({
|
||||
* @param presetId - preset id from the card's row.
|
||||
*/
|
||||
async function loadPreview(presetId) {
|
||||
const request = Symbol(presetId);
|
||||
previewRequests.set(presetId, request);
|
||||
snapshot = {
|
||||
...snapshot,
|
||||
previews: {
|
||||
@@ -139,6 +135,7 @@ window.__ModuleLoader__.load({
|
||||
publish();
|
||||
try {
|
||||
const preview = await call("preview", { presetId });
|
||||
if (previewRequests.get(presetId) !== request) return;
|
||||
snapshot = {
|
||||
...snapshot,
|
||||
previews: {
|
||||
@@ -150,6 +147,7 @@ window.__ModuleLoader__.load({
|
||||
}
|
||||
};
|
||||
} catch (error) {
|
||||
if (previewRequests.get(presetId) !== request) return;
|
||||
snapshot = {
|
||||
...snapshot,
|
||||
previews: {
|
||||
|
||||
Reference in new issue
Block a user