Updates
This commit is contained in:
@@ -158,68 +158,4 @@ angular.module('app.frontend')
|
|||||||
room.showRoom = true;
|
room.showRoom = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let extensionsIdentifier = "org.standardnotes.extensions-manager";
|
|
||||||
|
|
||||||
// Handle singleton ProLink instance
|
|
||||||
singletonManager.registerSingleton({content_type: "SN|Component", package_info: {identifier: extensionsIdentifier}}, (resolvedSingleton) => {
|
|
||||||
// Resolved Singleton
|
|
||||||
console.log("Resolved extensions-manager", resolvedSingleton);
|
|
||||||
var needsSync = false;
|
|
||||||
if(isDesktopApplication()) {
|
|
||||||
if(!resolvedSingleton.local_url) {
|
|
||||||
resolvedSingleton.local_url = window._extensions_manager_location;
|
|
||||||
needsSync = true;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if(!resolvedSingleton.hosted_url) {
|
|
||||||
resolvedSingleton.hosted_url = window._extensions_manager_location;
|
|
||||||
needsSync = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(needsSync) {
|
|
||||||
resolvedSingleton.setDirty(true);
|
|
||||||
syncManager.sync();
|
|
||||||
}
|
|
||||||
}, (valueCallback) => {
|
|
||||||
// Safe to create. Create and return object.
|
|
||||||
let url = window._extensions_manager_location;
|
|
||||||
console.log("Installing Extensions Manager from URL", url);
|
|
||||||
if(!url) {
|
|
||||||
console.error("window._extensions_manager_location must be set.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var item = {
|
|
||||||
content_type: "SN|Component",
|
|
||||||
content: {
|
|
||||||
name: "Extensions",
|
|
||||||
area: "rooms",
|
|
||||||
package_info: {
|
|
||||||
identifier: extensionsIdentifier
|
|
||||||
},
|
|
||||||
permissions: [
|
|
||||||
{
|
|
||||||
name: "stream-items",
|
|
||||||
content_types: ["SN|Component", "SN|Theme", "SF|Extension", "Extension", "SF|MFA"]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(isDesktopApplication()) {
|
|
||||||
item.content.local_url = window._extensions_manager_location;
|
|
||||||
} else {
|
|
||||||
item.content.hosted_url = window._extensions_manager_location;
|
|
||||||
}
|
|
||||||
|
|
||||||
var component = modelManager.createItem(item);
|
|
||||||
modelManager.addItem(component);
|
|
||||||
|
|
||||||
component.setDirty(true);
|
|
||||||
syncManager.sync();
|
|
||||||
|
|
||||||
valueCallback(component);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -64,9 +64,9 @@ angular.module('app.frontend')
|
|||||||
|
|
||||||
syncManager.sync(null);
|
syncManager.sync(null);
|
||||||
// refresh every 30s
|
// refresh every 30s
|
||||||
setInterval(function () {
|
// setInterval(function () {
|
||||||
syncManager.sync(null);
|
// syncManager.sync(null);
|
||||||
}, 30000);
|
// }, 30000);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ let ClientDataDomain = "org.standardnotes.sn.components";
|
|||||||
|
|
||||||
class ComponentManager {
|
class ComponentManager {
|
||||||
|
|
||||||
constructor($rootScope, modelManager, syncManager, desktopManager, $timeout, $compile) {
|
constructor($rootScope, modelManager, syncManager, desktopManager, sysExtManager, $timeout, $compile) {
|
||||||
this.$compile = $compile;
|
this.$compile = $compile;
|
||||||
this.$rootScope = $rootScope;
|
this.$rootScope = $rootScope;
|
||||||
this.modelManager = modelManager;
|
this.modelManager = modelManager;
|
||||||
|
|||||||
@@ -243,7 +243,7 @@ class ModelManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
createDuplicateItem(itemResponse, sourceItem) {
|
createDuplicateItem(itemResponse, sourceItem) {
|
||||||
var dup = this.createItem(itemResponse);
|
var dup = this.createItem(itemResponse, true);
|
||||||
this.resolveReferencesForItem(dup);
|
this.resolveReferencesForItem(dup);
|
||||||
return dup;
|
return dup;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,11 +16,13 @@ class SingletonManager {
|
|||||||
this.singletonHandlers = [];
|
this.singletonHandlers = [];
|
||||||
|
|
||||||
$rootScope.$on("initial-data-loaded", (event, data) => {
|
$rootScope.$on("initial-data-loaded", (event, data) => {
|
||||||
this.resolveSingletons(modelManager.allItems, true);
|
this.resolveSingletons(modelManager.allItems, null, true);
|
||||||
})
|
})
|
||||||
|
|
||||||
$rootScope.$on("sync:completed", (event, data) => {
|
$rootScope.$on("sync:completed", (event, data) => {
|
||||||
this.resolveSingletons(data.retrievedItems || []);
|
// The reason we also need to consider savedItems in consolidating singletons is in case of sync conflicts,
|
||||||
|
// a new item can be created, but is never processed through "retrievedItems" since it is only created locally then saved.
|
||||||
|
this.resolveSingletons(data.retrievedItems, data.savedItems);
|
||||||
})
|
})
|
||||||
|
|
||||||
// Testing code to make sure only 1 exists
|
// Testing code to make sure only 1 exists
|
||||||
@@ -43,10 +45,12 @@ class SingletonManager {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
resolveSingletons(retrievedItems, initialLoad) {
|
resolveSingletons(retrievedItems, savedItems, initialLoad) {
|
||||||
|
retrievedItems = retrievedItems || [];
|
||||||
|
savedItems = savedItems || [];
|
||||||
for(let singletonHandler of this.singletonHandlers) {
|
for(let singletonHandler of this.singletonHandlers) {
|
||||||
var predicate = singletonHandler.predicate;
|
var predicate = singletonHandler.predicate;
|
||||||
var singletonItems = this.filterItemsWithPredicate(retrievedItems, predicate);
|
var singletonItems = this.filterItemsWithPredicate(_.uniq(retrievedItems.concat(savedItems)), predicate);
|
||||||
if(singletonItems.length > 0) {
|
if(singletonItems.length > 0) {
|
||||||
/*
|
/*
|
||||||
Check local inventory and make sure only 1 similar item exists. If more than 1, delete oldest
|
Check local inventory and make sure only 1 similar item exists. If more than 1, delete oldest
|
||||||
|
|||||||
@@ -248,6 +248,11 @@ class SyncManager {
|
|||||||
this.allRetreivedItems = [];
|
this.allRetreivedItems = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// We also want to do this for savedItems
|
||||||
|
if(!this.allSavedItems) {
|
||||||
|
this.allSavedItems = [];
|
||||||
|
}
|
||||||
|
|
||||||
var version = this.authManager.protocolVersion();
|
var version = this.authManager.protocolVersion();
|
||||||
var keys = this.authManager.keys();
|
var keys = this.authManager.keys();
|
||||||
|
|
||||||
@@ -288,6 +293,9 @@ class SyncManager {
|
|||||||
var saved =
|
var saved =
|
||||||
this.handleItemsResponse(response.saved_items, omitFields, ModelManager.MappingSourceRemoteSaved);
|
this.handleItemsResponse(response.saved_items, omitFields, ModelManager.MappingSourceRemoteSaved);
|
||||||
|
|
||||||
|
// Append items to master list of saved items for this ongoing sync operation
|
||||||
|
this.allSavedItems = this.allSavedItems.concat(saved);
|
||||||
|
|
||||||
// Create copies of items or alternate their uuids if neccessary
|
// Create copies of items or alternate their uuids if neccessary
|
||||||
var unsaved = response.unsaved;
|
var unsaved = response.unsaved;
|
||||||
this.handleUnsavedItemsResponse(unsaved)
|
this.handleUnsavedItemsResponse(unsaved)
|
||||||
@@ -327,9 +335,10 @@ class SyncManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.callQueuedCallbacksAndCurrent(callback, response);
|
this.callQueuedCallbacksAndCurrent(callback, response);
|
||||||
this.$rootScope.$broadcast("sync:completed", {retrievedItems: this.allRetreivedItems});
|
this.$rootScope.$broadcast("sync:completed", {retrievedItems: this.allRetreivedItems, savedItems: this.allSavedItems});
|
||||||
|
|
||||||
this.allRetreivedItems = [];
|
this.allRetreivedItems = [];
|
||||||
|
this.allSavedItems = [];
|
||||||
}
|
}
|
||||||
}.bind(this);
|
}.bind(this);
|
||||||
|
|
||||||
|
|||||||
83
app/assets/javascripts/app/services/sysExtManager.js
Normal file
83
app/assets/javascripts/app/services/sysExtManager.js
Normal file
@@ -0,0 +1,83 @@
|
|||||||
|
/* A class for handling installation of system extensions */
|
||||||
|
|
||||||
|
class SysExtManager {
|
||||||
|
|
||||||
|
constructor(modelManager, syncManager, singletonManager) {
|
||||||
|
this.modelManager = modelManager;
|
||||||
|
this.syncManager = syncManager;
|
||||||
|
this.singletonManager = singletonManager;
|
||||||
|
|
||||||
|
this.resolveExtensionsManager();
|
||||||
|
}
|
||||||
|
|
||||||
|
resolveExtensionsManager() {
|
||||||
|
let extensionsIdentifier = "org.standardnotes.extensions-manager";
|
||||||
|
|
||||||
|
this.singletonManager.registerSingleton({content_type: "SN|Component", package_info: {identifier: extensionsIdentifier}}, (resolvedSingleton) => {
|
||||||
|
// Resolved Singleton
|
||||||
|
console.log("Resolved extensions-manager", resolvedSingleton);
|
||||||
|
var needsSync = false;
|
||||||
|
if(isDesktopApplication()) {
|
||||||
|
if(!resolvedSingleton.local_url) {
|
||||||
|
resolvedSingleton.local_url = window._extensions_manager_location;
|
||||||
|
needsSync = true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if(!resolvedSingleton.hosted_url) {
|
||||||
|
resolvedSingleton.hosted_url = window._extensions_manager_location;
|
||||||
|
needsSync = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(needsSync) {
|
||||||
|
resolvedSingleton.setDirty(true);
|
||||||
|
this.syncManager.sync();
|
||||||
|
}
|
||||||
|
}, (valueCallback) => {
|
||||||
|
// Safe to create. Create and return object.
|
||||||
|
let url = window._extensions_manager_location;
|
||||||
|
console.log("Installing Extensions Manager from URL", url);
|
||||||
|
if(!url) {
|
||||||
|
console.error("window._extensions_manager_location must be set.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let packageInfo = {
|
||||||
|
name: "Extensions",
|
||||||
|
identifier: extensionsIdentifier
|
||||||
|
}
|
||||||
|
|
||||||
|
var item = {
|
||||||
|
content_type: "SN|Component",
|
||||||
|
content: {
|
||||||
|
name: packageInfo.name,
|
||||||
|
area: "rooms",
|
||||||
|
package_info: packageInfo,
|
||||||
|
permissions: [
|
||||||
|
{
|
||||||
|
name: "stream-items",
|
||||||
|
content_types: ["SN|Component", "SN|Theme", "SF|Extension", "Extension", "SF|MFA", "SN|Editor"]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(isDesktopApplication()) {
|
||||||
|
item.content.local_url = window._extensions_manager_location;
|
||||||
|
} else {
|
||||||
|
item.content.hosted_url = window._extensions_manager_location;
|
||||||
|
}
|
||||||
|
|
||||||
|
var component = this.modelManager.createItem(item);
|
||||||
|
this.modelManager.addItem(component);
|
||||||
|
|
||||||
|
component.setDirty(true);
|
||||||
|
this.syncManager.sync();
|
||||||
|
|
||||||
|
valueCallback(component);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
angular.module('app.frontend').service('sysExtManager', SysExtManager);
|
||||||
Reference in New Issue
Block a user