-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
152 lines (131 loc) · 3.76 KB
/
app.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
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
const { ipcMain } = require("electron");
const log = require("electron-log");
const path = require("path");
var net = 'core';
var framework = net.charAt(0).toUpperCase() + net.substr(1);
log.info("framework: " + framework);
process.env.EDGE_USE_CORECLR = 1;
log.info("EDGE_USE_CORECLR: " + process.env.EDGE_USE_CORECLR);
try {
log.info(module.paths);
let baseNetAppPath = path.join(__dirname, '/src/QuickStart.Core/bin/Debug/net8.0');
//let baseNetAppPath = path.join(__dirname, '/src/QuickStart.Core/bin/Release/net8.0/win-x64/publish');
if (__dirname.indexOf("app.asar") !== -1) {
baseNetAppPath = path.join(process.resourcesPath,"net8.0");
}
process.env.EDGE_APP_ROOT = baseNetAppPath;
var edge = require("electron-edge-js");
log.info("baseNetAppPath: " + baseNetAppPath);
var baseDll = path.join(baseNetAppPath, "QuickStart.Core.dll");
var localTypeName = "QuickStart.LocalMethods";
var externalTypeName = "QuickStart.ExternalMethods";
var getAppDomainDirectory = edge.func({
assemblyFile: baseDll,
typeName: localTypeName,
methodName: "GetAppDomainDirectory",
});
var getCurrentTime = edge.func({
assemblyFile: baseDll,
typeName: localTypeName,
methodName: "GetCurrentTime",
});
var useDynamicInput = edge.func({
assemblyFile: baseDll,
typeName: localTypeName,
methodName: "UseDynamicInput",
});
var getPerson = edge.func({
assemblyFile: baseDll,
typeName: externalTypeName,
methodName: "GetPersonInfo",
});
var handleException = edge.func({
assemblyFile: baseDll,
typeName: localTypeName,
methodName: "ThrowException",
});
var getInlinePerson = edge.func({
source: function () {
/*
using System.Threading.Tasks;
using System;
public class Person
{
public Person(string name, string email, int age)
{
Id = Guid.NewGuid();
Name = name;
Email = email;
Age = age;
}
public Guid Id {get;}
public string Name {get;set;}
public string Email {get;set;}
public int Age {get;set;}
}
public class Startup
{
public async Task<object> Invoke(dynamic input)
{
return new Person(input.name, input.email, input.age);
}
}
*/
},
});
} catch (e) {
log.error(e);
process.exit(1);
}
exports.run = function (window) {
getInlinePerson(
{
name: "Peter Smith",
email: "peter.smith@electron-edge-js-quick-start.com",
age: 30,
},
function (error, result) {
if (error) throw error;
window.webContents.send(
"fromMain",
"getItem",
JSON.stringify(result, null, 2)
);
}
);
getAppDomainDirectory("", function (error, result) {
if (error) throw error;
window.webContents.send("fromMain", "getAppDomainDirectory", result);
});
getCurrentTime("", function (error, result) {
if (error) throw error;
window.webContents.send("fromMain", "getCurrentTime", result);
});
useDynamicInput(
{ framework: framework, node: "Node.Js" },
function (error, result) {
if (error) throw error;
window.webContents.send("fromMain", "useDynamicInput", result);
}
);
try {
handleException("", function (error, result) {});
} catch (e) {
window.webContents.send("fromMain", "handleException", e.Message);
}
getPerson(
{
name: "John Smith",
email: "john.smith@electron-edge-js-quick-start.com",
age: 35,
},
function (error, result) {
if (error) throw error;
window.webContents.send(
"fromMain",
"getPerson",
JSON.stringify(result, null, 2)
);
}
);
};