Skip to content

Commit

Permalink
NEO更新。3日以上経過した復元のためのローカルストレージデータは破棄。
Browse files Browse the repository at this point in the history
  • Loading branch information
satopian committed Sep 28, 2024
1 parent d617c12 commit f918d0d
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions potiboard5/neo.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ document.addEventListener("DOMContentLoaded", function () {

var Neo = function () {};

Neo.version = "1.6.3";
Neo.version = "1.6.5";
Neo.painter;
Neo.fullScreen = false;
Neo.uploaded = false;
Expand Down Expand Up @@ -108,15 +108,26 @@ Neo.init2 = function () {
Neo.animation = Neo.config.thumbnail_type == "animation";

// 続きから描く
Neo.storage = localStorage;
Neo.storage = localStorage; //PCの時にもlocalStorageを使用

var filename = Neo.getFilename();
var message =
!filename || filename.slice(-4).toLowerCase() != ".pch"
? "描きかけの画像があります。復元しますか?"
: "描きかけの画像があります。動画の読み込みを中止して復元しますか?";

if (Neo.storage.getItem("timestamp") && confirm(Neo.translate(message))) {
let storageTimestamp = Neo.storage.getItem("timestamp");
const nowTimestamp = new Date().getTime();

if (
Number.isInteger(storageTimestamp) &&
nowTimestamp - storageTimestamp > 3 * 86400 * 1000
) {
//3日経過した復元データは破棄
Neo.painter.clearSession();
storageTimestamp = null;
}
if (storageTimestamp && confirm(Neo.translate(message))) {
var oe = Neo.painter;
setTimeout(function () {
oe.loadSession(function () {
Expand Down Expand Up @@ -2289,6 +2300,10 @@ Neo.Painter.prototype._mouseDownHandler = function (e) {
this.prevMouseX = this.mouseX;
this.prevMouseY = this.mouseY;
this.securityCount++;
let autosaveCount = this.securityCount;
if (autosaveCount % 10 === 0 && Neo.painter.isDirty()) {
Neo.painter.saveSession(); //10ストロークごとに自動バックアップ
}

if (this.isMouseDownRight) {
this.isMouseDownRight = false;
Expand Down Expand Up @@ -4434,7 +4449,7 @@ Neo.Painter.prototype.loadSession = function (callback) {

Neo.Painter.prototype.saveSession = function () {
if (Neo.storage) {
Neo.storage.setItem("timestamp", +new Date());
Neo.storage.setItem("timestamp", new Date().getTime());
Neo.storage.setItem("layer0", this.canvas[0].toDataURL("image/png"));
Neo.storage.setItem("layer1", this.canvas[1].toDataURL("image/png"));
}
Expand Down

0 comments on commit f918d0d

Please sign in to comment.