49 lines
1.2 KiB
JavaScript
49 lines
1.2 KiB
JavaScript
var cef = null;
|
|
// Browser Class
|
|
class Browser {
|
|
constructor(resourcePath) {
|
|
this.path = resourcePath;
|
|
this.open = false;
|
|
}
|
|
show() {
|
|
if (this.open == false) {
|
|
this.open = true;
|
|
var resolution = API.getScreenResolution();
|
|
this.browser = API.createCefBrowser(resolution.Width, resolution.Height, true);
|
|
API.waitUntilCefBrowserInit(this.browser);
|
|
API.setCefBrowserPosition(this.browser, 0, 0);
|
|
API.loadPageCefBrowser(this.browser, this.path);
|
|
API.showCursor(true);
|
|
API.setCanOpenChat(false);
|
|
}
|
|
}
|
|
destroy() {
|
|
this.open = false;
|
|
API.destroyCefBrowser(this.browser);
|
|
API.showCursor(false);
|
|
API.setCanOpenChat(true);
|
|
}
|
|
eval(string) {
|
|
this.browser.eval(string);
|
|
}
|
|
}
|
|
// Destroy the browser if the resource stops.
|
|
API.onResourceStop.connect(function () {
|
|
killBrowser();
|
|
});
|
|
// Create the browser.
|
|
function createBrowser(path) {
|
|
if (cef !== null) {
|
|
return;
|
|
}
|
|
cef = new Browser(path);
|
|
cef.show();
|
|
}
|
|
// Destroy the browser.
|
|
function killBrowser() {
|
|
if (cef === null) {
|
|
return;
|
|
}
|
|
cef.destroy();
|
|
cef = null;
|
|
}
|