Skip to content

Commit

Permalink
Simplify backup stacking.
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan McQuen <[email protected]>
  • Loading branch information
ryanpcmcquen committed Jun 17, 2021
1 parent b6b7ec5 commit f25ba13
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 30 deletions.
39 changes: 14 additions & 25 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,13 @@ const monkeyPatchConsole = (plugin: Plugin) => {

const logFile = `${plugin.manifest.dir}/logs.txt`;
const logs: string[] = [];
const logMessages =
(prefix: string) =>
(...messages: unknown[]) => {
logs.push(`\n[${prefix}]`);
for (const message of messages) {
logs.push(String(message));
}
plugin.app.vault.adapter.write(logFile, logs.join(" "));
};
const logMessages = (prefix: string) => (...messages: unknown[]) => {
logs.push(`\n[${prefix}]`);
for (const message of messages) {
logs.push(String(message));
}
plugin.app.vault.adapter.write(logFile, logs.join(" "));
};

console.debug = logMessages("debug");
console.error = logMessages("error");
Expand All @@ -41,7 +39,7 @@ export default class DropboxBackups extends Plugin {
dbx: unknown;
dbxAuth: unknown;

backupsQueue: number[] = [];
currentBackupTime: number;

icons = {
cloudSlash: `
Expand Down Expand Up @@ -77,12 +75,9 @@ export default class DropboxBackups extends Plugin {

async backup(): Promise<void> {
const now = Date.now();
let status = "complete";
let finalStatus = "complete";

this.backupsQueue.push(now);
if (this.backupsQueue.length > 1) {
this.backupsQueue = [now];
}
this.currentBackupTime = now;

const year = moment(new Date(now)).format("YYYY");
const month = moment(new Date(now)).format("MM");
Expand All @@ -107,8 +102,8 @@ export default class DropboxBackups extends Plugin {
if (fileList.length > 0) {
let counter = 0;
for (const file of fileList) {
if (!this.backupsQueue.includes(now)) {
status = "canceled";
if (this.currentBackupTime !== now) {
finalStatus = "canceled";
break;
}
if (this.app.vault.adapter.exists(file.path)) {
Expand Down Expand Up @@ -139,7 +134,7 @@ export default class DropboxBackups extends Plugin {
}
}

console.log(`Backup to ${pathPrefix} ${status}!`);
console.log(`Backup to ${pathPrefix} ${finalStatus}!`);

if (!Platform.isMobile && this.dropboxBackupsRibbonIcon) {
this.dropboxBackupsRibbonIcon.setAttribute(
Expand All @@ -151,11 +146,6 @@ export default class DropboxBackups extends Plugin {
this.dropboxBackupsRibbonIcon,
"dropbox-backups-upload-complete"
);

const indexOfNow = this.backupsQueue.indexOf(now);
if (indexOfNow > -1) {
this.backupsQueue.splice(indexOfNow, 1);
}
}

async setupAuth() {
Expand Down Expand Up @@ -205,8 +195,7 @@ export default class DropboxBackups extends Plugin {
params.code
);

const accessTokenResponseResult =
accessTokenResponse?.result as accessTokenStore;
const accessTokenResponseResult = accessTokenResponse?.result as accessTokenStore;
this.dropboxBackupsTokenStore = accessTokenResponseResult;
await this.app.vault.adapter.write(
this.dropboxBackupsTokenStorePath,
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "obsidian-dropbox-backups",
"name": "Dropbox Backups",
"version": "0.14.0",
"version": "0.14.1",
"minAppVersion": "0.9.12",
"description": "Automated backups to Dropbox for your enjoyment.",
"author": "ryanpcmcquen",
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "obsidian-dropbox-backups",
"version": "0.14.0",
"version": "0.14.1",
"description": "Automated backups to Dropbox for your enjoyment.",
"main": "main.js",
"repository": "https://github.com/ryanpcmcquen/obsidian-dropbox-backups",
Expand All @@ -18,9 +18,9 @@
"@rollup/plugin-typescript": "^8.2.1",
"@types/node": "^14.17.3",
"obsidian": "^0.12.5",
"rollup": "^2.51.2",
"tslib": "^2.2.0",
"typescript": "^4.2.4"
"rollup": "^2.52.1",
"tslib": "^2.3.0",
"typescript": "^4.3.3"
},
"dependencies": {}
}
1 change: 1 addition & 0 deletions versions.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"0.14.1": "0.9.12",
"0.14.0": "0.9.12",
"0.13.1": "0.9.12",
"0.13.0": "0.9.12",
Expand Down

0 comments on commit f25ba13

Please sign in to comment.