This commit is contained in:
Mo Bitar
2020-02-09 16:46:12 -06:00
parent 1a87df0db8
commit 1497048c72
16 changed files with 307 additions and 210 deletions

View File

@@ -17,6 +17,7 @@ export class PureCtrl {
this.addAppStateObserver();
this.addAppEventObserver();
$scope.$on('$destroy', () => {
console.log("On destroy", this);
this.unsubApp();
this.unsubState();
});

View File

@@ -74,8 +74,12 @@ class EditorCtrl extends PureCtrl {
}
};
this.leftResizeControl = {};
this.rightResizeControl = {};
this.leftPanelPuppet = {
onReady: () => this.reloadPreferences()
};
this.rightPanelPuppet = {
onReady: () => this.reloadPreferences()
};
this.addSyncStatusObserver();
this.registerKeyboardShortcuts();
@@ -98,7 +102,7 @@ class EditorCtrl extends PureCtrl {
data.previousNote
);
} else if (eventName === AppStateEvents.PreferencesChanged) {
this.loadPreferences();
this.reloadPreferences();
}
}
@@ -236,7 +240,7 @@ class EditorCtrl extends PureCtrl {
noteReady: true,
});
this.reloadTagsString();
this.loadPreferences();
this.reloadPreferences();
if (note.dummy) {
this.focusEditor();
@@ -748,7 +752,7 @@ class EditorCtrl extends PureCtrl {
PrefKeys.EditorWidth,
width
);
this.leftResizeControl.setWidth(width);
this.leftPanelPuppet.setWidth(width);
}
}
if (left !== undefined && left !== null) {
@@ -756,12 +760,12 @@ class EditorCtrl extends PureCtrl {
PrefKeys.EditorLeft,
left
);
this.rightResizeControl.setLeft(left);
this.rightPanelPuppet.setLeft(left);
}
this.preferencesManager.syncUserPreferences();
}
loadPreferences() {
reloadPreferences() {
const monospaceEnabled = this.preferencesManager.getValue(
PrefKeys.EditorMonospaceEnabled,
true
@@ -787,22 +791,26 @@ class EditorCtrl extends PureCtrl {
this.reloadFont();
if (this.state.marginResizersEnabled) {
if (
this.state.marginResizersEnabled &&
this.leftPanelPuppet.ready &&
this.rightPanelPuppet.ready
) {
const width = this.preferencesManager.getValue(
PrefKeys.EditorWidth,
null
);
if (width != null) {
this.leftResizeControl.setWidth(width);
this.rightResizeControl.setWidth(width);
this.leftPanelPuppet.setWidth(width);
this.rightPanelPuppet.setWidth(width);
}
const left = this.preferencesManager.getValue(
PrefKeys.EditorLeft,
null
);
if (left != null) {
this.leftResizeControl.setLeft(left);
this.rightResizeControl.setLeft(left);
this.leftPanelPuppet.setLeft(left);
this.rightPanelPuppet.setLeft(left);
}
}
}
@@ -845,8 +853,8 @@ class EditorCtrl extends PureCtrl {
this.reloadFont();
} else if (key === PrefKeys.EditorResizersEnabled && this[key] === true) {
this.$timeout(() => {
this.leftResizeControl.flash();
this.rightResizeControl.flash();
this.leftPanelPuppet.flash();
this.rightPanelPuppet.flash();
});
}
}

View File

@@ -31,6 +31,9 @@ class FooterCtrl extends PureCtrl {
this.nativeExtManager = nativeExtManager;
this.statusManager = statusManager;
this.godService = godService;
this.state = {
hasPasscode: false
};
this.rooms = [];
this.themesWithIcons = [];
@@ -46,7 +49,9 @@ class FooterCtrl extends PureCtrl {
application.onUnlock(() => {
this.application.hasPasscode().then((value) => {
this.hasPasscode = value;
this.setState({
hasPasscode: value
});
});
this.godService.checkForSecurityUpdate().then((available) => {
@@ -234,7 +239,7 @@ class FooterCtrl extends PureCtrl {
}
lockApp() {
this.$rootScope.lockApplication();
this.application.lock();
}
refreshData() {

View File

@@ -63,7 +63,9 @@ class NotesCtrl extends PureCtrl {
noteFilter: { text: '' },
};
this.panelController = {};
this.panelPuppet = {
onReady: () => this.reloadPreferences()
};
window.onresize = (event) => {
this.resetPagination({
keepCurrentIfLarger: true
@@ -309,12 +311,12 @@ class NotesCtrl extends PureCtrl {
const width = this.preferencesManager.getValue(
PrefKeys.NotesPanelWidth
);
if (width) {
this.panelController.setWidth(width);
if (this.panelController.isCollapsed()) {
if (width && this.panelPuppet.ready) {
this.panelPuppet.setWidth(width);
if (this.panelPuppet.isCollapsed()) {
this.appState.panelDidResize({
name: PANEL_NAME_NOTES,
collapsed: this.panelController.isCollapsed()
collapsed: this.panelPuppet.isCollapsed()
});
}
}

View File

@@ -1,4 +1,4 @@
import { Challenges, ChallengeResponse } from 'snjs';
import { Challenges, ChallengeResponse, ApplicationEvents } from 'snjs';
import { getPlatformString } from '@/utils';
import template from '%/root.pug';
import { AppStateEvents } from '@/state';
@@ -7,9 +7,9 @@ import {
PANEL_NAME_TAGS
} from '@/controllers/constants';
import {
STRING_SESSION_EXPIRED,
// STRING_SESSION_EXPIRED,
STRING_DEFAULT_FILE_ERROR,
StringSyncException
// StringSyncException
} from '@/strings';
import { PureCtrl } from './abstract/pure_ctrl';
@@ -86,16 +86,22 @@ class RootCtrl extends PureCtrl {
}
});
await this.application.launch();
this.setState({ needsUnlock: false });
this.application.componentManager.setDesktopManager(this.desktopManager);
this.application.registerService(this.themeManager);
// this.addSyncStatusObserver();
// this.addSyncEventHandler();
}
onUpdateAvailable() {
this.$rootScope.$broadcast('new-update-available');
};
/** @override */
async onApplicationEvent(eventName) {
if (eventName === ApplicationEvents.ApplicationUnlocked) {
this.setState({ needsUnlock: false });
this.application.componentManager.setDesktopManager(this.desktopManager);
this.application.registerService(this.themeManager);
}
}
/** @override */
async onAppStateEvent(eventName, data) {

View File

@@ -19,14 +19,21 @@ class TagsPanelCtrl extends PureCtrl {
super($scope, $timeout, application, appState);
this.$rootScope = $rootScope;
this.preferencesManager = preferencesManager;
this.panelController = {};
this.loadPreferences();
this.registerComponentHandler();
this.panelPuppet = {
onReady: () => this.loadPreferences()
};
this.state = {
smartTags: [],
noteCounts: {}
};
application.onUnlock(() => {
}
$onInit() {
this.application.onStart(() => {
this.registerComponentHandler();
});
this.application.onUnlock(() => {
this.loadPreferences();
this.beginStreamingItems();
const smartTags = this.application.getSmartTags();
this.setState({
@@ -34,8 +41,8 @@ class TagsPanelCtrl extends PureCtrl {
});
this.selectTag(smartTags[0]);
});
application.onSync(() => {
this.application.onSync(() => {
this.reloadNoteCounts();
});
}
@@ -94,13 +101,16 @@ class TagsPanelCtrl extends PureCtrl {
}
loadPreferences() {
if(!this.panelPuppet.ready) {
return;
}
const width = this.preferencesManager.getValue(PrefKeys.TagsPanelWidth);
if (width) {
this.panelController.setWidth(width);
if (this.panelController.isCollapsed()) {
this.panelPuppet.setWidth(width);
if (this.panelPuppet.isCollapsed()) {
this.appState.panelDidResize({
name: PANEL_NAME_TAGS,
collapsed: this.panelController.isCollapsed()
collapsed: this.panelPuppet.isCollapsed()
});
}
}