printer-doctor 0.0.0-stage → 0.1.0
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/LICENSE +21 -0
- package/README.md +169 -2
- package/package.json +48 -4
- package/src/index.js +112 -0
- package/src/lib/cups.js +237 -0
- package/src/lib/diagnose.js +430 -0
- package/src/lib/gather.js +317 -0
- package/src/lib/ipp.js +283 -0
- package/src/lib/mdns.js +385 -0
- package/src/lib/net.js +236 -0
- package/src/lib/report.js +128 -0
- package/src/lib/run.js +52 -0
- package/src/lib/text.js +27 -0
- package/src/lib/windows.js +166 -0
|
@@ -0,0 +1,430 @@
|
|
|
1
|
+
// Turns the gathered facts into a verdict a non-technical person can act on. Pure: facts in,
|
|
2
|
+
// { verdict, findings, steps } out, so every rule can be tested with made-up facts.
|
|
3
|
+
import { cleanKeyword, cleanText } from "./text.js";
|
|
4
|
+
|
|
5
|
+
export const LIMITS = {
|
|
6
|
+
stuckJobSec: 300, // a job still waiting after this long, on a printer that is not printing, is stuck
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
// ---------- what a printer says about itself ---------------------------------------------------
|
|
10
|
+
//
|
|
11
|
+
// Printers (and print systems) describe trouble with standard keywords, "printer-state-reasons"
|
|
12
|
+
// in IPP (RFC 8011, section 5.4.12). Each may end in -error, -warning or -report.
|
|
13
|
+
|
|
14
|
+
const REASONS = {
|
|
15
|
+
"media-empty": { says: "is out of paper", step: "paper" },
|
|
16
|
+
"media-needed": { says: "is waiting for paper to be loaded", step: "paper" },
|
|
17
|
+
"media-jam": { says: "has a paper jam", step: "jam" },
|
|
18
|
+
"media-low": { says: "is running low on paper", soft: true, step: "paper" },
|
|
19
|
+
"input-tray-missing": { says: "has a paper tray that is missing or not pushed in all the way", step: "tray" },
|
|
20
|
+
"output-tray-missing": { says: "has its output tray missing", step: "tray" },
|
|
21
|
+
"output-area-full": { says: "has a full output tray", step: "output" },
|
|
22
|
+
"output-area-almost-full": { says: "has an output tray that is nearly full", soft: true, step: "output" },
|
|
23
|
+
"cover-open": { says: "has a cover open", step: "cover" },
|
|
24
|
+
"door-open": { says: "has a door open", step: "cover" },
|
|
25
|
+
"interlock-open": { says: "has a cover or door open", step: "cover" },
|
|
26
|
+
"toner-empty": { says: "is out of toner", step: "supply" },
|
|
27
|
+
"toner-low": { says: "is low on toner", soft: true, step: "supplySoon" },
|
|
28
|
+
"marker-supply-empty": { says: "is out of ink or toner", step: "supply" },
|
|
29
|
+
"marker-supply-low": { says: "is low on ink or toner", soft: true, step: "supplySoon" },
|
|
30
|
+
"marker-waste-full": { says: "has a full waste ink container", step: "service" },
|
|
31
|
+
"marker-waste-almost-full": { says: "has a waste ink container that is nearly full", soft: true, step: "service" },
|
|
32
|
+
"opc-life-over": { says: "needs a new drum (the imaging unit)", step: "supply" },
|
|
33
|
+
"opc-near-eol": { says: "has a drum (the imaging unit) near the end of its life", soft: true, step: "supplySoon" },
|
|
34
|
+
"developer-empty": { says: "is out of developer", step: "supply" },
|
|
35
|
+
"developer-low": { says: "is low on developer", soft: true, step: "supplySoon" },
|
|
36
|
+
"fuser-over-temp": { says: "reports a problem with its heating unit", step: "powerCycle" },
|
|
37
|
+
"fuser-under-temp": { says: "reports a problem with its heating unit", step: "powerCycle" },
|
|
38
|
+
"spool-area-full": { says: "has run out of memory for print jobs", step: "powerCycle" },
|
|
39
|
+
"attention-needed": { says: "needs someone to look at it", step: "panel" },
|
|
40
|
+
"other-error": { says: "reports an error", step: "panel" },
|
|
41
|
+
other: { says: "reports a problem it does not describe", step: "panel" },
|
|
42
|
+
shutdown: { says: "is switched off or shutting down", step: "power" },
|
|
43
|
+
"timed-out": { says: "is not answering", step: "power" },
|
|
44
|
+
"stopped-partly": { says: "has partly stopped", step: "panel" },
|
|
45
|
+
"cups-missing-filter": { says: "has missing printer software on this computer", soft: true, step: "readd", computer: true },
|
|
46
|
+
"cups-insecure-filter": { says: "has printer software on this computer with wrong file permissions", soft: true, step: "readd", computer: true },
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
// Said while things are working normally; not a problem.
|
|
50
|
+
const QUIET = /^(none|cups-waiting-for-job-completed|cups-remote-|connecting-to-device|moving-to-paused|stopping|wifi-not-configured|identify-printer-requested|hold-new-jobs|deactivated|cups-ipp-|com\.apple\.print\.recoverable)/;
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* One keyword -> { base, level: "problem" | "warning", says, step } or null when it is nothing to
|
|
54
|
+
* act on. An unknown keyword marked as an error is still reported, in the printer's own word.
|
|
55
|
+
*/
|
|
56
|
+
export function explainReason(keyword) {
|
|
57
|
+
const raw = cleanKeyword(keyword);
|
|
58
|
+
if (!raw) return null;
|
|
59
|
+
const suffix = /-(error|warning|report)$/.exec(raw)?.[1] || null;
|
|
60
|
+
const base = suffix ? raw.slice(0, -suffix.length - 1) : raw;
|
|
61
|
+
if (base === "offline") return { base, level: "problem", says: "is offline", step: "power", offline: true };
|
|
62
|
+
if (QUIET.test(raw) || suffix === "report") return null;
|
|
63
|
+
const known = REASONS[base];
|
|
64
|
+
if (known) return { base, level: suffix === "warning" || (known.soft && suffix !== "error") ? "warning" : "problem", says: known.says, step: known.step, computer: Boolean(known.computer) };
|
|
65
|
+
if (suffix === "error") return { base, level: "problem", says: `reports an error it calls "${base}"`, step: "panel" };
|
|
66
|
+
if (suffix === "warning") return { base, level: "warning", says: `reports a warning it calls "${base}"`, step: "panel" };
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// ---------- the steps --------------------------------------------------------------------------
|
|
71
|
+
|
|
72
|
+
const QUEUE = {
|
|
73
|
+
win32: "Open the print queue: Settings > Bluetooth & devices > Printers & scanners (on Windows 10: Settings > Devices > Printers & scanners), choose the printer, then Open print queue.",
|
|
74
|
+
darwin: "Open the printer's queue: System Settings > Printers & Scanners, choose the printer, then Printer Queue.",
|
|
75
|
+
linux: "Open the printer's queue: Settings > Printers, choose the printer, then its queue (or open http://localhost:631/printers in a browser).",
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
const steps = (platform) => {
|
|
79
|
+
const os = QUEUE[platform] ? platform : "linux";
|
|
80
|
+
return {
|
|
81
|
+
openQueue: QUEUE[os],
|
|
82
|
+
resume:
|
|
83
|
+
os === "win32"
|
|
84
|
+
? `${QUEUE.win32} In that window open the Printer menu (the three dots on newer Windows) and make sure "Pause Printing" is not ticked.`
|
|
85
|
+
: os === "darwin"
|
|
86
|
+
? `${QUEUE.darwin} If the toolbar shows a Resume button, the printer is paused: click it.`
|
|
87
|
+
: `${QUEUE.linux} Choose Resume (or "Resume Printer").`,
|
|
88
|
+
offlineFlag: `${QUEUE.win32} In that window open the Printer menu (the three dots on newer Windows) and make sure "Use Printer Offline" is not ticked.`,
|
|
89
|
+
restartSpooler:
|
|
90
|
+
"Restart Windows' print service: click Start, type services, open Services, find Print Spooler, right-click it and choose Start (or Restart). Restarting the computer does the same.",
|
|
91
|
+
spoolerDisabled:
|
|
92
|
+
"The print service is switched off on purpose. In Services, double-click Print Spooler, set Startup type to Automatic, click Apply, then Start. On a work computer, ask your IT person first: it is sometimes turned off for security.",
|
|
93
|
+
power: "Check the printer itself: is it switched on, with no error on its screen or blinking lights? Press a button to wake it up.",
|
|
94
|
+
powerCycle: "Switch the printer off, wait 30 seconds, and switch it on again. Give it a minute or two to rejoin the network.",
|
|
95
|
+
sameWifi:
|
|
96
|
+
"Make sure the printer and this computer are on the same network: the same Wi-Fi name, and not a guest network (guest networks usually keep devices from seeing each other). The printer's screen or its network report page shows which Wi-Fi it joined.",
|
|
97
|
+
printerWifi: "If the printer lost its Wi-Fi connection (new router, new Wi-Fi password), join it to the Wi-Fi again from the printer's own screen or the maker's app.",
|
|
98
|
+
readd:
|
|
99
|
+
os === "win32"
|
|
100
|
+
? "Remove the printer and add it again: Settings > Bluetooth & devices > Printers & scanners, choose the printer, Remove. Then Add device and pick it from the list."
|
|
101
|
+
: os === "darwin"
|
|
102
|
+
? "Remove the printer and add it again: System Settings > Printers & Scanners, choose the printer, Remove Printer. Then Add Printer, Scanner or Fax and pick it from the list."
|
|
103
|
+
: "Remove the printer and add it again in Settings > Printers.",
|
|
104
|
+
add:
|
|
105
|
+
os === "win32"
|
|
106
|
+
? "Add the printer: Settings > Bluetooth & devices > Printers & scanners > Add device, then pick it from the list."
|
|
107
|
+
: os === "darwin"
|
|
108
|
+
? "Add the printer: System Settings > Printers & Scanners > Add Printer, Scanner or Fax, then pick it from the list."
|
|
109
|
+
: "Add the printer in Settings > Printers > Add Printer.",
|
|
110
|
+
reserve: "To stop this from coming back, give the printer a fixed address: in your router's settings this is called a DHCP reservation or \"always use this address\".",
|
|
111
|
+
vpnOff: "Turn the VPN off and print again. If you need the VPN on while printing, look in the VPN app for a setting called \"allow local network access\" or \"LAN access\".",
|
|
112
|
+
usbCable: "Check the USB cable at both ends, try a different USB port on the computer, and plug the printer straight into the computer, not through a hub.",
|
|
113
|
+
paper: "Load paper, push the tray all the way in, and set the paper guides snug against the stack.",
|
|
114
|
+
jam: "Clear the paper jam: open the covers the printer's screen or manual points to, pull the paper out gently in the direction it travels, and check for torn scraps.",
|
|
115
|
+
tray: "Take the paper tray out and push it back in until it clicks.",
|
|
116
|
+
output: "Take the printed pages out of the output tray.",
|
|
117
|
+
cover: "Close every cover and door on the printer firmly, including the scanner lid and the back cover.",
|
|
118
|
+
supply: "Replace the empty ink or toner cartridge (or the part the printer's screen names).",
|
|
119
|
+
supplySoon: "Have a replacement cartridge ready. Printers often keep printing for a while after the first low warning.",
|
|
120
|
+
service: "Look up the message on the printer's screen in the maker's support pages: this one usually needs a part replaced or a service visit.",
|
|
121
|
+
panel: "Look at the printer's screen or lights: it is asking for something. The maker's support site explains each message and blink pattern.",
|
|
122
|
+
cancelJobs:
|
|
123
|
+
os === "win32"
|
|
124
|
+
? `${QUEUE.win32} Cancel the oldest job (or choose Cancel all), then print again.`
|
|
125
|
+
: `${QUEUE[os]} Delete the oldest job (the x next to it), then print again.`,
|
|
126
|
+
restartComputer: "If a job will not go away, restart the computer and the printer, then print again.",
|
|
127
|
+
setDefault:
|
|
128
|
+
os === "win32"
|
|
129
|
+
? "Make your real printer the default: Settings > Bluetooth & devices > Printers & scanners, turn off \"Let Windows manage my default printer\", choose the printer, then Set as default."
|
|
130
|
+
: os === "darwin"
|
|
131
|
+
? "Make your real printer the default: System Settings > Printers & Scanners, and pick it under Default printer."
|
|
132
|
+
: "Make your real printer the default in Settings > Printers.",
|
|
133
|
+
pickInApp: "When you print, check the printer name at the top of the print window. Pick your real printer there.",
|
|
134
|
+
resetMac:
|
|
135
|
+
"Last resort on a Mac: System Settings > Printers & Scanners, Control-click an empty spot in the printer list and choose Reset Printing System. This removes every printer, so you add yours again afterwards.",
|
|
136
|
+
testPage:
|
|
137
|
+
os === "win32"
|
|
138
|
+
? "Print a test page: Settings > Bluetooth & devices > Printers & scanners, choose the printer, then Print test page."
|
|
139
|
+
: "Print one page from a simple app (a short text note, for example) to see whether anything comes out.",
|
|
140
|
+
feed: "If the printer starts but no paper comes through, the paper feed is the problem, and the printer often can't tell: take the paper out, fan the stack, load fewer sheets, and wipe the rubber pickup roller with a damp lint-free cloth.",
|
|
141
|
+
appSide: "If one app won't print but others do, the problem is in that app: restart it, or save the document as a PDF and print the PDF.",
|
|
142
|
+
driver: "If pages come out as garbled text or plain letters, the printer was added with the wrong software: remove it and add it again, picking the printer's own name from the list.",
|
|
143
|
+
enable: "Turn the queue back on: remove the printer and add it again, which resets it to accept jobs.",
|
|
144
|
+
again: "Then ask me to check the printer again.",
|
|
145
|
+
};
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
// ---------- helpers ----------------------------------------------------------------------------
|
|
149
|
+
|
|
150
|
+
const minutes = (sec) => {
|
|
151
|
+
if (sec === null || sec === undefined) return null;
|
|
152
|
+
if (sec < 90) return "about a minute";
|
|
153
|
+
if (sec < 3600) return `${Math.round(sec / 60)} minutes`;
|
|
154
|
+
if (sec < 172800) return `${Math.round(sec / 3600)} hours`;
|
|
155
|
+
return `${Math.round(sec / 86400)} days`;
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* A printer's network name as it may be shown, or null. Makers build these names from the
|
|
160
|
+
* printer's hardware address (BRW plus twelve hex digits, for example), so a name with a long run
|
|
161
|
+
* of hex digits is never shown.
|
|
162
|
+
*/
|
|
163
|
+
export const showHost = (host) => (host && !/[0-9a-f]{6,}/i.test(String(host).replace(/[.:-]/g, "")) ? cleanText(host, 64) || null : null);
|
|
164
|
+
|
|
165
|
+
/** "the network name "x"" or, when the name must not be shown, "a network name". */
|
|
166
|
+
const netName = (host) => (showHost(host) ? `the network name "${showHost(host)}"` : "a network name");
|
|
167
|
+
|
|
168
|
+
const oldest = (jobs) => jobs.reduce((m, j) => (j.ageSec !== null && j.ageSec > m ? j.ageSec : m), 0);
|
|
169
|
+
|
|
170
|
+
export const displayName = (p) => (p ? cleanText(p.label || p.name, 80) || "the printer" : "the printer");
|
|
171
|
+
|
|
172
|
+
const uniq = (list) => [...new Set(list.filter(Boolean))];
|
|
173
|
+
|
|
174
|
+
// ---------- the diagnosis ----------------------------------------------------------------------
|
|
175
|
+
|
|
176
|
+
export function diagnose(f) {
|
|
177
|
+
const S = steps(f.platform);
|
|
178
|
+
const findings = [];
|
|
179
|
+
const add = (level, area, text) => findings.push({ level, area, text });
|
|
180
|
+
const sys = f.system || {};
|
|
181
|
+
const sel = f.selection || {};
|
|
182
|
+
const p = f.target;
|
|
183
|
+
const announced = f.network?.announced || [];
|
|
184
|
+
const done = (code, title, stepList) => ({ verdict: { code, title }, findings, steps: uniq(stepList) });
|
|
185
|
+
|
|
186
|
+
// ----- no print system, no printers, or no way to tell which printer is meant -----
|
|
187
|
+
if (sys.system === "windows" && sys.available && sys.serviceRunning === false) {
|
|
188
|
+
add("problem", "computer", `Windows' print service (the "Print Spooler") is not running${sys.serviceDisabled ? ", and it is switched off (disabled)" : ""}. Nothing can print from this computer until it runs, and the printer list looks empty.`);
|
|
189
|
+
return done("spooler_stopped", "Windows' print service is not running, so nothing can print.", sys.serviceDisabled ? [S.spoolerDisabled, S.again] : [S.restartSpooler, S.again]);
|
|
190
|
+
}
|
|
191
|
+
if (!sys.available) {
|
|
192
|
+
add("problem", "computer", sys.system === "cups" ? "This computer's print system (CUPS) is not running or not installed, so no printer can be used from it." : "I could not read this computer's print system.");
|
|
193
|
+
return done(
|
|
194
|
+
"no_system",
|
|
195
|
+
"This computer's print system is not available.",
|
|
196
|
+
f.platform === "linux" ? ["Install or start the print system: on most Linux systems, install the \"cups\" package and start the cups service.", S.again] : ["Restart the computer.", S.again],
|
|
197
|
+
);
|
|
198
|
+
}
|
|
199
|
+
const found = announced.length ? ` I can see ${announced.length === 1 ? "one printer" : `${announced.length} printers`} announcing ${announced.length === 1 ? "itself" : "themselves"} on your network: ${announced.map((a) => a.instance).join(", ")}.` : "";
|
|
200
|
+
if (sel.problem === "no_printers" || sel.problem === "only_virtual") {
|
|
201
|
+
const only = sel.problem === "only_virtual" ? ` The printers it lists (${sel.candidates.join(", ")}) save a file or send a fax: none of them puts ink on paper.` : "";
|
|
202
|
+
add("problem", "computer", `No real printer is set up on this computer.${only}${found}`);
|
|
203
|
+
const how = announced.length ? [S.add] : [S.power, S.sameWifi, S.add, "For a printer on a USB cable: plug it in and switch it on, and the computer normally adds it by itself within a minute."];
|
|
204
|
+
return done("no_printers", "No printer is set up on this computer.", [...how, S.again]);
|
|
205
|
+
}
|
|
206
|
+
if (sel.problem === "not_found") {
|
|
207
|
+
add("problem", "computer", `I can't find a printer called "${sel.asked}" on this computer.${sel.candidates.length ? ` The printers set up here are: ${sel.candidates.join(", ")}.` : " No real printer is set up here."}${found}`);
|
|
208
|
+
return done("not_found", `There is no printer called "${sel.asked}" on this computer.`, ["Tell me which of the printers above to check.", announced.length ? S.add : null]);
|
|
209
|
+
}
|
|
210
|
+
if (sel.problem === "choose") {
|
|
211
|
+
add("note", "computer", `${sel.asked ? `More than one printer matches "${sel.asked}"` : "More than one printer is set up here and none is the default"}: ${sel.candidates.join(", ")}.`);
|
|
212
|
+
return done("choose", "Tell me which printer to check.", ["Tell me the name of the printer that won't print, and I will check that one."]);
|
|
213
|
+
}
|
|
214
|
+
if (!p) return done("no_printers", "No printer is set up on this computer.", [S.add]);
|
|
215
|
+
|
|
216
|
+
// ----- one printer -----
|
|
217
|
+
const name = displayName(p);
|
|
218
|
+
const loc = f.location;
|
|
219
|
+
const dev = f.device;
|
|
220
|
+
const jobs = p.jobs || [];
|
|
221
|
+
const sysReasons = (p.reasons || []).map(explainReason).filter(Boolean);
|
|
222
|
+
const devReasons = dev?.answered ? (dev.reasons || []).map(explainReason).filter(Boolean) : [];
|
|
223
|
+
// Windows sets its "offline" mark by itself when it loses a printer, and people set it by hand.
|
|
224
|
+
const systemSaysOffline = Boolean(p.offlineFlag) || sysReasons.some((r) => r.offline);
|
|
225
|
+
const reached = Boolean(dev?.answered || loc?.answered);
|
|
226
|
+
const out = []; // step keys/texts, in order
|
|
227
|
+
// The headline. A definite cause (3) is never replaced; a likely cause (2) or a warning (1)
|
|
228
|
+
// gives way to anything stronger found later. Among equals, the first one found stays.
|
|
229
|
+
let verdict = null;
|
|
230
|
+
let rank = 0;
|
|
231
|
+
const settle = (code, title, weight = 3) => {
|
|
232
|
+
if (weight > rank) {
|
|
233
|
+
verdict = { code, title };
|
|
234
|
+
rank = weight;
|
|
235
|
+
}
|
|
236
|
+
};
|
|
237
|
+
const causeFound = () => rank >= 3;
|
|
238
|
+
|
|
239
|
+
if (p.virtual) {
|
|
240
|
+
add("note", "computer", `"${name}" is not a real printer: it saves a file (or sends a fax) instead of putting ink on paper.`);
|
|
241
|
+
settle("virtual", `"${name}" does not print on paper.`);
|
|
242
|
+
out.push(S.pickInApp);
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
// 1. The queue on this computer is held back.
|
|
246
|
+
if (p.paused) {
|
|
247
|
+
add("problem", "computer", `The queue for "${name}" on this computer is paused, so jobs wait and nothing is sent to the printer.${jobs.length ? ` ${jobs.length === 1 ? "One job is" : `${jobs.length} jobs are`} waiting.` : ""}`);
|
|
248
|
+
settle("paused", `Printing to "${name}" is paused on this computer.`);
|
|
249
|
+
out.push(S.resume);
|
|
250
|
+
}
|
|
251
|
+
if (p.accepting === false) {
|
|
252
|
+
add("problem", "computer", `The queue for "${name}" is set to refuse new jobs.`);
|
|
253
|
+
settle("not_accepting", `The queue for "${name}" refuses new jobs.`);
|
|
254
|
+
out.push(S.enable);
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
// 2. Can the printer be reached?
|
|
258
|
+
if (p.kind === "network" && loc) {
|
|
259
|
+
if (loc.publicAddress) {
|
|
260
|
+
add("warning", "network", `This computer sends jobs for "${name}" to an address on the internet, not inside your home. I only check printers at home, so I did not contact it.`);
|
|
261
|
+
settle("public_address", `"${name}" points at an address outside your home network.`);
|
|
262
|
+
out.push("If this is a work or cloud printer, ask whoever runs it. If it should be the printer next to you, remove it and add it again.", S.readd);
|
|
263
|
+
} else if (loc.addressChanged) {
|
|
264
|
+
if (loc.nameStillUsed) {
|
|
265
|
+
// The printer still goes by that name; it is this computer that can't look it up.
|
|
266
|
+
add("problem", "network", `This computer looks for "${name}" under ${netName(p.host)} and can't look that name up right now, although the printer is on and announcing itself on your network at ${loc.newAddress}.`);
|
|
267
|
+
settle("name_lookup", `This computer can't find "${name}" by its network name, although the printer is on.`);
|
|
268
|
+
out.push("Restart this computer: that clears a stuck name lookup.", S.readd);
|
|
269
|
+
} else {
|
|
270
|
+
const was = loc.hostIsName ? `under ${netName(p.host)}, and nothing answers to that name any more` : `at ${loc.queueAddress}, and nothing answers there any more`;
|
|
271
|
+
add("problem", "network", `The printer has moved. This computer looks for "${name}" ${was}. But the printer is on and announcing itself on your network at ${loc.newAddress}. ${loc.hostIsName ? "A printer gets a new name when it is reset or joins the network a different way (Wi-Fi instead of a cable, for example)." : "Routers sometimes hand a printer a new address after a restart."}`);
|
|
272
|
+
settle("address_changed", `"${name}" has a new address on your network, and this computer still uses the old one.`);
|
|
273
|
+
out.push(S.readd, loc.hostIsName ? null : S.reserve);
|
|
274
|
+
}
|
|
275
|
+
} else if (loc.answered === false) {
|
|
276
|
+
const ip = loc.address || loc.queueAddress;
|
|
277
|
+
const where = `${ip}${loc.hostIsName && showHost(p.host) ? ` ("${showHost(p.host)}")` : ""}`;
|
|
278
|
+
if (f.network?.viaVpn) {
|
|
279
|
+
add("problem", "network", `"${name}" does not answer at ${where}, and a VPN is on (${(f.network.vpnIfaces || []).join(", ") || "active"}). A VPN usually cuts this computer off from devices at home, printers included.`);
|
|
280
|
+
settle("vpn", `A VPN is on, and "${name}" can't be reached through it.`);
|
|
281
|
+
out.push(S.vpnOff, S.power);
|
|
282
|
+
} else if (loc.sameNetwork === false) {
|
|
283
|
+
add("problem", "network", `"${name}" does not answer at ${where}, and that address is not on the network this computer is using right now. Either the computer or the printer is on a different network (a guest Wi-Fi, a second router, or another place).`);
|
|
284
|
+
settle("other_network", `"${name}" is on a different network than this computer.`);
|
|
285
|
+
out.push(S.sameWifi, S.power, S.printerWifi, S.readd);
|
|
286
|
+
} else {
|
|
287
|
+
add("problem", "network", `"${name}" does not answer at ${where}. It is switched off, asleep so deeply it dropped off the network, or no longer connected to your Wi-Fi or cable.`);
|
|
288
|
+
settle("unreachable", `"${name}" can't be reached: it is off, asleep, or not on the network.`);
|
|
289
|
+
out.push(S.power, S.powerCycle, S.printerWifi, S.sameWifi);
|
|
290
|
+
}
|
|
291
|
+
} else if (loc.hostIsName && loc.nameFound === false && !loc.address) {
|
|
292
|
+
add("problem", "network", `This computer looks for "${name}" under ${netName(p.host)}, which it can't find, and I don't see the printer announcing itself either. It is switched off, not on your network, or was renamed.`);
|
|
293
|
+
settle(f.network?.viaVpn ? "vpn" : "unreachable", f.network?.viaVpn ? `A VPN is on, and "${name}" can't be found through it.` : `"${name}" can't be found on the network.`);
|
|
294
|
+
out.push(f.network?.viaVpn ? S.vpnOff : null, S.power, S.powerCycle, S.printerWifi, S.readd);
|
|
295
|
+
} else if (!loc.address) {
|
|
296
|
+
// The queue finds its printer by announcement (or Windows keeps the address to itself), and
|
|
297
|
+
// nothing matching it answered my own search.
|
|
298
|
+
const level = systemSaysOffline ? "problem" : "warning";
|
|
299
|
+
add(
|
|
300
|
+
level,
|
|
301
|
+
"network",
|
|
302
|
+
`I could not find "${name}" announcing itself on your network right now${f.network?.viaVpn ? ", and a VPN is on, which usually hides home devices" : ""}. ${systemSaysOffline ? "This computer also lists it as offline. " : ""}It may be off, asleep, or on a different network. (Some printers don't answer this kind of search, so this alone is not proof.)`,
|
|
303
|
+
);
|
|
304
|
+
if (systemSaysOffline) settle(f.network?.viaVpn ? "vpn" : "unreachable", f.network?.viaVpn ? `A VPN is on, and "${name}" can't be found through it.` : `"${name}" can't be found on the network.`);
|
|
305
|
+
else settle("warning_not_seen", `I could not find "${name}" on the network, so I can't confirm it is ready.`, 2);
|
|
306
|
+
out.push(f.network?.viaVpn ? S.vpnOff : null, S.power, S.sameWifi, systemSaysOffline ? S.powerCycle : null, systemSaysOffline ? S.printerWifi : null);
|
|
307
|
+
} else if (loc.answered) {
|
|
308
|
+
add("ok", "network", `"${name}" is on the network and answers at ${loc.address}.`);
|
|
309
|
+
if (f.network?.viaVpn) add("note", "network", "A VPN is on, but the printer can still be reached.");
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
// 3. The computer says "offline" while the printer answers (or it is on a cable).
|
|
314
|
+
if (systemSaysOffline && !causeFound()) {
|
|
315
|
+
if (p.kind === "network" && reached) {
|
|
316
|
+
add("problem", "computer", `This computer lists "${name}" as offline and holds its jobs back, but the printer itself is on and answering. The computer's own "offline" mark is wrong.`);
|
|
317
|
+
settle("offline_but_answers", `This computer thinks "${name}" is offline, but the printer is on.`);
|
|
318
|
+
out.push(f.platform === "win32" ? S.offlineFlag : S.resume, f.platform === "win32" ? S.restartSpooler : null, S.readd);
|
|
319
|
+
} else if (p.kind === "usb") {
|
|
320
|
+
add("problem", "computer", `This computer can't see "${name}" on its USB cable: it lists the printer as offline.`);
|
|
321
|
+
settle("usb_offline", `This computer can't see "${name}" on its USB cable.`);
|
|
322
|
+
out.push(S.power, S.usbCable, S.powerCycle, f.platform === "win32" ? S.offlineFlag : null);
|
|
323
|
+
} else if (p.kind !== "network") {
|
|
324
|
+
add("problem", "computer", `This computer lists "${name}" as offline.`);
|
|
325
|
+
settle("unreachable", `This computer lists "${name}" as offline.`);
|
|
326
|
+
out.push(S.power, S.powerCycle, f.platform === "win32" ? S.offlineFlag : null, S.readd);
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
// 4. What the printer says about itself (asked directly when it is on the network).
|
|
331
|
+
// The printer's own answer is fresher than the computer's copy of it; trouble with the printer
|
|
332
|
+
// software on this computer is only ever known to the computer.
|
|
333
|
+
const said = dev?.answered ? [...devReasons.filter((r) => !r.offline), ...sysReasons.filter((r) => r.computer)] : sysReasons.filter((r) => !r.offline);
|
|
334
|
+
const from = dev?.answered ? "The printer" : "This computer says the printer";
|
|
335
|
+
const problems = said.filter((r) => r.level === "problem");
|
|
336
|
+
const warnings = said.filter((r) => r.level === "warning");
|
|
337
|
+
for (const r of problems) {
|
|
338
|
+
add("problem", r.computer ? "computer" : "printer", r.computer ? `"${name}" ${r.says}.` : `${from} ${r.says}.`);
|
|
339
|
+
out.push(S[r.step]);
|
|
340
|
+
}
|
|
341
|
+
if (problems.length) settle("device_error", problems.length === 1 ? `The printer ${problems[0].says}.` : "The printer needs attention before it can print.");
|
|
342
|
+
if (dev?.answered && dev.state === 5 && !problems.length) {
|
|
343
|
+
add("problem", "printer", "The printer says it has stopped, without saying why.");
|
|
344
|
+
settle("device_error", "The printer says it has stopped.");
|
|
345
|
+
out.push(S.panel, S.powerCycle);
|
|
346
|
+
}
|
|
347
|
+
if (dev?.answered && dev.accepting === false) {
|
|
348
|
+
add("warning", "printer", "The printer says it is not accepting jobs right now.");
|
|
349
|
+
out.push(S.panel);
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
// 5. Jobs that are not moving.
|
|
353
|
+
const printingNow = dev?.answered && dev.state === 4;
|
|
354
|
+
const age = oldest(jobs);
|
|
355
|
+
const failed = jobs.filter((j) => j.error).length;
|
|
356
|
+
const after = []; // steps that only make sense once the cause above is fixed
|
|
357
|
+
if (jobs.length) {
|
|
358
|
+
const stuck = failed > 0 || (age >= LIMITS.stuckJobSec && !printingNow);
|
|
359
|
+
const waiting =
|
|
360
|
+
jobs.length === 1
|
|
361
|
+
? `One job ${age ? `has been waiting for "${name}" for ${minutes(age)}` : `is waiting for "${name}"`}`
|
|
362
|
+
: `${jobs.length} jobs are waiting for "${name}"${age ? `; the oldest for ${minutes(age)}` : ""}`;
|
|
363
|
+
if (causeFound()) {
|
|
364
|
+
// Something above already explains why nothing prints; the jobs are waiting on that.
|
|
365
|
+
if (!p.paused) add("note", "computer", `${waiting}.`);
|
|
366
|
+
after.push(`Once that is fixed, the waiting job${jobs.length === 1 ? " should print by itself" : "s should print by themselves"}. If not: ${S.cancelJobs}`);
|
|
367
|
+
} else if (stuck) {
|
|
368
|
+
add("problem", "computer", `${waiting}${failed ? `, and ${failed === 1 ? "one is" : `${failed} are`} marked as failed` : ""}. A job stuck at the front holds back everything behind it.`);
|
|
369
|
+
settle("stuck_job", `A print job is stuck in the queue for "${name}".`);
|
|
370
|
+
out.push(S.cancelJobs, S.restartComputer);
|
|
371
|
+
} else {
|
|
372
|
+
add("note", "computer", `${waiting}${printingNow ? ", and the printer says it is printing" : ""}.`);
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
// 6. Print jobs going to something that is not a printer.
|
|
377
|
+
const def = (sys.printers || []).find((x) => x.isDefault);
|
|
378
|
+
if (def && def.virtual && !p.virtual) {
|
|
379
|
+
add("warning", "computer", `The default printer on this computer is "${displayName(def)}", which saves a file instead of printing. Anything printed without picking a printer goes there, not to "${name}".`);
|
|
380
|
+
settle("default_virtual", `Print jobs are going to "${displayName(def)}", not to your printer.`, 2.5);
|
|
381
|
+
out.push(S.setDefault, S.pickInApp);
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
// 7. Warnings: supplies and software.
|
|
385
|
+
for (const r of warnings) {
|
|
386
|
+
add("warning", r.computer ? "computer" : "printer", r.computer ? `"${name}" ${r.says}.` : `${from} ${r.says}.`);
|
|
387
|
+
out.push(S[r.step]);
|
|
388
|
+
}
|
|
389
|
+
const markers = (dev?.answered && dev.markers?.length ? dev.markers : p.markers) || [];
|
|
390
|
+
const known = markers.filter((m) => m.level !== null);
|
|
391
|
+
const low = known.filter((m) => m.level <= m.low);
|
|
392
|
+
if (known.length) {
|
|
393
|
+
const list = known.map((m) => `${m.label} ${m.level}%`).join(", ");
|
|
394
|
+
if (low.length) {
|
|
395
|
+
add("warning", "supplies", `Running low: ${low.map((m) => `${m.label} ${m.level}%`).join(", ")}. (All levels: ${list}. These are the printer's own estimates.)`);
|
|
396
|
+
out.push(low.some((m) => m.level === 0) ? S.supply : S.supplySoon);
|
|
397
|
+
} else add("ok", "supplies", `Ink or toner: ${list} (the printer's own estimate).`);
|
|
398
|
+
}
|
|
399
|
+
if (warnings.length || low.length) settle("warning", warnings.length ? `"${name}" can print, but ${warnings[0].says.replace(/^(is|has) /, (m) => (m === "is " ? "it is " : "it has "))}.` : `"${name}" can print, but ink or toner is running low.`, 1);
|
|
400
|
+
if (p.genericDriver) {
|
|
401
|
+
add("note", "computer", `"${name}" uses a basic, generic printer driver (${p.driver}). That works for plain pages, but can print garbled text or miss features.`);
|
|
402
|
+
out.push(S.driver);
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
// 8. Good news and limits.
|
|
406
|
+
if (dev?.answered && !problems.length && dev.state !== 5) {
|
|
407
|
+
const state = dev.state === 4 ? "busy printing" : "ready";
|
|
408
|
+
add("ok", "printer", `The printer says it is ${state}${dev.accepting === false ? "" : " and accepting jobs"}${dev.alert?.some((a) => /sleep/i.test(a)) ? " (it is asleep, and wakes up when a job arrives)" : ""}.`);
|
|
409
|
+
} else if (p.kind === "network" && loc?.answered && dev && !dev.answered) {
|
|
410
|
+
add("note", "printer", dev.error === "needs-password" ? "The printer is on, but it wants a password before it tells its status, so I could not read paper and ink." : "The printer is on, but it does not answer status questions the standard way (IPP), so I could not read paper and ink.");
|
|
411
|
+
}
|
|
412
|
+
if (p.kind === "usb" && !p.virtual) add("note", "printer", "This printer is on a USB cable. I can only see what the computer knows about it, not the printer's own paper and ink sensors.");
|
|
413
|
+
if (p.kind === "shared") add("note", "printer", `This printer is shared by another computer${showHost(p.host) ? ` ("${showHost(p.host)}")` : ""}. That computer must be on, and I can only check this computer's side.`);
|
|
414
|
+
if (!jobs.length && !p.paused) add("ok", "computer", "Nothing is waiting in the queue on this computer.");
|
|
415
|
+
if (sel.how === "only" || sel.how === "default") {
|
|
416
|
+
const others = (sys.printers || []).filter((x) => !x.virtual && x !== p).length;
|
|
417
|
+
if (others) add("note", "computer", `I checked "${name}" because it is the default printer. ${others === 1 ? "One other printer is" : `${others} other printers are`} set up here: name one and I will check it.`);
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
if (!verdict) {
|
|
421
|
+
const confirmed = dev?.answered;
|
|
422
|
+
settle("healthy", confirmed ? `"${name}" is ready: the printer says so, and nothing is stuck on this computer.` : `Nothing looks wrong with "${name}" from this computer's side.`);
|
|
423
|
+
out.push(S.testPage, S.pickInApp, S.feed, S.appSide);
|
|
424
|
+
if (f.platform === "darwin") out.push(S.resetMac);
|
|
425
|
+
} else {
|
|
426
|
+
out.push(...after);
|
|
427
|
+
if (!["warning", "virtual", "default_virtual"].includes(verdict.code)) out.push(S.again);
|
|
428
|
+
}
|
|
429
|
+
return { verdict, findings, steps: uniq(out) };
|
|
430
|
+
}
|