-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
60 lines (47 loc) · 2.05 KB
/
main.js
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
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
import { dotnet } from './dotnet.js'
import { environment } from './environment.js'
const is_browser = typeof window != "undefined";
if (!is_browser) throw new Error(`Expected to be running in a browser`);
const dotnetRuntime = await dotnet
.withDiagnosticTracing(false)
.withApplicationArgumentsFromQuery()
.create();
const config = dotnetRuntime.getConfig();
let latestPaste = undefined;
if (navigator.userAgent.indexOf("Firefox") != -1) {
window.addEventListener("paste", e => { latestPaste = e.clipboardData.getData("text"); alert(latestPaste); });
}
const exports = await dotnetRuntime.getAssemblyExports(config.mainAssemblyName);
window.addEventListener('beforeunload', (event) => {
console.log("beforeUnload")
exports.InPixioLabs.Web.Interop.Save.SaveSettings();
});
const terminationEvent = 'onpagehide' in self ? 'pagehide' : 'unload';
console.log(terminationEvent)
window.addEventListener(terminationEvent, (event) => {
console.log("terminationEvent")
exports.InPixioLabs.Web.Interop.Save.SaveSettings();
});
/*
let latestPaste = undefined;
globalThis.addEventListener("paste", (e) => latestPaste = (e.clipboardData || window.clipboardData).getData("text"));
function getCpText(e) {
e.preventDefault();
latestPaste = (e.clipboardData || window.clipboardData).getData("text");
console.log("pasted text:");
console.log(latestPaste);
//var pastedText = undefined;
//if (window.clipboardData && window.clipboardData.getData) {
// pastedText = window.clipboardData.getData('Text');
//}
//else if (e.clipboardData && e.clipboardData.getData) {
// pastedText = e.clipboardData.getData('text/plain');
//}
//unityInstance.SendMessage(gameObjectName, voidName, pastedText);
}
if (navigator.userAgent.indexOf("Firefox") != -1) {
document.onpaste = getCpText;
}*/
await dotnetRuntime.runMainAndExit(config.mainAssemblyName, [`Environment=${environment}`]);