Skip to content

Commit

Permalink
fix: distinguish between app launch and start
Browse files Browse the repository at this point in the history
  • Loading branch information
moughxyz authored and laurentsenta committed Dec 15, 2021
1 parent 163cb50 commit 1babe68
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
)
#app.app(
ng-class='self.state.appClass',
ng-if='!self.state.needsUnlock && self.state.ready'
ng-if='!self.state.needsUnlock && self.state.launched'
)
tags-view(application='self.application')
notes-view(application='self.application')
Expand Down
63 changes: 35 additions & 28 deletions app/assets/javascripts/views/application/application_view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,25 @@ import { WebDirective } from '@/types';
import { getPlatformString } from '@/utils';
import template from './application-view.pug';
import { AppStateEvent, PanelResizedData } from '@/ui_models/app_state';
import { ApplicationEvent, Challenge, removeFromArray } from '@standardnotes/snjs';
import {
PANEL_NAME_NOTES,
PANEL_NAME_TAGS
} from '@/views/constants';
import {
STRING_DEFAULT_FILE_ERROR
} from '@/strings';
ApplicationEvent,
Challenge,
removeFromArray,
} from '@standardnotes/snjs';
import { PANEL_NAME_NOTES, PANEL_NAME_TAGS } from '@/views/constants';
import { STRING_DEFAULT_FILE_ERROR } from '@/strings';
import { PureViewCtrl } from '@Views/abstract/pure_view_ctrl';
import { alertDialog } from '@/services/alertService';

class ApplicationViewCtrl extends PureViewCtrl<unknown, {
ready?: boolean,
needsUnlock?: boolean,
appClass: string,
}> {
class ApplicationViewCtrl extends PureViewCtrl<
unknown,
{
started?: boolean;
launched?: boolean;
needsUnlock?: boolean;
appClass: string;
}
> {
public platformString: string;
private notesCollapsed = false;
private tagsCollapsed = false;
Expand Down Expand Up @@ -76,7 +79,7 @@ class ApplicationViewCtrl extends PureViewCtrl<unknown, {
this.$timeout(() => {
this.challenges.push(challenge);
});
}
},
});
await this.application.launch();
}
Expand All @@ -90,14 +93,17 @@ class ApplicationViewCtrl extends PureViewCtrl<unknown, {
async onAppStart() {
super.onAppStart();
this.setState({
ready: true,
needsUnlock: this.application.hasPasscode()
started: true,
needsUnlock: this.application.hasPasscode(),
});
}

async onAppLaunch() {
super.onAppLaunch();
this.setState({ needsUnlock: false });
this.setState({
launched: true,
needsUnlock: false,
});
this.handleDemoSignInFromParams();
}

Expand All @@ -111,12 +117,12 @@ class ApplicationViewCtrl extends PureViewCtrl<unknown, {
switch (eventName) {
case ApplicationEvent.LocalDatabaseReadError:
alertDialog({
text: 'Unable to load local database. Please restart the app and try again.'
text: 'Unable to load local database. Please restart the app and try again.',
});
break;
case ApplicationEvent.LocalDatabaseWriteError:
alertDialog({
text: 'Unable to write to local database. Please restart the app and try again.'
text: 'Unable to write to local database. Please restart the app and try again.',
});
break;
}
Expand All @@ -132,9 +138,13 @@ class ApplicationViewCtrl extends PureViewCtrl<unknown, {
if (panel === PANEL_NAME_TAGS) {
this.tagsCollapsed = collapsed;
}
let appClass = "";
if (this.notesCollapsed) { appClass += "collapsed-notes"; }
if (this.tagsCollapsed) { appClass += " collapsed-tags"; }
let appClass = '';
if (this.notesCollapsed) {
appClass += 'collapsed-notes';
}
if (this.tagsCollapsed) {
appClass += ' collapsed-tags';
}
this.setState({ appClass });
} else if (eventName === AppStateEvent.WindowDidFocus) {
if (!(await this.application.isLocked())) {
Expand Down Expand Up @@ -163,23 +173,20 @@ class ApplicationViewCtrl extends PureViewCtrl<unknown, {
if (event.dataTransfer?.files.length) {
event.preventDefault();
void alertDialog({
text: STRING_DEFAULT_FILE_ERROR
text: STRING_DEFAULT_FILE_ERROR,
});
}
}

async handleDemoSignInFromParams() {
if (
this.$location.search().demo === 'true' &&
!this.application.hasAccount()
!this.application.hasAccount()
) {
await this.application.setCustomHost(
'https://syncing-server-demo.standardnotes.com'
);
this.application.signIn(
'[email protected]',
'password',
);
this.application.signIn('[email protected]', 'password');
}
}
}
Expand All @@ -193,7 +200,7 @@ export class ApplicationView extends WebDirective {
this.controllerAs = 'self';
this.bindToController = true;
this.scope = {
application: '='
application: '=',
};
}
}

0 comments on commit 1babe68

Please sign in to comment.