Skip to content

Commit 1d471be

Browse files
committed
[ troubleshooting tools ] added new page with tools.
1 parent f6790d4 commit 1d471be

8 files changed

Lines changed: 237 additions & 125 deletions

File tree

index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,11 @@ electron.app.on("ready", () => {
225225
});
226226
electron.ipcMain.on("exit", (ev, code) => process.exit(code));
227227

228+
electron.ipcMain.on("relaunch-app", (ev) => {
229+
electron.app.relaunch()
230+
electron.app.quit()
231+
})
232+
228233
// announcements
229234
announcements.copy();
230235
if (announcements.available()) {

lib/depject/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ module.exports = {
167167
),
168168
blogs: require("./page/html/render/blogs.js"),
169169
books: require("./page/html/render/books.js"),
170+
troubleshootingTools: require("./page/html/render/troubleshooting-tools.js"),
170171
},
171172
},
172173
},
Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
const { computed, h, Dict, map, dictToCollection, onceTrue } = require("mutant");
2+
const nest = require("depnest");
3+
const renderProgress = require("../../../../progress/html/render");
4+
const fs = require("fs")
5+
const Path = require("path")
6+
const electron = require("electron")
7+
8+
exports.needs = nest({
9+
"sbot.pull.stream": "first",
10+
"sbot.obs.connection": "first",
11+
"config.sync.load": "first",
12+
"progress.obs": {
13+
indexes: "first",
14+
plugins: "first",
15+
replicate: "first",
16+
migration: "first",
17+
peer: "first",
18+
},
19+
"intl.sync.i18n": "first",
20+
});
21+
22+
exports.gives = nest("page.html.render");
23+
24+
exports.create = function (api) {
25+
return nest("page.html.render", function channel(path) {
26+
const indexes = api.progress.obs.indexes();
27+
const indexProgress = computed(indexes, calcProgress);
28+
const pluginIndexes = api.progress.obs.plugins();
29+
const peer = api.progress.obs.peer();
30+
const indexesJson = computed(
31+
[indexes, pluginIndexes],
32+
(indexes, plugins) => {
33+
return JSON.stringify({ indexes, plugins }, null, 4);
34+
},
35+
);
36+
const pluginProgress = computed(
37+
[indexes, pluginIndexes],
38+
(indexes, plugins) => {
39+
const keys = Object.keys(plugins);
40+
const result = [];
41+
keys.forEach((k) => {
42+
const obj = {
43+
target: indexes.target,
44+
start: indexes.start,
45+
current: plugins[k],
46+
};
47+
result.push([k, calcProgress(obj)]);
48+
});
49+
return result;
50+
},
51+
);
52+
const statusObj = computed([peer], (peer) => {
53+
return JSON.stringify(peer, null, 4);
54+
});
55+
const replicateProgress = api.progress.obs.replicate();
56+
const migration = api.progress.obs.migration();
57+
const migrationProgress = computed(migration, calcProgress);
58+
const config = api.config.sync.load()
59+
60+
function clamp(value) {
61+
return Math.min(1, Math.max(0, value)) || 0;
62+
}
63+
64+
function calcProgress(progress) {
65+
const range = progress.target - progress.start;
66+
if (range) {
67+
return (progress.current - progress.start) / range;
68+
} else {
69+
return 1;
70+
}
71+
}
72+
73+
function rebuildAllIndexes() {
74+
onceTrue(api.sbot.obs.connection, (ssb) => {
75+
ssb.rebuild((err) => {
76+
console.log(err)
77+
})
78+
})
79+
}
80+
81+
function deletePrivateIndex() {
82+
console.dir(config)
83+
const flumePath = Path.join(config.path, "flume")
84+
const toUrlFriendly = require('base64-url').escape
85+
const key = `private-${toUrlFriendly(config.keys.public.slice(0, 9))}`
86+
const indexPath = Path.join(flumePath, key)
87+
console.log(indexPath)
88+
if (fs.existsSync(indexPath)) {
89+
fs.rmSync(indexPath, {recursive: true, force: true})
90+
}
91+
electron.ipcRenderer.send("relaunch-app")
92+
}
93+
94+
if (path !== "/troubleshooting-tools") return;
95+
const i18n = api.intl.sync.i18n;
96+
97+
98+
const prepend = [
99+
h("PageHeading", [
100+
h("h1", [
101+
h("strong", i18n("Troubleshooting Tools")),
102+
]),
103+
]),
104+
];
105+
106+
return h("Scroller", { style: { overflow: "auto" } }, [
107+
h("div.wrapper", [
108+
h("section.prepend", prepend),
109+
h("section.content", [
110+
h("TroubleshootingTools", [
111+
// TOOLS
112+
h("div.col", [
113+
h("section", [
114+
h("h2", "Indexing Tools"),
115+
// rebuild all indexes
116+
h("button", {
117+
"ev-click": rebuildAllIndexes
118+
}, "Rebuild all indexes"),
119+
h("span", "This can take a very long time."),
120+
// delete private index
121+
h("button", {
122+
"ev-click": deletePrivateIndex
123+
}, "Delete private index"),
124+
h("span", "This will relaunch Patchwork.")
125+
])
126+
]),
127+
// REPORT ON INDEXES
128+
h("div.col", [
129+
h("h2", i18n("Indexing Report")),
130+
h("IndexingReport", [
131+
h("ReportItem", [
132+
h("span.info", "Index"),
133+
h("meter", {
134+
style: { "margin-left": "10px" },
135+
min: 0,
136+
max: 1,
137+
low: 0.3,
138+
high: 0.6,
139+
optimum: 0.9,
140+
value: indexProgress,
141+
}),
142+
]),
143+
144+
map(pluginProgress, (item) => {
145+
return h("ReportItem", [
146+
h("span.info", item[0]),
147+
h("meter", {
148+
style: { "margin-left": "10px" },
149+
min: 0,
150+
max: 1,
151+
low: 0.5,
152+
high: 0.9,
153+
optimum: 0.97,
154+
value: item[1],
155+
}),
156+
]);
157+
}),
158+
]),
159+
h("h2", "Raw data"),
160+
h("pre", [indexesJson]),
161+
h("h2", i18n("Extra Statuses")),
162+
h("pre", [statusObj]),
163+
]),
164+
]),
165+
]),
166+
]),
167+
]);
168+
});
169+
};

lib/main-window.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,11 @@ module.exports = function (config) {
435435
label: i18n("Status"),
436436
target: "/status",
437437
},
438+
{
439+
type: "normal",
440+
label: i18n("Troubleshooting Tools"),
441+
target: "/troubleshooting-tools",
442+
},
438443
];
439444
return dropTabItems;
440445
}

locales/en.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,5 +418,6 @@
418418
"Neutral": "Neutral",
419419
"Listen": "Listen",
420420
"Ignore": "Ignore",
421-
"Update Gathering": "Update Gathering"
421+
"Update Gathering": "Update Gathering",
422+
"Troubleshooting Tools": "Troubleshooting Tools"
422423
}

0 commit comments

Comments
 (0)