(session_id)
| 95 | |
| 96 | class LocalSession { |
| 97 | constructor(session_id) { |
| 98 | this.id = session_id; |
| 99 | const lsid = `image#${session_id}`; |
| 100 | log(`Local storage ID: ${lsid}`); |
| 101 | // save image to storage |
| 102 | this.save_image_to_storage_immediately = () => { |
| 103 | const save_paused = handle_data_loss(); |
| 104 | if (save_paused) { |
| 105 | return; |
| 106 | } |
| 107 | log(`Saving image to storage: ${lsid}`); |
| 108 | storage.set(lsid, main_canvas.toDataURL("image/png"), err => { |
| 109 | if (err) { |
| 110 | if (err.quotaExceeded) { |
| 111 | storage_quota_exceeded(); |
| 112 | } |
| 113 | else { |
| 114 | // e.g. localStorage is disabled |
| 115 | // (or there's some other error?) |
| 116 | // @TODO: show warning with "Don't tell me again" type option |
| 117 | } |
| 118 | } |
| 119 | }); |
| 120 | }; |
| 121 | this.save_image_to_storage_soon = debounce(this.save_image_to_storage_immediately, 100); |
| 122 | storage.get(lsid, (err, uri) => { |
| 123 | if (err) { |
| 124 | if (localStorageAvailable) { |
| 125 | show_error_message("Failed to retrieve image from local storage.", err); |
| 126 | } |
| 127 | else { |
| 128 | // @TODO: DRY with storage manager message |
| 129 | showMessageBox({ |
| 130 | message: "Please enable local storage in your browser's settings for local backup. It may be called Cookies, Storage, or Site Data.", |
| 131 | }); |
| 132 | } |
| 133 | } |
| 134 | else if (uri) { |
| 135 | load_image_from_uri(uri).then((info) => { |
| 136 | open_from_image_info(info, null, null, true, true); |
| 137 | }, (error) => { |
| 138 | show_error_message("Failed to open image from local storage.", error); |
| 139 | }); |
| 140 | } |
| 141 | else { |
| 142 | // no uri so lets save the blank canvas |
| 143 | this.save_image_to_storage_soon(); |
| 144 | } |
| 145 | }); |
| 146 | $G.on("session-update.session-hook", this.save_image_to_storage_soon); |
| 147 | } |
| 148 | end() { |
| 149 | // Skip debounce and save immediately |
| 150 | this.save_image_to_storage_soon.cancel(); |
nothing calls this directly
no test coverage detected