MCPcopy
hub / github.com/1j01/jspaint / show_recovery_window

Function show_recovery_window

src/sessions.js:34–91  ·  view source on GitHub ↗
(no_longer_blank)

Source from the content-addressed store, hash-verified

32
33let $recovery_window;
34function show_recovery_window(no_longer_blank) {
35 $recovery_window?.close();
36 const $w = $recovery_window = $DialogWindow();
37 $w.on("close", () => {
38 $recovery_window = null;
39 });
40 $w.title("Recover Document");
41 let backup_impossible = false;
42 try { window.localStorage.getItem("bogus test key"); } catch (_error) { backup_impossible = true; }
43 // TODO: get rid of this invasive dialog https://github.com/1j01/jspaint/issues/325
44 // It appears when it shouldn't, in basic scenarios like Ctrl+A in a transparent document,
45 // and it gets bigger once you edit the document, which feels... almost aggressive.
46 // That said, I've made it more compact and delineated the expanded section with a horizontal rule,
47 // so it doesn't feel as much like it's changed out from under you and you have to re-read it.
48 $w.$main.append($(`
49 <p>Woah! The canvas became empty.</p>
50 <p>If this was on purpose, please ignore this message.</p>
51 <p>
52 If the canvas was cleared due to memory usage,<br>
53 click Undo to recover the document.
54 </p>
55 <!--<p>Remember to save with <b>File > Save</b>!</p>-->
56 ${backup_impossible ?
57 "<p><b>Note:</b> No automatic backup is possible unless you enable Cookies in your browser.</p>" :
58 (
59 no_longer_blank ?
60 `<hr>
61 <p style="opacity: 0.8; font-size: 0.9em;">
62 Auto-save is paused while this dialog is open.
63 </p>
64 <p style="opacity: 0.8; font-size: 0.9em;">
65 (See <b>File &gt; Manage Storage</b> to view backups.)
66 </p>` :
67 ""
68 )
69 }
70 `));
71
72 const $undo = $w.$Button("Undo", () => {
73 undo();
74 });
75 const $redo = $w.$Button("Redo", () => {
76 redo();
77 });
78 const update_buttons_disabled = () => {
79 $undo.prop("disabled", undos.length < 1);
80 $redo.prop("disabled", redos.length < 1);
81 };
82 $G.on("session-update.session-hook", update_buttons_disabled);
83 update_buttons_disabled();
84
85 $w.$Button(localize("Close"), () => {
86 $w.close();
87 });
88 $w.center();
89
90 $w.find("button:enabled").focus();
91}

Callers 1

handle_data_lossFunction · 0.85

Calls 12

$DialogWindowFunction · 0.90
undoFunction · 0.90
redoFunction · 0.90
update_buttons_disabledFunction · 0.85
localizeFunction · 0.85
onMethod · 0.80
titleMethod · 0.80
centerMethod · 0.80
closeMethod · 0.65
$ButtonMethod · 0.65
focusMethod · 0.65
$Function · 0.50

Tested by

no test coverage detected