Skip to content

Commit

Permalink
Stop removing Electron event listeners after adding the new ones
Browse files Browse the repository at this point in the history
  • Loading branch information
dmsnell committed Aug 5, 2020
1 parent e8bfbb2 commit 97bdc2c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
9 changes: 5 additions & 4 deletions lib/boot-without-auth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@ class AppWithoutAuth extends Component<Props, State> {
window.electron?.receive('appCommand', this.onAppCommand);
}

componentWillUnmount() {
login(token: string, username: string, createWelcomeNote: boolean) {
window.electron?.removeListener('appCommand');
this.props.onAuth(token, username, createWelcomeNote);
}

onAppCommand = (event) => {
Expand Down Expand Up @@ -76,7 +77,7 @@ class AppWithoutAuth extends Component<Props, State> {
if (!user.access_token) {
throw new Error('missing access token');
}
this.props.onAuth(user.access_token, username, false);
this.login(user.access_token, username, false);
})
.catch((error: unknown) => {
if (
Expand Down Expand Up @@ -106,7 +107,7 @@ class AppWithoutAuth extends Component<Props, State> {
}

recordEvent('user_account_created');
this.props.onAuth(user.access_token, username, true);
this.login(user.access_token, username, true);
})
.catch(() => {
this.setState({ authStatus: 'unknown-error' });
Expand All @@ -115,7 +116,7 @@ class AppWithoutAuth extends Component<Props, State> {
};

tokenLogin = (username: string, token: string) => {
this.props.onAuth(token, username, false);
this.login(token, username, false);
};

render() {
Expand Down
10 changes: 7 additions & 3 deletions lib/boot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import './utils/ensure-platform-support';

import { parse } from 'cookie';

import analytics from './analytics';
import getConfig from '../get-config';
import { boot as bootWithoutAuth } from './boot-without-auth';
import { boot as bootLoggingOut } from './logging-out';
Expand All @@ -24,8 +23,13 @@ const clearStorage = (): Promise<void> =>

const settings = localStorage.getItem('simpleNote');
if (settings) {
const { accountName, ...otherSettings } = settings;
localStorage.setItem('simpleNote', otherSettings);
try {
const { accountName, ...otherSettings } = JSON.parse(settings);
localStorage.setItem('simpleNote', JSON.stringify(otherSettings));
} catch (e) {
// pass - we only care if we can successfully do this,
// not if we fail to do it
}
}

Promise.all([
Expand Down

0 comments on commit 97bdc2c

Please sign in to comment.