未验证 提交 b441991d 编写于 作者: frostime's avatar frostime 提交者: GitHub

Merge pull request #47 from frostime/36-dnapi

36 dnapi
......@@ -55,6 +55,7 @@
type="button"
content={contents.update}
settingKey="Update"
settingValue={""}
on:click={onClick}
/>
</div>
......@@ -82,7 +82,7 @@ export class ToolbarMenuItem {
/**
* 初始化的时候,加载所有的笔记本
*/
autoOpenDailyNote() {
async autoOpenDailyNote() {
info('自动开启日记');
if (notebooks.notebooks.length > 0) {
if (settings.settings.OpenOnStart === true) {
......
......@@ -198,21 +198,23 @@ export async function createDiary(notebook: Notebook, todayDiaryHpath: string) {
* @param notebook_index 笔记本的 index
*/
export async function openDiary(notebook: Notebook) {
let todayDiaryPath = notebook.dailynotePath;
info(`打开日记 ${notebook.name}${todayDiaryPath}`);
//queryNotebooks() 保证了 todayDiaryPath 不为 null
let docs = await getDocsByHpath(todayDiaryPath!, notebook);
if (docs != null && docs.length > 0) {
let doc = docs[0];
let id = doc.id;
window.open(`siyuan://blocks/${id}`);
notify(`${i18n.Open}${notebook.name}`, 'info', 2500);
} else {
let id = await createDiary(notebook, todayDiaryPath!);
window.open(`siyuan://blocks/${id}`);
notify(`${i18n.Create}: ${notebook.name}`, 'info', 2500);
}
// let todayDiaryPath = notebook.dailynotePath;
// info(`打开日记 ${notebook.name}${todayDiaryPath}`);
// let docs = await getDocsByHpath(todayDiaryPath!, notebook);
await serverApi.createDailyNote(notebook.id, "");
notify(`${i18n.Open}: ${notebook.name}`, 'info', 2000);
// if (docs != null && docs.length > 0) {
// let doc = docs[0];
// let id = doc.id;
// window.open(`siyuan://blocks/${id}`);
// notify(`${i18n.Open}: ${notebook.name}`, 'info', 2500);
// } else {
// let id = await createDiary(notebook, todayDiaryPath!);
// window.open(`siyuan://blocks/${id}`);
// notify(`${i18n.Create}: ${notebook.name}`, 'info', 2500);
// }
}
export function compareVersion(v1Str: string, v2Str: string) {
......
......@@ -43,7 +43,7 @@ class SettingManager {
}
set(key: any, value: any) {
info(`Setting update: ${key} = ${value}`)
// info(`Setting update: ${key} = ${value}`)
if (!(key in this.settings)) {
error(`"${key}" is not a setting`);
return;
......
......@@ -15,6 +15,7 @@ import * as serverApi from './serverApi';
export default class DailyNoteTodayPlugin extends Plugin {
app: any;
toolbar_item: ToolbarMenuItem;
component_setting: Setting;
......@@ -49,14 +50,15 @@ export default class DailyNoteTodayPlugin extends Plugin {
this.initToolbarItem();
this.initUpToDate();
eventBus.subscribe('UpdateAll', () => {this.updateAll()});
// 如果有笔记本,且设置中允许启动时打开,则打开第一个笔记本
this.toolbar_item.autoOpenDailyNote();
await this.toolbar_item.autoOpenDailyNote();
// 等日记创建,完成了状态更新后再读取新的状态
setTimeout(
() => this.toolbar_item.updateDailyNoteStatus(), 2000
() => this.toolbar_item.updateDailyNoteStatus(), 1000
);
eventBus.subscribe('UpdateAll', () => {this.updateAll()});
let end = performance.now();
info(`启动耗时: ${end - start} ms`);
......
......@@ -10,39 +10,6 @@ async function request(url: string, data: any) {
return res;
}
function parseBody(body: any) {
return body;
}
async function test() {
let notebooks = await lsNotebooks();
console.log(notebooks);
let notebookId = notebooks?.notebooks[0].id;
try {
let notebookConf = await getNotebookConf('20220305173526-4yjl33h');
console.log(notebookConf);
} catch (err) {
console.log(err);
}
try {
let block = await getBlockByID('20220316145830-u0u6srg');
console.log(block);
} catch (err) {
console.log(err);
}
try {
let block = await renderSprig('/daily note/{{now | date "2006/01"}}/{{now | date "2006-01-02"}}');
console.log(block);
} catch (err) {
console.log(err);
}
// try {
// await moveBlock('20230512192002-q5ekmhh', '20230512192017-eyc4dyb', null);
// } catch (err) {
// console.log(err);
// }
}
export async function sql(sql: string) {
let sqldata = {
......@@ -67,6 +34,11 @@ export async function createDocWithMd(notebookId: string, path: string, markdown
return request(url, data);
}
export async function createDailyNote(notebookId: string, app: string) {
let url = '/api/filetree/createDailyNote';
return request(url, { notebook: notebookId, app: app });
}
export async function getNotebookConf(notebookId: string) {
let data = { notebook: notebookId };
let url = '/api/notebook/getNotebookConf';
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册