Skip to content

Commit

Permalink
feat: snjs app groups (#468)
Browse files Browse the repository at this point in the history
* feat: snjs app groups

* fix: update snjs version to point to wip commit

* wip: account switcher

* feat: rename lock manager to auto lock service

* fix: more relevant sign out copy

* chore(deps): update snjs

* fix: use setTimeout instead of setImmediate

* feat: make account switcher expiremental feature

* chore(deps): upgrade snjs
  • Loading branch information
Mo Bitar authored Sep 15, 2020
1 parent ae6ef50 commit 2b6abee
Show file tree
Hide file tree
Showing 46 changed files with 590 additions and 375 deletions.
2 changes: 2 additions & 0 deletions app/assets/javascripts/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import angular from 'angular';
import { configRoutes } from './routes';

import { ApplicationGroup } from './ui_models/application_group';
import { AccountSwitcher } from './views/account_switcher/account_switcher';

import {
ApplicationGroupView,
Expand Down Expand Up @@ -104,6 +105,7 @@ function startApplication(
angular
.module('app')
.directive('accountMenu', () => new AccountMenu())
.directive('accountSwitcher', () => new AccountSwitcher())
.directive('actionsMenu', () => new ActionsMenu())
.directive('challengeModal', () => new ChallengeModal())
.directive('componentModal', () => new ComponentModal())
Expand Down
23 changes: 11 additions & 12 deletions app/assets/javascripts/database.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { SNAlertService } from "@node_modules/snjs/dist/@types";
import { SNAlertService } from "snjs/dist/@types";

const DB_NAME = 'standardnotes';
const STORE_NAME = 'items';
const READ_WRITE = 'readwrite';

Expand All @@ -17,18 +16,18 @@ const DB_DELETION_BLOCKED =
const QUOTE_EXCEEDED_ERROR = 'QuotaExceededError';

export class Database {

private locked = true
private alertService?: SNAlertService
private db?: IDBDatabase

public deinit() {
this.alertService = undefined;
this.db = undefined;
constructor(
public databaseName: string,
private alertService: SNAlertService) {

}

public setAlertService(alertService: SNAlertService) {
this.alertService = alertService;
public deinit() {
(this.alertService as any) = undefined;
this.db = undefined;
}

/**
Expand All @@ -41,7 +40,7 @@ export class Database {
/**
* Opens the database natively, or returns the existing database object if already opened.
* @param onNewDatabase - Callback to invoke when a database has been created
* as part of the open process. This can happen on new application sessions, or if the
* as part of the open process. This can happen on new application sessions, or if the
* browser deleted the database without the user being aware.
*/
public async openDatabase(onNewDatabase?: () => void): Promise<IDBDatabase | undefined> {
Expand All @@ -51,7 +50,7 @@ export class Database {
if (this.db) {
return this.db;
}
const request = window.indexedDB.open(DB_NAME, 1);
const request = window.indexedDB.open(this.databaseName, 1);
return new Promise((resolve, reject) => {
request.onerror = (event) => {
const target = event!.target! as any;
Expand Down Expand Up @@ -181,7 +180,7 @@ export class Database {
}

public async clearAllPayloads(): Promise<void> {
const deleteRequest = window.indexedDB.deleteDatabase(DB_NAME);
const deleteRequest = window.indexedDB.deleteDatabase(this.databaseName);
return new Promise((resolve, reject) => {
deleteRequest.onerror = () => {
reject(Error('Error deleting database.'));
Expand Down
4 changes: 2 additions & 2 deletions app/assets/javascripts/directives/functional/selectOnFocus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ export function selectOnFocus($window: ng.IWindowService) {
if (!$window.getSelection()!.toString()) {
const input = element[0] as HTMLInputElement;
/** Allow text to populate */
setImmediate(() => {
setTimeout(() => {
input.setSelectionRange(0, input.value.length);
})
}, 0);
}
});
}
Expand Down
9 changes: 5 additions & 4 deletions app/assets/javascripts/directives/views/accountMenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ type AccountMenuState = {
class AccountMenuCtrl extends PureViewCtrl<{}, AccountMenuState> {

public appVersion: string
private syncStatus?: SyncOpStatus
/** @template */
syncStatus?: SyncOpStatus
private closeFunction?: () => void

/* @ngInject */
Expand All @@ -86,7 +87,7 @@ class AccountMenuCtrl extends PureViewCtrl<{}, AccountMenuState> {
getInitialState() {
return {
appVersion: 'v' + ((window as any).electronAppVersion || this.appVersion),
passcodeAutoLockOptions: this.application!.getLockService().getAutoLockIntervalOptions(),
passcodeAutoLockOptions: this.application!.getAutolockService().getAutoLockIntervalOptions(),
user: this.application!.getUser(),
formData: {
mergeLocal: true,
Expand Down Expand Up @@ -463,15 +464,15 @@ class AccountMenuCtrl extends PureViewCtrl<{}, AccountMenuState> {
}

async reloadAutoLockInterval() {
const interval = await this.application!.getLockService().getAutoLockInterval();
const interval = await this.application!.getAutolockService().getAutoLockInterval();
this.setState({
selectedAutoLockInterval: interval
});
}

async selectAutoLockInterval(interval: number) {
const run = async () => {
await this.application!.getLockService().setAutoLockInterval(interval);
await this.application!.getAutolockService().setAutoLockInterval(interval);
this.reloadAutoLockInterval();
};
const needsPrivilege = await this.application!.privilegesService!.actionRequiresPrivilege(
Expand Down
2 changes: 1 addition & 1 deletion app/assets/javascripts/directives/views/editorMenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { SNComponent, SNItem, ComponentArea } from 'snjs';
import { isDesktopApplication } from '@/utils';
import template from '%/directives/editor-menu.pug';
import { PureViewCtrl } from '@Views/abstract/pure_view_ctrl';
import { ComponentMutator } from '@node_modules/snjs/dist/@types/models';
import { ComponentMutator } from 'snjs/dist/@types/models';

interface EditorMenuScope {
callback: (component: SNComponent) => void
Expand Down
2 changes: 1 addition & 1 deletion app/assets/javascripts/directives/views/historyMenu.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { WebDirective } from '../../types';
import { WebApplication } from '@/ui_models/application';
import template from '%/directives/history-menu.pug';
import { SNItem, ItemHistoryEntry } from '@node_modules/snjs/dist/@types';
import { SNItem, ItemHistoryEntry } from 'snjs/dist/@types';
import { PureViewCtrl } from '@/views';
import { ItemSessionHistory } from 'snjs/dist/@types/services/history/session/item_session_history';
import { RemoteHistoryList, RemoteHistoryListEntry } from 'snjs/dist/@types/services/history/history_manager';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { WebApplication } from '@/ui_models/application';
import template from '%/directives/privileges-management-modal.pug';
import { PrivilegeCredential, ProtectedAction, SNPrivileges, PrivilegeSessionLength } from 'snjs';
import { PureViewCtrl } from '@Views/abstract/pure_view_ctrl';
import { PrivilegeMutator } from '@node_modules/snjs/dist/@types/models';
import { PrivilegeMutator } from 'snjs/dist/@types/models';

type DisplayInfo = {
label: string
Expand Down Expand Up @@ -32,7 +32,7 @@ class PrivilegesManagementModalCtrl extends PureViewCtrl {
super($timeout);
this.$element = $element;
}

async onAppLaunch() {
super.onAppLaunch();
this.hasPasscode = this.application.hasPasscode();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
ComponentArea
} from 'snjs';
import template from '%/directives/revision-preview-modal.pug';
import { PayloadContent } from '@node_modules/snjs/dist/@types/protocol/payloads/generator';
import { PayloadContent } from 'snjs/dist/@types/protocol/payloads/generator';
import { confirmDialog } from '@/services/alertService';

interface RevisionPreviewScope {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { ApplicationGroup } from './../ui_models/application_group';
import { WebApplication } from '@/ui_models/application';
import { isDesktopApplication } from '@/utils';
import { AppStateEvent } from '@/ui_models/app_state';
Expand All @@ -12,7 +13,7 @@ const LOCK_INTERVAL_ONE_HOUR = 3600 * MILLISECONDS_PER_SECOND;

const STORAGE_KEY_AUTOLOCK_INTERVAL = "AutoLockIntervalKey";

export class LockManager {
export class AutolockService {

private application: WebApplication
private unsubState: any
Expand All @@ -21,11 +22,13 @@ export class LockManager {
private lockAfterDate?: Date
private lockTimeout?: any

constructor(application: WebApplication) {
constructor(
application: WebApplication
) {
this.application = application;
setImmediate(() => {
setTimeout(() => {
this.observeVisibility();
});
}, 0);
}

observeVisibility() {
Expand All @@ -50,6 +53,10 @@ export class LockManager {
}
}

private lockApplication() {
this.application.lock();
}

async setAutoLockInterval(interval: number) {
return this.application!.setValue(
STORAGE_KEY_AUTOLOCK_INTERVAL,
Expand Down Expand Up @@ -118,7 +125,7 @@ export class LockManager {
this.lockAfterDate &&
new Date() > this.lockAfterDate
) {
this.application.lock();
this.lockApplication();
}
this.cancelAutoLockTimer();
} else {
Expand All @@ -132,9 +139,9 @@ export class LockManager {
return;
}
/**
* Use a timeout if possible, but if the computer is put to sleep, timeouts won't
* work. Need to set a date as backup. this.lockAfterDate does not need to be
* persisted, as living in memory is sufficient. If memory is cleared, then the
* Use a timeout if possible, but if the computer is put to sleep, timeouts won't
* work. Need to set a date as backup. this.lockAfterDate does not need to be
* persisted, as living in memory is sufficient. If memory is cleared, then the
* application will lock anyway.
*/
const addToNow = (seconds: number) => {
Expand All @@ -145,7 +152,7 @@ export class LockManager {
this.lockAfterDate = addToNow(interval / MILLISECONDS_PER_SECOND);
this.lockTimeout = setTimeout(() => {
this.cancelAutoLockTimer();
this.application.lock();
this.lockApplication();
this.lockAfterDate = undefined;
}, interval);
}
Expand Down
2 changes: 1 addition & 1 deletion app/assets/javascripts/services/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ export { AlertService } from './alertService';
export { ArchiveManager } from './archiveManager';
export { DesktopManager } from './desktopManager';
export { KeyboardManager } from './keyboardManager';
export { LockManager } from './lockManager';
export { AutolockService } from './autolock_service';
export { NativeExtManager } from './nativeExtManager';
export { PreferencesManager } from './preferencesManager';
export { StatusManager } from './statusManager';
Expand Down
4 changes: 2 additions & 2 deletions app/assets/javascripts/services/nativeExtManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import {
Copy,
dictToArray
} from 'snjs';
import { PayloadContent } from '@node_modules/snjs/dist/@types/protocol/payloads/generator';
import { ComponentPermission } from '@node_modules/snjs/dist/@types/models/app/component';
import { PayloadContent } from 'snjs/dist/@types/protocol/payloads/generator';
import { ComponentPermission } from 'snjs/dist/@types/models/app/component';

/** A class for handling installation of system extensions */
export class NativeExtManager extends ApplicationService {
Expand Down
2 changes: 1 addition & 1 deletion app/assets/javascripts/strings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export const STRING_INVALID_IMPORT_FILE = "Unable to open file. Ensure it is a p
export function StringImportError(errorCount: number) {
return `Import complete. ${errorCount} items were not imported because there was an error decrypting them. Make sure the password is correct and try again.`;
}
export const STRING_ENTER_ACCOUNT_PASSCODE = 'Enter your application passcode to decrypt your data and unlock the application';
export const STRING_ENTER_ACCOUNT_PASSCODE = 'Enter your application passcode to unlock the application';
export const STRING_ENTER_ACCOUNT_PASSWORD = 'Enter your account password';
export const STRING_ENTER_PASSCODE_FOR_MIGRATION = 'Your application passcode is required to perform an upgrade of your local data storage structure.';
export const STRING_ENTER_PASSCODE_FOR_LOGIN_REGISTER = 'Enter your application passcode before signing in or registering';
Expand Down
4 changes: 4 additions & 0 deletions app/assets/javascripts/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ export interface PermissionsModalScope extends Partial<ng.IScope> {
callback: (approved: boolean) => void
}

export interface AccountSwitcherScope extends Partial<ng.IScope> {
application: any
}

export type PanelPuppet = {
onReady?: () => void
ready?: boolean
Expand Down
Loading

0 comments on commit 2b6abee

Please sign in to comment.