Skip to content
This repository has been archived by the owner on Aug 27, 2023. It is now read-only.

Commit

Permalink
update 230201
Browse files Browse the repository at this point in the history
  • Loading branch information
HowcanoeWang committed Feb 1, 2023
1 parent 9651bc7 commit 5d51cc2
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 17 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ C:\Users\<user>\Documents\SiYuan\conf\appearance\themes\Savor\

**反编译的纯js版本(calendar-v7-fix)**

## v230201

* 使用`/data/widgets/Calendar.config.json`代替`localstorage['calendar_current_notebook']`作为用户默认日记本配置
* 修复顶栏星期显示错误

## v230123

* 修复电脑重启后,首次打开思源笔记本配置加载错误
Expand Down
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<!DOCTYPE html><html lang=""><head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><link rel="icon" href="./favicon.ico"><title>calendar</title><link href="./css/app.a2e4f2e0.css" rel="preload" as="style"><link href="./js/app.230123.js" rel="preload" as="script"><link href="./js/chunk-vendors.5c31667a.js" rel="preload" as="script"><link href="./css/app.a2e4f2e0.css" rel="stylesheet"></head><body><noscript><strong>We're sorry but calendar doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id="app"></div><script src="./js/chunk-vendors.5c31667a.js"></script><script src="./js/app.230123.js"></script></body></html>
<!DOCTYPE html><html lang=""><head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><link rel="icon" href="./favicon.ico"><title>calendar</title><link href="./css/app.a2e4f2e0.css" rel="preload" as="style"><link href="./js/app.230201.js" rel="preload" as="script"><link href="./js/chunk-vendors.5c31667a.js" rel="preload" as="script"><link href="./css/app.a2e4f2e0.css" rel="stylesheet"></head><body><noscript><strong>We're sorry but calendar doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id="app"></div><script src="./js/chunk-vendors.5c31667a.js"></script><script src="./js/app.230201.js"></script></body></html>
76 changes: 60 additions & 16 deletions js/app.230123.js → js/app.230201.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,20 +217,21 @@
monthCurrent: undefined,
dayCurrent: undefined,
template_path: undefined,
config_json_path: "/data/widgets/Calendar.config.json"
};
},
created() {
var now = new Date();
this.date = now.getDate(); //得到日期
var day = now.getDay(); //得到周几
var arr_week = new Array(
"星期日",
"星期一",
"星期二",
"星期三",
"星期四",
"星期五",
"星期六",
"星期日"
);
this.week = arr_week[day];
},
Expand All @@ -252,10 +253,7 @@
this.currentNotebook.name = e.target.getAttribute("data-name");
this.currentNotebook.id = e.target.getAttribute("data-id");
this.showNotebookList = false;
localStorage.setItem(
"calendar_current_notebook",
JSON.stringify(this.currentNotebook)
);
await this.set_crt_nb();

// also refersh the template path
this.markArr=[]; // 清除之前的日记缓存
Expand Down Expand Up @@ -288,15 +286,63 @@
}
});
},
////////////////////////////
// 读写之前打开的笔记本记录 //
////////////////////////////
// inspired from https://github.com/UFDXD/HBuilderX-Light/blob/main/theme.js

async 写入文件(path, filedata, then = null, obj = null, isDir = false, modTime = Date.now()) {

let blob = new Blob([filedata]);
let file = new File([blob], path.split('/').pop());
let formdata = new FormData();
formdata.append("path", path);
formdata.append("file", file);
formdata.append("isDir", isDir);
formdata.append("modTime", modTime);
await fetch(
"/api/file/putFile", {
body: formdata,
method: "POST",
headers: {
Authorization: `Token ""`,
},
}).then((v) => {
setTimeout(() => {
if (then) then(obj);
}, 200)
});
},

async get_crt_nb() {

try {
let r = {"path": this.config_json_path}
let calendar_config = await this.request("/api/file/getFile", r);
this.currentNotebook = calendar_config;

} catch (err) {
console.log("[日历插件][Error] 大概率是由于第一次启动,配置文件 [" + this.config_json_path + "] 未创建,文件不存在造成的404, 错误日志如下:\n", err);
//大概率是文件没有创建,调用一下创建文件的命令即可
await this.set_crt_nb();
}

},

async set_crt_nb() {
await this.写入文件(this.config_json_path, JSON.stringify(this.currentNotebook, undefined, 4));
},

////////////////////////////
// 读写之前打开的笔记本记录 //
////////////////////////////

// initialize notebook data
async init_open_app(){
// for testing the empty localstorage
// localStorage.removeItem("calendar_current_notebook");

if (localStorage.getItem("calendar_current_notebook")) {
this.currentNotebook = JSON.parse(
localStorage.getItem("calendar_current_notebook")
);
await this.get_crt_nb();

if (this.currentNotebook.name !== "") {
console.log("[日历插件][Info] currentNotebook is [" + this.currentNotebook.name +"]");
} else {// 在缓存数据中,找不到选中的笔记本
// 和下面的handleweekclick差不多的,但是直接调用那个函数会有问题,这边重复一下
Expand All @@ -315,13 +361,11 @@
// set the first notebook as default, to avoid undefined error
this.currentNotebook.name = this.notebookList[0].name;
this.currentNotebook.id = this.notebookList[0].id;
localStorage.setItem(
"calendar_current_notebook",
JSON.stringify(this.currentNotebook)
);

await this.set_crt_nb();

// print log info
console.log("[日历插件][Info] localStorage['calendar_current_notebook'] is empty, use [", this.currentNotebook.name +"] as default");
console.log("[日历插件][Info] 未在缓存中找到默认笔记本设置,使用笔记本["+ this.currentNotebook.name +"]作为默认");
let success_str = {"msg": "[日历插件][info] 未在缓存中找到默认笔记本设置,使用笔记本["+ this.currentNotebook.name +"]作为默认,如有需要请点击日历的【星期x】按钮进行切换", "timeout": 7000};
let print = await this.request("/api/notification/pushMsg", success_str);
}
Expand Down

0 comments on commit 5d51cc2

Please sign in to comment.