Skip to content

Commit 3a67477

Browse files
authored
Merge pull request #33 from RefactorSecurity/29-add-autosave
Add autosave feature
2 parents ba0b805 + 811a86e commit 3a67477

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

src/helpers.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { getReactionGroup } from './reactions/resource';
55
import { RemoteDb } from './persistence/remote-db';
66
import { v4 as uuidv4 } from 'uuid';
77
import { Deserializer } from './persistence/serialization/deserializer';
8+
import { saveNotesToFile } from './persistence/local-db';
89

910
export const saveNoteComment = (
1011
thread: vscode.CommentThread,
@@ -32,6 +33,7 @@ export const saveNoteComment = (
3233
thread.contextValue = uuidv4();
3334
noteMap.set(thread.contextValue, thread);
3435
}
36+
saveNotesToFile(noteMap);
3537
if (remoteDb) {
3638
remoteDb.pushNoteComment(thread, firstComment);
3739
}
@@ -148,6 +150,8 @@ export const syncNoteMapWithRemote = (
148150
remoteDb && remoteDb.pushNoteComment(localThread, true);
149151
}
150152
});
153+
154+
saveNotesToFile(noteMap);
151155
};
152156

153157
export const getSetting = (settingName: string, defaultValue?: any) => {

src/persistence/remote-db/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import * as rethinkdb from 'rethinkdb';
33
import { Serializer } from '../serialization/serializer';
44
import { Deserializer } from '../serialization/deserializer';
55
import { readFileSync } from 'fs';
6+
import { saveNotesToFile } from '../local-db';
67

78
export class RemoteDb {
89
private host: string;
@@ -134,6 +135,7 @@ export class RemoteDb {
134135
newThread.contextValue ? newThread.contextValue : '',
135136
newThread,
136137
);
138+
saveNotesToFile(this.noteMap);
137139
vscode.window.showInformationMessage('Note received from remote DB.');
138140
});
139141
});

src/utils/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import * as vscode from 'vscode';
44
import * as path from 'path';
55
import { platform } from 'os';
6-
import { getSetting } from '../helpers';
76

87
export const isWindows = () => {
98
return platform() === 'win32';
@@ -26,7 +25,9 @@ export const getWorkspacePath = () => {
2625
};
2726

2827
export const getLocalDbFilePath = () => {
29-
const localDbFilePath = getSetting('localDatabase');
28+
const localDbFilePath = vscode.workspace
29+
.getConfiguration('security-notes')
30+
.get<string>('localDatabase', '.security-notes.json');
3031
if (path.isAbsolute(localDbFilePath)) {
3132
return localDbFilePath;
3233
} else {

0 commit comments

Comments
 (0)