Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
moughxyz committed Feb 9, 2020
1 parent b5ec64f commit 046f6ca
Show file tree
Hide file tree
Showing 19 changed files with 894 additions and 610 deletions.
4 changes: 2 additions & 2 deletions app/assets/javascripts/application.js
Expand Up @@ -12,8 +12,8 @@ import { WebDeviceInterface } from '@/web_device_interface';

export class Application extends SNApplication {
/* @ngInject */
constructor($compile, $rootScope) {
const deviceInterface = new WebDeviceInterface();
constructor($compile, $timeout, $rootScope) {
const deviceInterface = new WebDeviceInterface({timeout: $timeout});
super({
environment: Environments.Web,
platform: platformFromString(getPlatformString()),
Expand Down
4 changes: 2 additions & 2 deletions app/assets/javascripts/controllers/editor.js
Expand Up @@ -701,7 +701,7 @@ class EditorCtrl extends PureCtrl {
this.saveTags({ strings: strings });
}

saveTags({ strings } = {}) {
async saveTags({ strings } = {}) {
if (!strings && this.state.mutable.tagsString === this.state.note.tagsString()) {
return;
}
Expand Down Expand Up @@ -732,7 +732,7 @@ class EditorCtrl extends PureCtrl {
);
if (!existingRelationship) {
tags.push(
this.application.findOrCreateTag({ title: tagString })
await this.application.findOrCreateTag({ title: tagString })
);
}
}
Expand Down
17 changes: 8 additions & 9 deletions app/assets/javascripts/controllers/lockScreen.js
Expand Up @@ -18,6 +18,12 @@ class LockScreenCtrl {
this.addDestroyHandler();
}

$onInit() {
this.puppet.focusInput = () => {
this.passcodeInput.focus();
};
}

get passcodeInput() {
return document.getElementById(
ELEMENT_ID_PASSCODE_INPUT
Expand Down Expand Up @@ -49,15 +55,7 @@ class LockScreenCtrl {
return;
}
this.passcodeInput.blur();
const success = await this.onValue()(this.formData.passcode);
if(!success) {
this.application.alertManager.alert({
text: "Invalid passcode. Please try again.",
onClose: () => {
this.passcodeInput.focus();
}
});
}
this.onValue()(this.formData.passcode);
}

forgotPasscode() {
Expand Down Expand Up @@ -85,6 +83,7 @@ export class LockScreen {
this.bindToController = true;
this.scope = {
onValue: '&',
puppet: '='
};
}
}
37 changes: 32 additions & 5 deletions app/assets/javascripts/controllers/root.js
@@ -1,5 +1,4 @@
import _ from 'lodash';
import { Challenges } from 'snjs';
import { Challenges, ChallengeResponse } from 'snjs';
import { getPlatformString } from '@/utils';
import template from '%/root.pug';
import { AppStateEvents } from '@/state';
Expand Down Expand Up @@ -46,20 +45,48 @@ class RootCtrl extends PureCtrl {
this.loadApplication();
this.addAppStateObserver();
this.addDragDropHandlers();

application.onReady(() => {
this.handleAutoSignInFromParams();
});

this.lockScreenPuppet = {
focusInput: () => {}
};
}

async watchLockscreenValue() {
return new Promise((resolve) => {
const onLockscreenValue = (value) => {
resolve(new ChallengeResponse({
challenge: Challenges.LocalPasscode,
value: value
}));
};
this.setState({ onLockscreenValue });
});
}

async loadApplication() {
await this.application.prepareForLaunch({
callbacks: {
authChallengeResponses: async (challenges) => {
console.log("Needs challenge repsonses", challenges);
requiresChallengeResponses: async (challenges) => {
if (challenges.includes(Challenges.LocalPasscode)) {
this.setState({ needsUnlock: true });
}
return this.watchLockscreenValue();
},
handleChallengeFailures: (responses) => {
for(const response of responses) {
if(response.challenge === Challenges.LocalPasscode) {
this.application.alertManager.alert({
text: "Invalid passcode. Please try again.",
onClose: () => {
this.lockScreenPuppet.focusInput();
}
});
}
}
},
onReady: async () => {
await this.appState.setApplicationReady();
Expand Down
4 changes: 4 additions & 0 deletions app/assets/javascripts/controllers/tags.js
Expand Up @@ -36,6 +36,10 @@ class TagsPanelCtrl extends PureCtrl {
});
this.selectTag(smartTags[0]);
});

application.onSync(() => {
this.reloadNoteCounts();
});
}

beginStreamingItems() {
Expand Down
22 changes: 13 additions & 9 deletions app/assets/javascripts/directives/views/accountMenu.js
Expand Up @@ -59,19 +59,27 @@ class AccountMenuCtrl extends PureCtrl {
},
mutable: {}
};
application.onReady(() => {
this.setState({
user: this.application.getUser(),
canAddPasscode: !this.application.isEphemeralSession(),
});
application.onReady(async () => {
this.setState(await this.refreshedCredentialState());
this.loadHost();
this.checkForSecurityUpdate();
this.reloadAutoLockInterval();
this.loadBackupsAvailability();
});
application.onCredentialChange(async () => {
this.setState(await this.refreshedCredentialState());
});
this.syncStatus = this.application.getSyncStatus();
}

async refreshedCredentialState() {
return {
user: this.application.getUser(),
canAddPasscode: !this.application.isEphemeralSession(),
hasPasscode: await this.application.hasPasscode()
};
}

$onInit() {
this.initProps({
closeFunction: this.closeFunction
Expand Down Expand Up @@ -473,10 +481,6 @@ class AccountMenuCtrl extends PureCtrl {
}
}

hasPasscode() {
return this.application.hasPasscode();
}

addPasscodeClicked() {
this.setFormDataState({
showPasscodeForm: true
Expand Down
4 changes: 2 additions & 2 deletions app/assets/javascripts/directives/views/passwordWizard.js
Expand Up @@ -38,7 +38,7 @@ class PasswordWizardCtrl {
this.title = "Change Password";
this.changePassword = true;
} else if (this.type === 'upgrade-security') {
this.title = "Security Update";
this.title = "Account Update";
this.securityUpdate = true;
}
this.continueTitle = DEFAULT_CONTINUE_TITLE;
Expand Down Expand Up @@ -135,7 +135,7 @@ class PasswordWizardCtrl {
if (this.changePassword) {
this.formData.status = "Successfully changed password.";
} else if (this.securityUpdate) {
this.formData.status = "Successfully performed security update.";
this.formData.status = "Successfully performed account update.";
}
}

Expand Down
Expand Up @@ -9,11 +9,13 @@ class RevisionPreviewModalCtrl {
constructor(
$element,
$scope,
$timeout
$timeout,
application
) {
this.$element = $element;
this.$scope = $scope;
this.$timeout = $timeout;
this.application = application;
this.configure();
$scope.$on('$destroy', () => {
if (this.identifier) {
Expand Down
13 changes: 4 additions & 9 deletions app/assets/javascripts/services/alertManager.js
@@ -1,13 +1,8 @@
/* eslint-disable prefer-promise-reject-errors */
import { SNAlertManager } from 'snjs';
import { SKAlert } from 'sn-stylekit';

export class AlertManager extends SNAlertManager {
/* @ngInject */
constructor($timeout) {
super();
this.$timeout = $timeout;
}

async alert({
title,
text,
Expand All @@ -21,7 +16,7 @@ export class AlertManager extends SNAlertManager {
style: "neutral",
action: async () => {
if(onClose) {
this.$timeout(onClose);
this.deviceInterface.timeout(onClose);
}
resolve(true);
}
Expand All @@ -48,7 +43,7 @@ export class AlertManager extends SNAlertManager {
style: "neutral",
action: async () => {
if(onCancel) {
this.$timeout(onCancel);
this.deviceInterface.timeout(onCancel);
}
reject(false);
}
Expand All @@ -58,7 +53,7 @@ export class AlertManager extends SNAlertManager {
style: destructive ? "danger" : "info",
action: async () => {
if(onConfirm) {
this.$timeout(onConfirm);
this.deviceInterface.timeout(onConfirm);
}
resolve(true);
}
Expand Down
5 changes: 1 addition & 4 deletions app/assets/javascripts/services/godService.js
Expand Up @@ -16,14 +16,11 @@ export class GodService {
if (this.application.noAccount()) {
return false;
}

const latest = await this.application.getUserVersion();
const updateAvailable = await this.protocolVersion() !== latest;
const updateAvailable = await this.application.protocolService.upgradeAvailable();
if (updateAvailable !== this.securityUpdateAvailable) {
this.securityUpdateAvailable = updateAvailable;
this.$rootScope.$broadcast("security-update-status-changed");
}

return this.securityUpdateAvailable;
}

Expand Down
3 changes: 2 additions & 1 deletion app/assets/javascripts/web_device_interface.js
Expand Up @@ -7,10 +7,11 @@ export class WebDeviceInterface extends DeviceInterface {

constructor({
namespace,
timeout
} = {}) {
super({
namespace,
timeout: setTimeout.bind(getGlobalScope()),
timeout: timeout || setTimeout.bind(getGlobalScope()),
interval: setInterval.bind(getGlobalScope())
});
this.createDatabase();
Expand Down
6 changes: 3 additions & 3 deletions app/assets/templates/directives/account-menu.pug
Expand Up @@ -201,7 +201,7 @@
ng-if='self.state.securityUpdateAvailable'
)
.inline.sk-circle.small.success.mr-8
.inline Security Update Available
.inline Account Update Available
.sk-panel-section
.sk-panel-section-title Encryption
.sk-panel-section-subtitle.info(ng-if='self.state.encryptionEnabled')
Expand All @@ -210,7 +210,7 @@
| {{self.state.encryptionStatusString}}
.sk-panel-section
.sk-panel-section-title Passcode Lock
div(ng-if='!self.hasPasscode()')
div(ng-if='!self.state.hasPasscode')
div(ng-if='self.state.canAddPasscode')
.sk-panel-row(ng-if='!self.state.formData.showPasscodeForm')
.sk-button.info(
Expand Down Expand Up @@ -247,7 +247,7 @@
a.neutral.sk-a.sk-panel-row(
ng-click='self.state.formData.showPasscodeForm = false'
) Cancel
div(ng-if='self.hasPasscode() && !self.state.formData.showPasscodeForm')
div(ng-if='self.state.hasPasscode && !self.state.formData.showPasscodeForm')
.sk-p
| Passcode lock is enabled.
.sk-notification.contrast
Expand Down
4 changes: 2 additions & 2 deletions app/assets/templates/directives/password-wizard.pug
Expand Up @@ -24,7 +24,7 @@
| steps necessary with your supervision.
.sk-panel-row
.sk-panel-column
p.sk-p For more information about security updates, please visit
p.sk-p For more information about account updates, please visit
a.sk-a.info(
href='https://standardnotes.org/help/security',
rel='noopener',
Expand Down Expand Up @@ -121,7 +121,7 @@
p.sk-p.sk-panel-row.info-i Your password has been successfully changed.
div(ng-if='ctrl.securityUpdate')
p.sk-p.sk-panel-row.info-i
| The security update has been successfully applied to your account.
| The account update has been successfully applied to your account.
p.sk-p.sk-panel-row
| Please ensure you are running the latest version of Standard Notes
| on all platforms to ensure maximum compatibility.
Expand Down
2 changes: 1 addition & 1 deletion app/assets/templates/footer.pug
Expand Up @@ -42,7 +42,7 @@
ng-click='ctrl.openSecurityUpdate()',
ng-show='ctrl.securityUpdateAvailable'
)
span.success.sk-label Security update available.
span.success.sk-label Account update available.
.sk-app-bar-item(
ng-click='ctrl.clickedNewUpdateAnnouncement()',
ng-show='ctrl.newUpdateAvailable == true'
Expand Down
2 changes: 2 additions & 0 deletions app/assets/templates/root.pug
Expand Up @@ -3,6 +3,8 @@
)
lock-screen(
ng-if='self.state.needsUnlock'
on-value='self.state.onLockscreenValue',
puppet='self.lockScreenPuppet'
)
#app.app(
ng-class='self.state.appClass',
Expand Down

0 comments on commit 046f6ca

Please sign in to comment.