ApplicationService integration
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
import { ApplicationEvents } from 'snjs';
|
import { ApplicationService } from 'snjs';
|
||||||
export class PureCtrl {
|
|
||||||
|
export class PureCtrl extends ApplicationService {
|
||||||
/* @ngInject */
|
/* @ngInject */
|
||||||
constructor(
|
constructor(
|
||||||
$scope,
|
$scope,
|
||||||
@@ -10,21 +11,23 @@ export class PureCtrl {
|
|||||||
if (!$scope || !$timeout || !application || !appState) {
|
if (!$scope || !$timeout || !application || !appState) {
|
||||||
throw 'Invalid PureCtrl construction.';
|
throw 'Invalid PureCtrl construction.';
|
||||||
}
|
}
|
||||||
|
super(application);
|
||||||
this.$scope = $scope;
|
this.$scope = $scope;
|
||||||
this.$timeout = $timeout;
|
this.$timeout = $timeout;
|
||||||
this.appState = appState;
|
this.appState = appState;
|
||||||
this.application = application;
|
|
||||||
this.state = this.getInitialState();
|
|
||||||
this.props = {};
|
this.props = {};
|
||||||
|
/* Allow caller constructor to finish setting instance variables */
|
||||||
|
setImmediate(() => {
|
||||||
|
this.state = this.getInitialState();
|
||||||
|
});
|
||||||
$scope.$on('$destroy', () => {
|
$scope.$on('$destroy', () => {
|
||||||
this.unsubApp();
|
|
||||||
this.unsubState();
|
this.unsubState();
|
||||||
|
this.deinit();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
$onInit() {
|
$onInit() {
|
||||||
this.addAppStateObserver();
|
this.addAppStateObserver();
|
||||||
this.addAppEventObserver();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @private */
|
/** @private */
|
||||||
@@ -60,49 +63,13 @@ export class PureCtrl {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
addAppEventObserver() {
|
|
||||||
if (this.application.isStarted()) {
|
|
||||||
this.onAppStart();
|
|
||||||
}
|
|
||||||
if (!this.appState.isLocked()) {
|
|
||||||
this.onAppLaunch();
|
|
||||||
}
|
|
||||||
this.unsubApp = this.application.addEventObserver(async (eventName) => {
|
|
||||||
this.onAppEvent(eventName);
|
|
||||||
if (eventName === ApplicationEvents.Started) {
|
|
||||||
await this.resetState();
|
|
||||||
await this.onAppStart();
|
|
||||||
} else if (eventName === ApplicationEvents.Launched) {
|
|
||||||
await this.onAppLaunch();
|
|
||||||
} else if (eventName === ApplicationEvents.CompletedSync) {
|
|
||||||
this.onAppSync();
|
|
||||||
} else if (eventName === ApplicationEvents.KeyStatusChanged) {
|
|
||||||
this.onAppKeyChange();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
onAppEvent(eventName) {
|
|
||||||
/** Optional override */
|
|
||||||
}
|
|
||||||
|
|
||||||
onAppStateEvent(eventName, data) {
|
onAppStateEvent(eventName, data) {
|
||||||
/** Optional override */
|
/** Optional override */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @override */
|
||||||
async onAppStart() {
|
async onAppStart() {
|
||||||
/** Optional override */
|
await this.resetState();
|
||||||
}
|
return super.onAppStart();
|
||||||
|
|
||||||
async onAppLaunch() {
|
|
||||||
/** Optional override */
|
|
||||||
}
|
|
||||||
|
|
||||||
async onAppKeyChange() {
|
|
||||||
/** Optional override */
|
|
||||||
}
|
|
||||||
|
|
||||||
onAppSync() {
|
|
||||||
/** Optional override */
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -61,7 +61,6 @@ class RootCtrl extends PureCtrl {
|
|||||||
onAppLaunch() {
|
onAppLaunch() {
|
||||||
super.onAppLaunch();
|
super.onAppLaunch();
|
||||||
this.setState({ needsUnlock: false });
|
this.setState({ needsUnlock: false });
|
||||||
this.application.registerService(this.themeManager);
|
|
||||||
this.handleAutoSignInFromParams();
|
this.handleAutoSignInFromParams();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -45,9 +45,14 @@ class AccountMenuCtrl extends PureCtrl {
|
|||||||
this.archiveManager = archiveManager;
|
this.archiveManager = archiveManager;
|
||||||
this.godService = godService;
|
this.godService = godService;
|
||||||
this.lockManager = lockManager;
|
this.lockManager = lockManager;
|
||||||
|
this.appVersion = appVersion;
|
||||||
|
this.syncStatus = this.application.getSyncStatus();
|
||||||
|
}
|
||||||
|
|
||||||
this.state = {
|
/** @override */
|
||||||
appVersion: 'v' + (window.electronAppVersion || appVersion),
|
getInitialState() {
|
||||||
|
return {
|
||||||
|
appVersion: 'v' + (window.electronAppVersion || this.appVersion),
|
||||||
passcodeAutoLockOptions: this.lockManager.getAutoLockIntervalOptions(),
|
passcodeAutoLockOptions: this.lockManager.getAutoLockIntervalOptions(),
|
||||||
user: this.application.getUser(),
|
user: this.application.getUser(),
|
||||||
formData: {
|
formData: {
|
||||||
@@ -56,7 +61,6 @@ class AccountMenuCtrl extends PureCtrl {
|
|||||||
},
|
},
|
||||||
mutable: {}
|
mutable: {}
|
||||||
};
|
};
|
||||||
this.syncStatus = this.application.getSyncStatus();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async onAppKeyChange() {
|
async onAppKeyChange() {
|
||||||
|
|||||||
@@ -2,13 +2,13 @@
|
|||||||
// An interface used by the Desktop app to interact with SN
|
// An interface used by the Desktop app to interact with SN
|
||||||
import pull from 'lodash/pull';
|
import pull from 'lodash/pull';
|
||||||
import { isDesktopApplication } from '@/utils';
|
import { isDesktopApplication } from '@/utils';
|
||||||
import { EncryptionIntents } from 'snjs';
|
import { EncryptionIntents, ApplicationService, ApplicationEvents } from 'snjs';
|
||||||
|
|
||||||
const COMPONENT_DATA_KEY_INSTALL_ERROR = 'installError';
|
const COMPONENT_DATA_KEY_INSTALL_ERROR = 'installError';
|
||||||
const COMPONENT_CONTENT_KEY_PACKAGE_INFO = 'package_info';
|
const COMPONENT_CONTENT_KEY_PACKAGE_INFO = 'package_info';
|
||||||
const COMPONENT_CONTENT_KEY_LOCAL_URL = 'local_url';
|
const COMPONENT_CONTENT_KEY_LOCAL_URL = 'local_url';
|
||||||
|
|
||||||
export class DesktopManager {
|
export class DesktopManager extends ApplicationService {
|
||||||
/* @ngInject */
|
/* @ngInject */
|
||||||
constructor(
|
constructor(
|
||||||
$rootScope,
|
$rootScope,
|
||||||
@@ -16,6 +16,7 @@ export class DesktopManager {
|
|||||||
application,
|
application,
|
||||||
appState,
|
appState,
|
||||||
) {
|
) {
|
||||||
|
super(application);
|
||||||
this.$rootScope = $rootScope;
|
this.$rootScope = $rootScope;
|
||||||
this.$timeout = $timeout;
|
this.$timeout = $timeout;
|
||||||
this.appState = appState;
|
this.appState = appState;
|
||||||
@@ -23,19 +24,21 @@ export class DesktopManager {
|
|||||||
this.componentActivationObservers = [];
|
this.componentActivationObservers = [];
|
||||||
this.updateObservers = [];
|
this.updateObservers = [];
|
||||||
this.isDesktop = isDesktopApplication();
|
this.isDesktop = isDesktopApplication();
|
||||||
|
}
|
||||||
|
|
||||||
$rootScope.$on('initial-data-loaded', () => {
|
/** @override */
|
||||||
|
onAppEvent(eventName) {
|
||||||
|
super.onAppEvent(eventName);
|
||||||
|
if (eventName === ApplicationEvents.LocalDataLoaded) {
|
||||||
this.dataLoaded = true;
|
this.dataLoaded = true;
|
||||||
if (this.dataLoadHandler) {
|
if (this.dataLoadHandler) {
|
||||||
this.dataLoadHandler();
|
this.dataLoadHandler();
|
||||||
}
|
}
|
||||||
});
|
} else if (eventName === ApplicationEvents.MajorDataChange) {
|
||||||
|
|
||||||
$rootScope.$on('major-data-change', () => {
|
|
||||||
if (this.majorDataChangeHandler) {
|
if (this.majorDataChangeHandler) {
|
||||||
this.majorDataChangeHandler();
|
this.majorDataChangeHandler();
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
saveBackup() {
|
saveBackup() {
|
||||||
|
|||||||
@@ -1,24 +1,27 @@
|
|||||||
import { isDesktopApplication, dictToArray } from '@/utils';
|
import { isDesktopApplication, dictToArray } from '@/utils';
|
||||||
import {
|
import {
|
||||||
ApplicationEvents,
|
|
||||||
SNPredicate,
|
SNPredicate,
|
||||||
ContentTypes,
|
ContentTypes,
|
||||||
CreateMaxPayloadFromAnyObject
|
CreateMaxPayloadFromAnyObject,
|
||||||
|
ApplicationService
|
||||||
} from 'snjs';
|
} from 'snjs';
|
||||||
|
|
||||||
const STREAM_ITEMS_PERMISSION = 'stream-items';
|
const STREAM_ITEMS_PERMISSION = 'stream-items';
|
||||||
|
|
||||||
/** A class for handling installation of system extensions */
|
/** A class for handling installation of system extensions */
|
||||||
export class NativeExtManager {
|
export class NativeExtManager extends ApplicationService {
|
||||||
/* @ngInject */
|
/* @ngInject */
|
||||||
constructor(application) {
|
constructor(application) {
|
||||||
|
super(application);
|
||||||
this.application = application;
|
this.application = application;
|
||||||
this.extManagerId = 'org.standardnotes.extensions-manager';
|
this.extManagerId = 'org.standardnotes.extensions-manager';
|
||||||
this.batchManagerId = 'org.standardnotes.batch-manager';
|
this.batchManagerId = 'org.standardnotes.batch-manager';
|
||||||
|
}
|
||||||
this.unsub = application.addSingleEventObserver(ApplicationEvents.Launched, () => {
|
|
||||||
this.reload();
|
/** @override */
|
||||||
});
|
onAppLaunch() {
|
||||||
|
super.onAppLaunch();
|
||||||
|
this.reload();
|
||||||
}
|
}
|
||||||
|
|
||||||
get extManagerPred() {
|
get extManagerPred() {
|
||||||
|
|||||||
@@ -1,4 +1,10 @@
|
|||||||
import { ApplicationEvents, SNPredicate, ContentTypes, CreateMaxPayloadFromAnyObject } from 'snjs';
|
import {
|
||||||
|
ApplicationEvents,
|
||||||
|
SNPredicate,
|
||||||
|
ContentTypes,
|
||||||
|
CreateMaxPayloadFromAnyObject,
|
||||||
|
ApplicationService
|
||||||
|
} from 'snjs';
|
||||||
|
|
||||||
export const PrefKeys = {
|
export const PrefKeys = {
|
||||||
TagsPanelWidth: 'tagsPanelWidth',
|
TagsPanelWidth: 'tagsPanelWidth',
|
||||||
@@ -17,18 +23,21 @@ export const PrefKeys = {
|
|||||||
NotesHideTags: 'hideTags'
|
NotesHideTags: 'hideTags'
|
||||||
};
|
};
|
||||||
|
|
||||||
export class PreferencesManager {
|
export class PreferencesManager extends ApplicationService {
|
||||||
/* @ngInject */
|
/* @ngInject */
|
||||||
constructor(
|
constructor(
|
||||||
appState,
|
appState,
|
||||||
application
|
application
|
||||||
) {
|
) {
|
||||||
this.application = application;
|
super(application);
|
||||||
this.appState = appState;
|
this.appState = appState;
|
||||||
this.unsub = application.addSingleEventObserver(ApplicationEvents.Launched, () => {
|
}
|
||||||
this.streamPreferences();
|
|
||||||
this.loadSingleton();
|
/** @override */
|
||||||
});
|
onAppLaunch() {
|
||||||
|
super.onAppLaunch();
|
||||||
|
this.streamPreferences();
|
||||||
|
this.loadSingleton();
|
||||||
}
|
}
|
||||||
|
|
||||||
streamPreferences() {
|
streamPreferences() {
|
||||||
@@ -61,7 +70,7 @@ export class PreferencesManager {
|
|||||||
|
|
||||||
syncUserPreferences() {
|
syncUserPreferences() {
|
||||||
if (this.userPreferences) {
|
if (this.userPreferences) {
|
||||||
this.application.saveItem({item: this.userPreferences});
|
this.application.saveItem({ item: this.userPreferences });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,34 +3,23 @@ import {
|
|||||||
ApplicationEvents,
|
ApplicationEvents,
|
||||||
StorageValueModes,
|
StorageValueModes,
|
||||||
EncryptionIntents,
|
EncryptionIntents,
|
||||||
PureService,
|
ApplicationService,
|
||||||
} from 'snjs';
|
} from 'snjs';
|
||||||
import { AppStateEvents } from '@/state';
|
import { AppStateEvents } from '@/state';
|
||||||
|
|
||||||
const CACHED_THEMES_KEY = 'cachedThemes';
|
const CACHED_THEMES_KEY = 'cachedThemes';
|
||||||
|
|
||||||
export class ThemeManager extends PureService {
|
export class ThemeManager extends ApplicationService {
|
||||||
/* @ngInject */
|
/* @ngInject */
|
||||||
constructor(
|
constructor(
|
||||||
application,
|
application,
|
||||||
appState,
|
appState,
|
||||||
desktopManager,
|
desktopManager,
|
||||||
) {
|
) {
|
||||||
super();
|
super(application);
|
||||||
this.application = application;
|
|
||||||
this.appState = appState;
|
this.appState = appState;
|
||||||
this.desktopManager = desktopManager;
|
this.desktopManager = desktopManager;
|
||||||
this.activeThemes = [];
|
this.activeThemes = [];
|
||||||
if (this.application.isStarted()) {
|
|
||||||
this.onAppStart();
|
|
||||||
}
|
|
||||||
this.unsub = application.addEventObserver((event) => {
|
|
||||||
if (event === ApplicationEvents.Started) {
|
|
||||||
this.onAppStart();
|
|
||||||
} else if (event === ApplicationEvents.SignedOut) {
|
|
||||||
this.deactivateAllThemes();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
this.unsubState = appState.addObserver((eventName, data) => {
|
this.unsubState = appState.addObserver((eventName, data) => {
|
||||||
if (eventName === AppStateEvents.DesktopExtsReady) {
|
if (eventName === AppStateEvents.DesktopExtsReady) {
|
||||||
this.activateCachedThemes();
|
this.activateCachedThemes();
|
||||||
@@ -38,18 +27,20 @@ export class ThemeManager extends PureService {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @override */
|
||||||
onAppStart() {
|
onAppStart() {
|
||||||
|
super.onAppStart();
|
||||||
this.registerObservers();
|
this.registerObservers();
|
||||||
if (!this.desktopManager.isDesktop) {
|
if (!this.desktopManager.isDesktop) {
|
||||||
this.activateCachedThemes();
|
this.activateCachedThemes();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @override */
|
onAppEvent(eventName) {
|
||||||
async deinit() {
|
super.onAppEvent(eventName);
|
||||||
super.deinit();
|
if (eventName === ApplicationEvents.SignedOut) {
|
||||||
this.unsubState();
|
this.deactivateAllThemes();
|
||||||
this.activeThemes = [];
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async activateCachedThemes() {
|
async activateCachedThemes() {
|
||||||
|
|||||||
1184
dist/javascripts/app.js
vendored
1184
dist/javascripts/app.js
vendored
File diff suppressed because one or more lines are too long
2
dist/javascripts/app.js.map
vendored
2
dist/javascripts/app.js.map
vendored
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user