Skip to content
This repository has been archived by the owner on Mar 5, 2021. It is now read-only.

Commit

Permalink
Restore ability to use app while offline (i.e. when registry can't be…
Browse files Browse the repository at this point in the history
… downloaded), fixes #46
  • Loading branch information
elisee committed Aug 28, 2016
1 parent 1b404dd commit 5f08431
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 24 deletions.
2 changes: 2 additions & 0 deletions src/renderer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@ function installFirstSystem(callback: Function) {

function updateSystemsAndPlugins() {
serverSettingsSystems.getRegistry((registry) => {
if (registry == null) { localServer.start(); return; }

const systemsAndPlugins: string[] = [];
for (const systemId in registry.systems) {
const system = registry.systems[systemId];
Expand Down
55 changes: 32 additions & 23 deletions src/renderer/serverSettings/systems.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,31 +88,35 @@ function onRegistryReceived(event: any) {
return;
}

registry = event.registry;
const systemsById = registry.systems;

for (const systemId in systemsById) {
const system = systemsById[systemId];

const systemElt = html("li", { dataset: { id: systemId } });
html("div", "label", { parent: systemElt, textContent: systemId });
html("div", "progress", { parent: systemElt });
treeView.append(systemElt, "group");

for (const authorName in system.plugins) {
const plugins = system.plugins[authorName];

const authorElt = html("li");
html("div", "label", { parent: authorElt, textContent: `${authorName} (${Object.keys(plugins).length} plugins)` });
treeView.append(authorElt, "group", systemElt);

for (const pluginName in plugins) {
const pluginElt = html("li", { dataset: { id: `${systemId}:${authorName}/${pluginName}` } });
html("div", "label", { parent: pluginElt, textContent: pluginName });
html("div", "progress", { parent: pluginElt });
treeView.append(pluginElt, "item", authorElt);
if (event.error == null && event.registry != null) {
registry = event.registry;
const systemsById = registry.systems;

for (const systemId in systemsById) {
const system = systemsById[systemId];

const systemElt = html("li", { dataset: { id: systemId } });
html("div", "label", { parent: systemElt, textContent: systemId });
html("div", "progress", { parent: systemElt });
treeView.append(systemElt, "group");

for (const authorName in system.plugins) {
const plugins = system.plugins[authorName];

const authorElt = html("li");
html("div", "label", { parent: authorElt, textContent: `${authorName} (${Object.keys(plugins).length} plugins)` });
treeView.append(authorElt, "group", systemElt);

for (const pluginName in plugins) {
const pluginElt = html("li", { dataset: { id: `${systemId}:${authorName}/${pluginName}` } });
html("div", "label", { parent: pluginElt, textContent: pluginName });
html("div", "progress", { parent: pluginElt });
treeView.append(pluginElt, "item", authorElt);
}
}
}
} else {
registry = null;
}

for (const getRegistryCallback of getRegistryCallbacks) getRegistryCallback(registry);
Expand All @@ -122,6 +126,8 @@ function onRegistryReceived(event: any) {
type ActionItem = { systemId: string; authorName?: string; pluginName?: string };
export function action(command: string, item: ActionItem, callback?: (succeed: boolean) => void) {
getRegistry((registry) => {
if (registry == null) return;

const id = item.pluginName != null ? `${item.systemId}:${item.authorName}/${item.pluginName}` : item.systemId;

const progressElt = treeView.treeRoot.querySelector(`li[data-id="${id}"] .progress`) as HTMLDivElement;
Expand All @@ -146,6 +152,7 @@ export function action(command: string, item: ActionItem, callback?: (succeed: b

progressElt.textContent = `${event.value}%`;
});

process.on("exit", (statusCode: number) => {
progressElt.textContent = "";
delete serverProcessById[id];
Expand Down Expand Up @@ -173,6 +180,8 @@ export function action(command: string, item: ActionItem, callback?: (succeed: b

export function updateAll(callback?: Function) {
getRegistry((registry) => {
if (registry == null) return;

async.each(Object.keys(registry.systems), (systemId, cb) => {
const system = registry.systems[systemId];
async.parallel([
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/updateManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ function firstCoreInstall(callback: (error: Error) => void) {

function updateCore(callback: (error: Error) => void) {
systemServerSettings.getRegistry((registry) => {
if (registry.core.isLocalDev || registry.core.version === registry.core.localVersion) { callback(null); return; }
if (registry == null || registry.core.isLocalDev || registry.core.version === registry.core.localVersion) { callback(null); return; }

const label = i18n.t("startup:updateAvailable.core", { latest: registry.core.version, current: registry.core.localVersion });
const options = {
Expand Down

0 comments on commit 5f08431

Please sign in to comment.