Skip to content

Commit

Permalink
fix: store username in localstorage
Browse files Browse the repository at this point in the history
  • Loading branch information
Vinzent03 committed Nov 1, 2022
1 parent 2c42609 commit f3668ac
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 8 deletions.
1 change: 0 additions & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ export const DEFAULT_SETTINGS: ObsidianGitSettings = {
basePath: "",
differentIntervalCommitAndPush: false,
changedFilesInStatusBar: false,
username: "",
showedMobileNotice: false,
refreshSourceControlTimer: 7000,
showBranchStatusBar: true
Expand Down
5 changes: 2 additions & 3 deletions src/isomorphicGit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export class IsomorphicGit extends GitManager {
dir: this.plugin.settings.basePath,
onAuth: () => {
return {
username: this.plugin.settings.username,
username: this.plugin.localStorage.getUsername() ?? undefined,
password: this.plugin.localStorage.getPassword() ?? undefined
};
},
Expand All @@ -60,8 +60,7 @@ export class IsomorphicGit extends GitManager {
if (username) {
const password = await new GeneralModal({ placeholder: "Specify your password/personal access token" }).open();
if (password) {
this.plugin.settings.username = username;
await this.plugin.saveSettings();
this.plugin.localStorage.setUsername(username);
this.plugin.localStorage.setPassword(password);
return {
username,
Expand Down
8 changes: 8 additions & 0 deletions src/localStorageSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ export class LocalStorageSettings {
return app.saveLocalStorage(this.prefix + "password", value);
}

getUsername(): string | null {
return app.loadLocalStorage(this.prefix + "username");
}

setUsername(value: string): void {
return app.saveLocalStorage(this.prefix + "username", value);
}

getHostname(): string | null {
return app.loadLocalStorage(this.prefix + "hostname");
}
Expand Down
5 changes: 5 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,11 @@ export default class ObsidianGit extends Plugin {
this.settings.gitPath = undefined;
await this.saveSettings();
}
if (this.settings.username != undefined) {
this.localStorage.setPassword(this.settings.username);
this.settings.username = undefined;
await this.saveSettings();
}
}

unloadPlugin() {
Expand Down
5 changes: 2 additions & 3 deletions src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -431,10 +431,9 @@ export class ObsidianGitSettingsTab extends PluginSettingTab {
new Setting(containerEl)
.setName("Username on your git server. E.g. your username on GitHub")
.addText(cb => {
cb.setValue(plugin.settings.username);
cb.setValue(plugin.localStorage.getUsername() ?? "");
cb.onChange((value) => {
plugin.settings.username = value;
plugin.saveSettings();
plugin.localStorage.setUsername(value);
});
});

Expand Down
5 changes: 4 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ export interface ObsidianGitSettings {
customMessageOnAutoBackup: boolean;
autoBackupAfterFileChange: boolean;
treeStructure: boolean;
username: string;
/**
* @deprecated Using `localstorage` instead
*/
username?: string;
differentIntervalCommitAndPush: boolean;
changedFilesInStatusBar: boolean;

Expand Down

0 comments on commit f3668ac

Please sign in to comment.