|
@@ -135,6 +135,10 @@ export function Snapshots(ctx: PluginContext) {
|
|
PluginCommands.State.Snapshots.Apply.subscribe(ctx, ({ id }) => {
|
|
PluginCommands.State.Snapshots.Apply.subscribe(ctx, ({ id }) => {
|
|
const snapshot = ctx.state.snapshots.setCurrent(id);
|
|
const snapshot = ctx.state.snapshots.setCurrent(id);
|
|
if (!snapshot) return;
|
|
if (!snapshot) return;
|
|
|
|
+ return PluginCommands.State.Snapshots.Set.dispatch(ctx, { snapshot });
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ PluginCommands.State.Snapshots.Set.subscribe(ctx, ({ snapshot }) => {
|
|
return ctx.state.setSnapshot(snapshot);
|
|
return ctx.state.setSnapshot(snapshot);
|
|
});
|
|
});
|
|
|
|
|
|
@@ -150,9 +154,9 @@ export function Snapshots(ctx: PluginContext) {
|
|
|
|
|
|
PluginCommands.State.Snapshots.Fetch.subscribe(ctx, async ({ url }) => {
|
|
PluginCommands.State.Snapshots.Fetch.subscribe(ctx, async ({ url }) => {
|
|
const json = await ctx.runTask(ctx.fetch({ url, type: 'json' })); // fetch(url, { referrer: 'no-referrer' });
|
|
const json = await ctx.runTask(ctx.fetch({ url, type: 'json' })); // fetch(url, { referrer: 'no-referrer' });
|
|
- const current = ctx.state.snapshots.setRemoteSnapshot(json.data);
|
|
|
|
- if (!current) return;
|
|
|
|
- return ctx.state.setSnapshot(current);
|
|
|
|
|
|
+ const snapshot = ctx.state.snapshots.setRemoteSnapshot(json.data);
|
|
|
|
+ if (!snapshot) return;
|
|
|
|
+ return PluginCommands.State.Snapshots.Set.dispatch(ctx, { snapshot });
|
|
});
|
|
});
|
|
|
|
|
|
PluginCommands.State.Snapshots.DownloadToFile.subscribe(ctx, ({ name }) => {
|
|
PluginCommands.State.Snapshots.DownloadToFile.subscribe(ctx, ({ name }) => {
|
|
@@ -169,8 +173,8 @@ export function Snapshots(ctx: PluginContext) {
|
|
PluginCommands.State.Snapshots.OpenFile.subscribe(ctx, async ({ file }) => {
|
|
PluginCommands.State.Snapshots.OpenFile.subscribe(ctx, async ({ file }) => {
|
|
try {
|
|
try {
|
|
const data = await readFromFile(file, 'string').run();
|
|
const data = await readFromFile(file, 'string').run();
|
|
- const json = JSON.parse(data as string);
|
|
|
|
- await ctx.state.setSnapshot(json);
|
|
|
|
|
|
+ const snapshot = JSON.parse(data as string);
|
|
|
|
+ return PluginCommands.State.Snapshots.Set.dispatch(ctx, { snapshot });
|
|
} catch (e) {
|
|
} catch (e) {
|
|
ctx.log.error(`Reading JSON state: ${e}`);
|
|
ctx.log.error(`Reading JSON state: ${e}`);
|
|
}
|
|
}
|