@netless/app-slide 0.3.0-canary.12 → 0.3.0-canary.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/connect.d.ts +4 -2
- package/dist/main.iife.js +2 -2
- package/dist/main.iife.js.map +1 -1
- package/dist/main.js +2 -2
- package/dist/main.js.map +1 -1
- package/dist/main.mjs +156 -156
- package/dist/main.mjs.map +1 -1
- package/package.json +2 -2
- package/src/connect.ts +12 -10
- package/src/index.ts +6 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@netless/app-slide",
|
|
3
|
-
"version": "0.3.0-canary.
|
|
3
|
+
"version": "0.3.0-canary.13",
|
|
4
4
|
"main": "dist/main.js",
|
|
5
5
|
"module": "dist/main.mjs",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"README-zh.md"
|
|
11
11
|
],
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@netless/slide": "^0.7.
|
|
13
|
+
"@netless/slide": "^0.7.4"
|
|
14
14
|
},
|
|
15
15
|
"devDependencies": {
|
|
16
16
|
"@types/color-string": "^1.5.2",
|
package/src/connect.ts
CHANGED
|
@@ -1,17 +1,19 @@
|
|
|
1
|
-
import type { AppContext, WhiteBoardView } from "@netless/window-manager";
|
|
1
|
+
import type { AppContext, Storage, WhiteBoardView } from "@netless/window-manager";
|
|
2
2
|
import type { SideEffectManager } from "side-effect-manager";
|
|
3
3
|
import type { SlideViewer } from "./SlideViewer";
|
|
4
|
+
import type { Attributes } from "./typings";
|
|
4
5
|
|
|
5
6
|
import { get } from "./utils";
|
|
6
7
|
|
|
7
8
|
export interface ConnectParams {
|
|
8
9
|
context: AppContext;
|
|
10
|
+
storage: Storage<Attributes>;
|
|
9
11
|
viewer: SlideViewer;
|
|
10
12
|
sideEffect: SideEffectManager;
|
|
11
13
|
logger: { info: (msg: string) => void };
|
|
12
14
|
}
|
|
13
15
|
|
|
14
|
-
export function connect({ context, viewer, sideEffect, logger }: ConnectParams) {
|
|
16
|
+
export function connect({ context, storage, viewer, sideEffect, logger }: ConnectParams) {
|
|
15
17
|
const log = logger.info.bind(logger);
|
|
16
18
|
|
|
17
19
|
let whiteboard: WhiteBoardView | null = null;
|
|
@@ -26,14 +28,14 @@ export function connect({ context, viewer, sideEffect, logger }: ConnectParams)
|
|
|
26
28
|
|
|
27
29
|
const { slide } = viewer;
|
|
28
30
|
|
|
29
|
-
function dump_state(state: unknown =
|
|
31
|
+
function dump_state(state: unknown = storage.state.state) {
|
|
30
32
|
return JSON.stringify(state);
|
|
31
33
|
}
|
|
32
34
|
|
|
33
35
|
function kick_start() {
|
|
34
|
-
if (
|
|
36
|
+
if (storage.state.state) {
|
|
35
37
|
log("[Slide] restore " + dump_state());
|
|
36
|
-
slide.setSlideState(
|
|
38
|
+
slide.setSlideState(storage.state.state);
|
|
37
39
|
} else if (context.isAddApp) {
|
|
38
40
|
log("[Slide] kick start");
|
|
39
41
|
slide.renderSlide(1);
|
|
@@ -41,7 +43,7 @@ export function connect({ context, viewer, sideEffect, logger }: ConnectParams)
|
|
|
41
43
|
log("[Slide] wait for restore");
|
|
42
44
|
const timeoutID = sideEffect.add(() => {
|
|
43
45
|
const timer = setInterval(() => {
|
|
44
|
-
if (!
|
|
46
|
+
if (!storage.state.state) {
|
|
45
47
|
log("[Slide] timeout");
|
|
46
48
|
slide.renderSlide(1);
|
|
47
49
|
}
|
|
@@ -49,10 +51,10 @@ export function connect({ context, viewer, sideEffect, logger }: ConnectParams)
|
|
|
49
51
|
return () => clearInterval(timer);
|
|
50
52
|
});
|
|
51
53
|
const disposerID = sideEffect.push(
|
|
52
|
-
|
|
53
|
-
if (
|
|
54
|
+
storage.on("stateChanged", () => {
|
|
55
|
+
if (storage.state.state) {
|
|
54
56
|
log("[Slide] restore " + dump_state());
|
|
55
|
-
slide.setSlideState(
|
|
57
|
+
slide.setSlideState(storage.state.state);
|
|
56
58
|
sideEffect.flush(disposerID);
|
|
57
59
|
sideEffect.flush(timeoutID);
|
|
58
60
|
}
|
|
@@ -65,7 +67,7 @@ export function connect({ context, viewer, sideEffect, logger }: ConnectParams)
|
|
|
65
67
|
slide.on("stateChange", () => {
|
|
66
68
|
if (context.isWritable) {
|
|
67
69
|
// log("[Slide] save state " + dump_state(slide.slideState));
|
|
68
|
-
|
|
70
|
+
storage.setState({ state: slide.slideState });
|
|
69
71
|
}
|
|
70
72
|
});
|
|
71
73
|
slide.on("syncDispatch", payload => {
|
package/src/index.ts
CHANGED
|
@@ -30,10 +30,12 @@ const SlideApp: NetlessApp<Attributes, MagixEvents, AppOptions, void> = {
|
|
|
30
30
|
const logger = new Logger(context);
|
|
31
31
|
logger.info("[Slide] setup @ " + __APP_VERSION__);
|
|
32
32
|
|
|
33
|
-
if (!context.
|
|
33
|
+
if (!context.attributes.taskId) {
|
|
34
34
|
throw new Error("[Slide] no taskId");
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
+
const storage = context.createStorage("slide", context.attributes);
|
|
38
|
+
|
|
37
39
|
const appOptions = context.getAppOptions() || {};
|
|
38
40
|
const renderOptions = appOptions.renderOptions || {};
|
|
39
41
|
|
|
@@ -61,8 +63,8 @@ const SlideApp: NetlessApp<Attributes, MagixEvents, AppOptions, void> = {
|
|
|
61
63
|
loaderDelegate: appOptions.loaderDelegate,
|
|
62
64
|
navigatorDelegate: appOptions.navigatorDelegate,
|
|
63
65
|
fixedFrameSize: appOptions.fixedFrameSize,
|
|
64
|
-
taskId:
|
|
65
|
-
url:
|
|
66
|
+
taskId: storage.state.taskId,
|
|
67
|
+
url: storage.state.url,
|
|
66
68
|
});
|
|
67
69
|
|
|
68
70
|
// For debugging.
|
|
@@ -97,7 +99,7 @@ const SlideApp: NetlessApp<Attributes, MagixEvents, AppOptions, void> = {
|
|
|
97
99
|
sideEffect.push(() => viewer.destroy());
|
|
98
100
|
|
|
99
101
|
// Connect UI with Netless App
|
|
100
|
-
connect({ context, viewer, sideEffect, logger });
|
|
102
|
+
connect({ context, storage, viewer, sideEffect, logger });
|
|
101
103
|
|
|
102
104
|
context.emitter.on("destroy", () => {
|
|
103
105
|
logger.info("[Slide] destroy");
|