@copylee/dsh-computer-use 0.7.0 → 0.7.1

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.
Files changed (2) hide show
  1. package/lib/client.js +38 -27
  2. package/package.json +1 -1
package/lib/client.js CHANGED
@@ -915,14 +915,18 @@ window.__ModuleLoader__.load({
915
915
  const [view, setView] = react.useState(void 0);
916
916
  const [draft, setDraft] = react.useState(() => draftFrom(void 0));
917
917
  const [dirty, setDirty] = react.useState(false);
918
+ const dirtyRef = react.useRef(false);
919
+ dirtyRef.current = dirty;
920
+ const draftRef = react.useRef(draft);
921
+ draftRef.current = draft;
918
922
  const [saving, setSaving] = react.useState(false);
923
+ /** The draft whose save failed: not retried until it is edited again. */
924
+ const [failed, setFailed] = react.useState(null);
919
925
  const [message, setMessage] = react.useState(null);
920
926
  const [status, setStatus] = react.useState(null);
921
927
  const [cache, setCache] = react.useState(null);
922
928
  const [cacheBusy, setCacheBusy] = react.useState(false);
923
929
  const [cacheNote, setCacheNote] = react.useState(null);
924
- const dirtyRef = react.useRef(false);
925
- dirtyRef.current = dirty;
926
930
  const load = react.useCallback(async (reset) => {
927
931
  try {
928
932
  const result = await ctx.remote.settings.describe();
@@ -931,7 +935,8 @@ window.__ModuleLoader__.load({
931
935
  setWritable(result.value.writable);
932
936
  setView(found);
933
937
  if (reset || !dirtyRef.current) {
934
- setDraft(draftFrom(found?.value));
938
+ const stored = draftFrom(found?.value);
939
+ if (reset || JSON.stringify(valuesFrom(stored)) !== JSON.stringify(valuesFrom(draftRef.current))) setDraft(stored);
935
940
  setDirty(false);
936
941
  }
937
942
  } catch (error) {
@@ -1010,12 +1015,13 @@ window.__ModuleLoader__.load({
1010
1015
  };
1011
1016
  const errors = validate(draft);
1012
1017
  const invalid = Object.keys(errors).length > 0;
1013
- const disabled = !writable || view === void 0 || saving;
1018
+ const disabled = !writable || view === void 0;
1014
1019
  const save = async () => {
1015
1020
  if (view === void 0 || invalid) return;
1016
1021
  setSaving(true);
1022
+ const saved = draft;
1017
1023
  try {
1018
- const values = valuesFrom(draft);
1024
+ const values = valuesFrom(saved);
1019
1025
  const result = await ctx.remote.settings.mutate(ENTRY_ID, Object.entries(values).map(([key, value]) => ({
1020
1026
  op: "set",
1021
1027
  path: [key],
@@ -1024,12 +1030,16 @@ window.__ModuleLoader__.load({
1024
1030
  if (!result.ok) throw new Error(result.error.message);
1025
1031
  setMessage({
1026
1032
  kind: "ok",
1027
- text: "已保存,下一步操作即生效"
1033
+ text: "已自动保存,下一步操作即生效"
1028
1034
  });
1029
- setDirty(false);
1030
- await load(true);
1035
+ if (draftRef.current === saved) {
1036
+ dirtyRef.current = false;
1037
+ setDirty(false);
1038
+ }
1039
+ await load(false);
1031
1040
  refreshStatus();
1032
1041
  } catch (error) {
1042
+ setFailed(saved);
1033
1043
  setMessage({
1034
1044
  kind: "error",
1035
1045
  text: `保存失败:${error.message}`
@@ -1038,6 +1048,20 @@ window.__ModuleLoader__.load({
1038
1048
  setSaving(false);
1039
1049
  }
1040
1050
  };
1051
+ react.useEffect(() => {
1052
+ if (!dirty || invalid || disabled || saving || failed === draft) return;
1053
+ const timer = setTimeout(() => {
1054
+ save();
1055
+ }, 500);
1056
+ return () => clearTimeout(timer);
1057
+ }, [
1058
+ draft,
1059
+ dirty,
1060
+ invalid,
1061
+ disabled,
1062
+ saving,
1063
+ failed
1064
+ ]);
1041
1065
  const preview = async () => {
1042
1066
  try {
1043
1067
  const response = await fetch(PREVIEW_ROUTE, {
@@ -1274,34 +1298,21 @@ window.__ModuleLoader__.load({
1274
1298
  refreshCache();
1275
1299
  }
1276
1300
  }, cacheBusy ? "统计中…" : "重新统计"), cacheNote === null ? null : h("span", { style: cacheNote.kind === "ok" ? S.ok : S.error }, cacheNote.text))), h("div", { style: S.actions }, h("button", {
1277
- type: "button",
1278
- style: {
1279
- ...S.primary,
1280
- opacity: disabled || !dirty || invalid ? .5 : 1
1281
- },
1282
- disabled: disabled || !dirty || invalid,
1283
- onClick: () => {
1284
- save();
1285
- }
1286
- }, saving ? "保存中…" : "保存"), h("button", {
1287
1301
  type: "button",
1288
1302
  style: S.secondary,
1289
- disabled: !dirty || saving,
1303
+ disabled,
1290
1304
  onClick: () => {
1291
- setDraft(draftFrom(view?.value));
1292
- setDirty(false);
1305
+ setDraft(draftFrom({}));
1306
+ setDirty(true);
1293
1307
  setMessage(null);
1294
1308
  }
1295
- }, "放弃修改"), h("button", {
1309
+ }, "恢复默认"), saving ? h("span", { style: S.hint }, "保存中…") : dirty && invalid ? h("span", { style: S.error }, "有数值超出范围,改好后自动保存") : failed === draft && dirty ? h("button", {
1296
1310
  type: "button",
1297
1311
  style: S.secondary,
1298
- disabled,
1299
1312
  onClick: () => {
1300
- setDraft(draftFrom({}));
1301
- setDirty(true);
1302
- setMessage(null);
1313
+ setFailed(null);
1303
1314
  }
1304
- }, "恢复默认"), dirty ? h("span", { style: S.hint }, "有未保存的修改") : null, message === null ? null : h("span", { style: message.kind === "ok" ? S.ok : S.error }, message.text)), h(AccentPicker, null));
1315
+ }, "重试保存") : null, message === null || dirty && invalid ? null : h("span", { style: message.kind === "ok" ? S.ok : S.error }, message.text)), h(AccentPicker, null));
1305
1316
  }
1306
1317
  const inject = [
1307
1318
  "slots",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@copylee/dsh-computer-use",
3
- "version": "0.7.0",
3
+ "version": "0.7.1",
4
4
  "description": "DeepSeek Harness Computer Use 插件(Windows):让 AI 看屏幕、点鼠标、敲键盘操控电脑;控制时屏幕泛起橙色光晕并显示“DeepSeek Harness 正在操控你的电脑”,按 Esc 暂停 / 继续。",
5
5
  "type": "module",
6
6
  "author": "copylee",