4
1
mirror of https://github.com/Qortal/qortal-ui.git synced 2025-02-11 17:55:51 +00:00

Added start core function from nodemanagement

This commit is contained in:
AlphaX-Projects 2024-01-03 16:47:53 +01:00
parent 1697adeafe
commit 6123f5eb36
4 changed files with 118 additions and 26 deletions

View File

@ -999,7 +999,9 @@
"nchange31": "Stop Node",
"nchange32": "Successfully Sent Stop Request!",
"nchange33": "Restart Node",
"nchange34": "Successfully Sent Restart Request!"
"nchange34": "Successfully Sent Restart Request!",
"nchange35": "Start Node",
"nchange36": "Successfully Started Node!"
},
"transpage": {
"tchange1": "Transaction request",

View File

@ -207,6 +207,70 @@ async function checkWin() {
}
}
async function checkOsPlatform() {
if (process.platform === 'win32') {
startElectronWin()
} else if (process.platform === 'linux' || process.platform === 'darwin') {
startElectronUnix()
} else {
return
}
}
async function startElectronWin() {
if (fs.existsSync(winjar)) {
isRunning('qortal.exe', (status) => {
if (status == true) {
log.info("Core is running, perfect !")
} else {
spawn(startWinCore, { detached: true })
}
})
} else {
const dialogOpts = {
type: 'info',
buttons: [i18n.__("electron_translate_18"), i18n.__("electron_translate_19")],
title: i18n.__("electron_translate_20"),
message: i18n.__("electron_translate_21"),
detail: i18n.__("electron_translate_22")
}
dialog.showMessageBox(dialogOpts).then((returnValue) => {
if (returnValue.response === 0) {
downloadWindows()
} else {
return
}
})
}
}
function startElectronUnix() {
if (fs.existsSync(qortaljar)) {
isRunning('qortal.jar', (status) => {
if (status == true) {
log.info("Core is running, perfect !")
} else {
startQortal()
}
})
} else {
const dialogOpts = {
type: 'info',
buttons: [i18n.__("electron_translate_18"), i18n.__("electron_translate_19")],
title: i18n.__("electron_translate_20"),
message: i18n.__("electron_translate_21"),
detail: i18n.__("electron_translate_22")
}
dialog.showMessageBox(dialogOpts).then((returnValue) => {
if (returnValue.response === 0) {
downloadQortal()
} else {
return
}
})
}
}
async function downloadWindows() {
let winLoader = new BrowserWindow({
width: 500,
@ -1085,6 +1149,9 @@ if (!isLock) {
check.show()
autoUpdater.checkForUpdatesAndNotify()
})
ipcMain.on('start-core-electron', (event) => {
checkOsPlatform()
})
ipcMain.on('show-my-menu', (event) => {
let homePageOptions = Menu.buildFromTemplate([
{

View File

@ -2,6 +2,7 @@ const { contextBridge, ipcRenderer, webFrame } = require('electron')
contextBridge.exposeInMainWorld('electronAPI', {
setStartCore: () => ipcRenderer.send('set-start-core'),
startCore: () => ipcRenderer.send('start-core-electron'),
checkForUpdate: () => ipcRenderer.send('check-for-update'),
showMyMenu: () => ipcRenderer.send('show-my-menu'),
focusApp: () => ipcRenderer.send('focus-app'),

View File

@ -77,6 +77,10 @@ class NodeManagement extends LitElement {
--mdc-theme-primary: #F44336;
}
.green {
--mdc-theme-primary: #198754;
}
.red-button {
--mdc-theme-primary: red;
--mdc-theme-on-primary: white;
@ -151,8 +155,8 @@ class NodeManagement extends LitElement {
<div class="node-card">
<h2>${translate("nodepage.nchange1")} ${this.nodeDomain}</h2>
<mwc-button style="float:right;" ?hidden="${(this.upTime === "offline")}" @click=${() => this.bootstrap()}><mwc-icon>restart_alt</mwc-icon>&nbsp;${translate("tour.tour18")}</mwc-button>
<mwc-button style="float:right;" class="red" ?hidden="${(this.upTime === "offline")}" @click=${() => this.stopNode()}><mwc-icon>dangerous</mwc-icon>&nbsp;${translate("nodepage.nchange31")}</mwc-button>
<mwc-button style="float:right;" ?hidden="${(this.upTime === "offline")}" @click=${() => this.restartNode()}><mwc-icon>360</mwc-icon>&nbsp;${translate("nodepage.nchange33")}</mwc-button>
${this.renderStartStopButton()}
<span class="sblack"><br>${translate("nodepage.nchange2")} ${this.upTime}</span>
<br><br>
<div id="minting">
@ -402,6 +406,27 @@ class NodeManagement extends LitElement {
})
}
renderStartStopButton() {
if (!isElectron()) {
return html`<mwc-button style="float:right;" class="red" ?hidden="${(this.upTime === "offline")}" @click=${() => this.stopNode()}><mwc-icon>dangerous</mwc-icon>&nbsp;${translate("nodepage.nchange31")}</mwc-button>`
} else {
if (this.upTime === "offline") {
return html`<mwc-button style="float:right;" class="green" @click=${() => this.startNode()}><mwc-icon>play_circle</mwc-icon>&nbsp;${translate("nodepage.nchange35")}</mwc-button>`
} else {
return html`<mwc-button style="float:right;" class="red" @click=${() => this.stopNode()}><mwc-icon>stop_circle</mwc-icon>&nbsp;${translate("nodepage.nchange31")}</mwc-button>`
}
}
}
startNode() {
if (!isElectron()) {
} else {
window.parent.electronAPI.startCore()
let startString = get("nodepage.nchange36")
parentEpml.request('showSnackBar', `${startString}`)
}
}
stopNode() {
parentEpml
.request("apiCall", {
@ -427,17 +452,14 @@ class NodeManagement extends LitElement {
}
bootstrap() {
parentEpml
.request("apiCall", {
parentEpml.request("apiCall", {
url: `/admin/bootstrap/?apiKey=${this.getApiKey()}`,
method: "GET"
})
.then((res) => {
}).then((res) => {
if (res === true) {
let snackString = get("tour.tour22")
parentEpml.request('showSnackBar', `${snackString}`)
}
})
}