-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
195 lines (176 loc) · 5.72 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
<html>
<head>
<title>Main Window</title>
</head>
<style>
body {
font-family: Arial, Helvetica, sans-serif;
}
</style>
<script type="application/javascript">
window.addEventListener("DOMContentLoaded", event => {
const storageKey = "platform-messaging-sample-snapshot";
const storageKeyWindowSelect =
"platform-messaging-sample-snapshot-window-select";
const storageKeySnapShotApplied =
"platform-messaging-sample-snapshot-applied";
const send = document.getElementById("send-message");
const save = document.getElementById("save");
const apply = document.getElementById("apply");
const launchWindowOne = document.getElementById("launch-window-one");
const launchViewOne = document.getElementById("launch-view-one");
const windowSelect = document.getElementById("launched-windows-select");
const platform = fin.Platform.getCurrentSync();
let rootUrl = location.href.replace(location.pathname,'');
rootUrl = rootUrl.replace('#','');
function setup() {
let storedSelect = localStorage.getItem(storageKeyWindowSelect);
let snapShotApplied = localStorage.getItem(storageKeySnapShotApplied);
if (snapShotApplied) {
localStorage.removeItem(storageKeySnapShotApplied);
if (
storedSelect !== undefined &&
storedSelect !== null &&
storedSelect !== ""
) {
let selectOptions = JSON.parse(storedSelect);
selectOptions.forEach(entry => {
updateWindowSelect(entry);
});
}
}
}
function updateWindowSelect(name) {
windowSelect.options[windowSelect.options.length] = new Option(
name,
name
);
if (send.disabled) {
send.disabled = false;
}
if (save.disabled) {
save.disabled = false;
}
}
async function launchView(name) {
let viewName = "view-" + name + "-" + Date.now();
let url = rootUrl +
"/platform-messaging/views/view-" +
name +
".html";
console.log("Adding Window with View " + viewName + " is created");
updateWindowSelect(viewName);
const platform = fin.Platform.getCurrentSync();
await platform.createView({
url: url,
name: viewName
});
}
function launchWindow(name) {
let windowName = "window-" + name + "-" + Date.now();
async function createWindow() {
let url = rootUrl +
"/platform-messaging/windows/window-" +
name +
".html";
return fin.Platform.getCurrentSync().applySnapshot({
windows: [
{
defaultWidth: 300,
defaultHeight: 300,
defaultLeft: 200,
defaultTop: 200,
name: windowName,
saveWindowState: false,
url: url,
contextMenu: true
}
]
});
}
createWindow()
.then(() => {
console.log("Window " + windowName + " is created");
updateWindowSelect(windowName);
})
.catch(err => console.log(err));
}
send.onclick = () => {
if (windowSelect.options.length > 0) {
let name = windowSelect.options[windowSelect.selectedIndex].value;
let identity = { uuid: fin.me.identity.uuid, name: name };
console.log("Sending message to: " + JSON.stringify(identity));
fin.InterApplicationBus.send(
identity,
"sample-topic",
"From Main Window: " + Date.now()
)
.then(() => console.log("Message sent"))
.catch(err => console.log(err));
}
};
save.onclick = async () => {
let snapShot = await platform.getSnapshot();
localStorage.setItem(storageKey, JSON.stringify(snapShot));
apply.disabled = false;
let optionKeys = Object.keys(windowSelect.options);
let names = [];
optionKeys.forEach(key => {
names.push(windowSelect.options[key].value);
});
localStorage.setItem(storageKeyWindowSelect, JSON.stringify(names));
};
apply.onclick = async () => {
let storedSnapShot = localStorage.getItem(storageKey);
if (
storedSnapShot !== undefined &&
storedSnapShot !== null &&
storedSnapShot !== ""
) {
let snapShot = JSON.parse(storedSnapShot);
localStorage.setItem(storageKeySnapShotApplied, true);
await platform.applySnapshot(snapShot, {
closeExistingWindows: true
});
}
};
launchWindowOne.onclick = event => {
event.preventDefault();
launchWindow("one");
};
launchViewOne.onclick = async event => {
event.preventDefault();
launchView("one");
};
setup();
});
</script>
<body>
<h1>
Main Window
</h1>
<div>
<ul>
<li>
<a title="Launch Window One" href="#" id="launch-window-one"
>Launch Window One</a
>
</li>
<li>
<a title="Launch Window With View" href="#" id="launch-view-one"
>Launch Window With View</a
>
</li>
</ul>
</div>
<h4>Message Launched Window/View:</h4>
<div>
<select id="launched-windows-select"></select>
<button id="send-message" disabled>Send Message</button>
</div>
<div>
<button id="save" disabled>Save SnapShot</button>
<button id="apply" disabled>Apply SnapShot</button>
</div>
</body>
</html>