Newbrict / obsidian-obligator

A fully featured replacement for the built-in daily notes plugin. Obligator functions like a virtual bullet journal by copying over unchecked to-do items to your new daily note, along with adding any scheduled items you've set up
MIT License
65 stars 4 forks source link

Wait for sync to complete before automatically making a new note #22

Open Newbrict opened 10 months ago

Newbrict commented 10 months ago

Currently, with the automatic new note feature turned on, there is a bug that happens if you made new files on a different device that's synced. The solution is to wait for the sync to finish before opening a new note.

ChrisJefferson commented 8 months ago

I've been hitting this bug, as I use obsidian on both my phone and computer, and often tick off some to-dos at the end of the day on my phone, then first open my computer in the morning on my computer.

Yesterday the problem was even worse, as I never opened obsidian on my computer, turned my computer on today, and now I have today and yesterday's unsynced note.

I really like this plugin, so I hope you can fix this issue!

Newbrict commented 8 months ago

Hi @ChrisJefferson,

I do intend to fix this at some point, but I haven't thought of a good fix for it, and I've been a bit busy lately.

For a temporary fix, I disabled the "automatically open new note on startup" option. If you manually open the note on your phone and your computer, you are much less likely to experience the issue. I hope that helps.

ChrisJefferson commented 8 months ago

I went looking for a fix, and found the following snippet on discord. I then decided this is too deep for me to want to try to hack myself, but I'll post it here, just in case it's useful for you and you haven't seen it :) But I definately understand having too many projects, and not enough time to work on any of them. ( https://discord.com/channels/686053708261228577/840286264964022302/947675707188846652 )

let sync = this.app.internalPlugins.plugins.sync.instance;
sync.on("status-change", () => { console.log("sync status is", sync.syncStatus) })

// other sync info

let syncPlugin = app.internalPlugins.plugins["sync"].instance;
//Hook into "status-change" event for a callback when syncing has started or has completed. This event fires alot while syncing so need to put criteria around it
syncPlugin.on("status-change", () => {
    console.log("sync status is", syncPlugin.syncStatus);
});
//Hook into the "new-log" event for a callback for each Sync log event (mirrors Sync log)
syncPlugin.on("new-log", () => {
    const syncLogs = syncPlugin.syncLog;
    const recentLog = syncLogs[syncLogs.length - 1];
    const fileName = recentLog.file ? recentLog.file : "";
    const logNote = `[${new Date(recentLog.ts)}] - ${recentLog.info} ${fileName}`;
    console.log("New sync log:", logNote);
});
//Sync plugin turned on or off
console.log(syncPlugin.plugin.enabled);
//Sync plugin paused or not
console.log(syncPlugin.pause);
//Sync plugin currently in the middle of syncing
console.log(syncPlugin.syncing);
console.log(syncPlugin.getStatus());
//Sync plugin status; "Fully synced" means good to go.
console.log(syncPlugin.syncStatus);
//Recent sync logs
console.log(syncPlugin.syncLog);
//Get sync device name
console.log(syncPlugin.deviceName ? syncPlugin.deviceName : syncPlugin.getDefaultDeviceName());
//Get your current Sync storage capacity used
let syncStorageSize = await syncPlugin.size();
console.log(`Currently using ${(syncStorageSize.size / 1073741824).toFixed(2)} GB out of allowed ${(syncStorageSize.limit / 1073741824).toFixed(2)} GB`);