From 54fb9beeee680373463603b66a90be23af110dce Mon Sep 17 00:00:00 2001 From: Alexander Rose <alexander.rose@weirdbyte.de> Date: Mon, 27 Apr 2020 19:31:55 -0700 Subject: [PATCH] add State.Snapshots.OpenUrl --- src/mol-plugin/behavior/static/state.ts | 5 +++++ src/mol-plugin/commands.ts | 3 ++- src/mol-plugin/state.ts | 2 ++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/mol-plugin/behavior/static/state.ts b/src/mol-plugin/behavior/static/state.ts index d2faaebef..fad738a73 100644 --- a/src/mol-plugin/behavior/static/state.ts +++ b/src/mol-plugin/behavior/static/state.ts @@ -187,4 +187,9 @@ export function Snapshots(ctx: PluginContext) { PluginCommands.State.Snapshots.OpenFile.subscribe(ctx, ({ file }) => { return ctx.managers.snapshot.open(file); }); + + PluginCommands.State.Snapshots.OpenUrl.subscribe(ctx, async ({ url, type }) => { + const data = await ctx.runTask(ctx.fetch({ url, type: 'binary' })); + return ctx.managers.snapshot.open(new File([data], `state.${type}`)); + }); } \ No newline at end of file diff --git a/src/mol-plugin/commands.ts b/src/mol-plugin/commands.ts index 6f111ebeb..e2921b6ce 100644 --- a/src/mol-plugin/commands.ts +++ b/src/mol-plugin/commands.ts @@ -37,8 +37,9 @@ export const PluginCommands = { Upload: PluginCommand<{ name?: string, description?: string, playOnLoad?: boolean, serverUrl: string, params?: PluginState.SnapshotParams }>(), Fetch: PluginCommand<{ url: string }>(), - DownloadToFile: PluginCommand<{ name?: string, type: 'json' | 'molj' | 'zip' | 'molx', params?: PluginState.SnapshotParams }>(), + DownloadToFile: PluginCommand<{ name?: string, type: PluginState.SnapshotType, params?: PluginState.SnapshotParams }>(), OpenFile: PluginCommand<{ file: File }>(), + OpenUrl: PluginCommand<{ url: string, type: PluginState.SnapshotType }>(), } }, Interactivity: { diff --git a/src/mol-plugin/state.ts b/src/mol-plugin/state.ts index 9c7d3af70..7e9cd2007 100644 --- a/src/mol-plugin/state.ts +++ b/src/mol-plugin/state.ts @@ -166,4 +166,6 @@ namespace PluginState { structureFocus?: StructureFocusSnapshot, durationInMs?: number } + + export type SnapshotType = 'json' | 'molj' | 'zip' | 'molx' } -- GitLab