Added server

This commit is contained in:
Myx
2022-01-02 01:26:38 +01:00
parent a0aef9e2c8
commit a30d6b2d63
293 changed files with 3337 additions and 5 deletions

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 40 KiB

BIN
Server/dist/.icon-ico/icon.ico vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

BIN
Server/dist/Changed port example.lnk vendored Normal file

Binary file not shown.

BIN
Server/dist/GoToBed.exe vendored Normal file

Binary file not shown.

13
Server/dist/builder-debug.yml vendored Normal file
View File

@@ -0,0 +1,13 @@
x64:
firstOrDefaultFilePatterns:
- '**/*'
- '!build{,/**/*}'
- '!dist{,/**/*}'
- '!**/*.{iml,hprof,orig,pyc,pyo,rbc,swp,csproj,sln,suo,xproj,cc,d.ts,pdb'
- '!**/._*'
- '!**/electron-builder.{yaml,yml,json,json5,toml}'
- '!**/{.git,.hg,.svn,CVS,RCS,SCCS,__pycache__,.DS_Store,thumbs.db,.gitignore,.gitkeep,.gitattributes,.npmignore,.idea,.vs,.flowconfig,.jshintrc,.eslintrc,.circleci,.yarn-integrity,.yarn-metadata.json,yarn-error.log,yarn.lock,package-lock.json,npm-debug.log,appveyor.yml,.travis.yml,circle.yml,.nyc_output}'
- '!.editorconfig'
nodeModuleFilePatterns: []
nsis:
script: "!include \"C:\\Users\\Ludvi\\AppData\\Roaming\\npm\\node_modules\\electron-builder\\node_modules\\app-builder-lib\\templates\\nsis\\include\\StdUtils.nsh\"\n!addincludedir \"C:\\Users\\Ludvi\\AppData\\Roaming\\npm\\node_modules\\electron-builder\\node_modules\\app-builder-lib\\templates\\nsis\\include\"\n!macro _isUpdated _a _b _t _f\n ${StdUtils.TestParameter} $R9 \"updated\"\n StrCmp \"$R9\" \"true\" `${_t}` `${_f}`\n!macroend\n!define isUpdated `\"\" isUpdated \"\"`\n\n!macro _isForceRun _a _b _t _f\n ${StdUtils.TestParameter} $R9 \"force-run\"\n StrCmp \"$R9\" \"true\" `${_t}` `${_f}`\n!macroend\n!define isForceRun `\"\" isForceRun \"\"`\n\n!macro _isKeepShortcuts _a _b _t _f\n ${StdUtils.TestParameter} $R9 \"keep-shortcuts\"\n StrCmp \"$R9\" \"true\" `${_t}` `${_f}`\n!macroend\n!define isKeepShortcuts `\"\" isKeepShortcuts \"\"`\n\n!macro _isNoDesktopShortcut _a _b _t _f\n ${StdUtils.TestParameter} $R9 \"no-desktop-shortcut\"\n StrCmp \"$R9\" \"true\" `${_t}` `${_f}`\n!macroend\n!define isNoDesktopShortcut `\"\" isNoDesktopShortcut \"\"`\n\n!macro _isDeleteAppData _a _b _t _f\n ${StdUtils.TestParameter} $R9 \"delete-app-data\"\n StrCmp \"$R9\" \"true\" `${_t}` `${_f}`\n!macroend\n!define isDeleteAppData `\"\" isDeleteAppData \"\"`\n\n!macro _isForAllUsers _a _b _t _f\n ${StdUtils.TestParameter} $R9 \"allusers\"\n StrCmp \"$R9\" \"true\" `${_t}` `${_f}`\n!macroend\n!define isForAllUsers `\"\" isForAllUsers \"\"`\n\n!macro _isForCurrentUser _a _b _t _f\n ${StdUtils.TestParameter} $R9 \"currentuser\"\n StrCmp \"$R9\" \"true\" `${_t}` `${_f}`\n!macroend\n!define isForCurrentUser `\"\" isForCurrentUser \"\"`\n\n!macro addLangs\n !insertmacro MUI_LANGUAGE \"English\"\n !insertmacro MUI_LANGUAGE \"German\"\n !insertmacro MUI_LANGUAGE \"French\"\n !insertmacro MUI_LANGUAGE \"SpanishInternational\"\n !insertmacro MUI_LANGUAGE \"SimpChinese\"\n !insertmacro MUI_LANGUAGE \"TradChinese\"\n !insertmacro MUI_LANGUAGE \"Japanese\"\n !insertmacro MUI_LANGUAGE \"Korean\"\n !insertmacro MUI_LANGUAGE \"Italian\"\n !insertmacro MUI_LANGUAGE \"Dutch\"\n !insertmacro MUI_LANGUAGE \"Danish\"\n !insertmacro MUI_LANGUAGE \"Swedish\"\n !insertmacro MUI_LANGUAGE \"Norwegian\"\n !insertmacro MUI_LANGUAGE \"Finnish\"\n !insertmacro MUI_LANGUAGE \"Russian\"\n !insertmacro MUI_LANGUAGE \"Portuguese\"\n !insertmacro MUI_LANGUAGE \"PortugueseBR\"\n !insertmacro MUI_LANGUAGE \"Polish\"\n !insertmacro MUI_LANGUAGE \"Ukrainian\"\n !insertmacro MUI_LANGUAGE \"Czech\"\n !insertmacro MUI_LANGUAGE \"Slovak\"\n !insertmacro MUI_LANGUAGE \"Hungarian\"\n !insertmacro MUI_LANGUAGE \"Arabic\"\n !insertmacro MUI_LANGUAGE \"Turkish\"\n !insertmacro MUI_LANGUAGE \"Thai\"\n !insertmacro MUI_LANGUAGE \"Vietnamese\"\n!macroend\n\n!include \"C:\\Users\\Ludvi\\AppData\\Local\\Temp\\t-6b9X7N\\0-messages.nsh\"\n!addplugindir /x86-unicode \"C:\\Users\\Ludvi\\AppData\\Local\\electron-builder\\Cache\\nsis\\nsis-resources-3.4.1\\plugins\\x86-unicode\"\n\n!include \"common.nsh\"\n!include \"extractAppPackage.nsh\"\n\n# https://github.com/electron-userland/electron-builder/issues/3972#issuecomment-505171582\nCRCCheck off\nWindowIcon Off\nAutoCloseWindow True\nRequestExecutionLevel ${REQUEST_EXECUTION_LEVEL}\n\nSilentInstall silent\n\nFunction .onInit\n !insertmacro check64BitAndSetRegView\nFunctionEnd\n\nSection\n StrCpy $INSTDIR \"$TEMP\\${UNPACK_DIR_NAME}\"\n RMDir /r $INSTDIR\n\tSetOutPath $INSTDIR\n\n\t!ifdef APP_DIR_64\n !ifdef APP_DIR_32\n ${if} ${RunningX64}\n File /r \"${APP_DIR_64}\\*.*\"\n ${else}\n File /r \"${APP_DIR_32}\\*.*\"\n ${endIf}\n !else\n File /r \"${APP_DIR_64}\\*.*\"\n !endif\n !else\n !ifdef APP_DIR_32\n File /r \"${APP_DIR_32}\\*.*\"\n !else\n !insertmacro extractEmbeddedAppPackage\n !endif\n !endif\n\n System::Call 'Kernel32::SetEnvironmentVariable(t, t)i (\"PORTABLE_EXECUTABLE_DIR\", \"$EXEDIR\").r0'\n System::Call 'Kernel32::SetEnvironmentVariable(t, t)i (\"PORTABLE_EXECUTABLE_FILE\", \"$EXEPATH\").r0'\n System::Call 'Kernel32::SetEnvironmentVariable(t, t)i (\"PORTABLE_EXECUTABLE_APP_FILENAME\", \"${APP_FILENAME}\").r0'\n ${StdUtils.GetAllParameters} $R0 0\n\tExecWait \"$INSTDIR\\${APP_EXECUTABLE_FILENAME} $R0\" $0\n SetErrorLevel $0\n\n SetOutPath $PLUGINSDIR\n\tRMDir /r $INSTDIR\nSectionEnd\n"

View File

@@ -0,0 +1,39 @@
directories:
output: dist
buildResources: build
appId: com.azaaxin
productName: GoToBed
copyright: Copyright © 2021
mac:
category: public.app-category.utilities
icon: assets/icon.icns
target:
- zip
- dmg
publish:
- github
win:
publisherName: Azaaxin
icon: buildResources/icon.png
publish:
- github
target:
- nsis
linux:
target:
- AppImage
- tar.gz
nsis:
oneClick: false
perMachine: false
allowToChangeInstallationDirectory: true
createDesktopShortcut: true
createStartMenuShortcut: true
publish:
- provider: github
owner: azaaxin
repo: accurate
vPrefixedTagName: true
private: true
releaseType: draft
electronVersion: 15.3.0

0
Server/index.html Normal file
View File

114
Server/index.js Normal file
View File

@@ -0,0 +1,114 @@
const { app, BrowserWindow, dialog } = require('electron')
const system = require('electron-shutdown-command');
const express = require('express')
const cors = require('cors');
const AutoLaunch = require('auto-launch');
const server = express();
const ip = require('ip');
const firstRun = require('electron-first-run');
const autoLaunch = new AutoLaunch({
name: 'GoToBed Server',
});
const paramPort = app.commandLine.getSwitchValue("port") == "" ? "3000" : app.commandLine.getSwitchValue("port");
const isFirstRun = firstRun();
const options = {
type: 'question',
buttons: ['ok'],
title: 'GoToBed Server: First time setup',
message: 'You can now connect to your server on this address: http://' + ip.address() +':'+ paramPort + '',
detail: 'Open GoToBed app and in settings make sure it looks like this: \n\nProtocol: http\nAddress: ' +
ip.address() + '\nPort: '+paramPort+'\n\nYou can also change the port by adding the parameter: --port=1337 when launching the server.',
};
server.use(express.json())
server.use(express.urlencoded({ extended: true }))
server.use(cors({
exposedHeaders: ['Access-Control-Allow-Origin', '*'],
}))
server.post('/commandbridge', function (req, res) {
console.log(req.body.command)
switch (req.body.command) {
case 'shutdown':
console.log('shutting down')
system.shutdown()
break;
case 'reboot':
console.log('rebooting')
system.reboot();
break;
case 'logout':
console.log('logging out')
system.logout();
break;
case 'shutdown-options':
system.shutdown({
force: req.body.options.force ?? false,
timerseconds: req.body.options.timerseconds ?? 0,
sudo: true,
debug: true,
quitapp: req.body.options.quitapp ?? false
})
break;
case 'cancel-shutdown':
console.log('cancelling shutdown')
system.abort()
break;
case 'sleep':
console.log('going to sleep')
system.hibernate()
break;
case 'set-autostart':
autoLaunch.isEnabled().then((isEnabled) => {
if (!isEnabled) {
autoLaunch.enable()
res.send('Autostart enabled');
} else {
res.status(400).send('Autostart already enabled');
}});
break;
case 'unset-autostart':
autoLaunch.isEnabled().then((isEnabled) => {
if (isEnabled) {
autoLaunch.disable()
res.send('Autostart disabled');
} else {
res.status(400).send('Autostart already disabled');
}});
break;
case 'closeServer':
res.send('Shutting down server');
app.exit();
break;
case 'resetFirstRun':
res.send('First run has been reset');
firstRun.clear();
break;
default:
console.log('unknown command')
break;
}})
app.on('ready', async () => {
if(isFirstRun) {
const firstSetup = dialog.showMessageBox(null, options);
console.log(firstSetup);
}
if(paramPort != null) {
server.listen(paramPort, err => {
if (err) {
return console.error(err);
}
})
}
});

3091
Server/package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

80
Server/package.json Normal file
View File

@@ -0,0 +1,80 @@
{
"name": "gotobed",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "node index.js",
"nodemon": "nodemon --exec npm start",
"build": "electron-builder --win portable"
},
"repository": {
"type": "git",
"url": "gotobed"
},
"author": "",
"license": "ISC",
"dependencies": {
"auto-launch": "^5.0.5",
"cors": "^2.8.5",
"electron-first-run": "^3.0.0",
"electron-shutdown-command": "^2.0.1",
"express": "^4.17.1",
"ip": "^1.1.5",
"nodemon": "^2.0.14"
},
"devDependencies": {
"electron": "^15.3.0",
"electron-builder": "^21.2.0",
"electron-shutdown-command": "^2.0.1"
},
"build": {
"appId": "com.azaaxin",
"productName": "GoToBed",
"copyright": "Copyright © 2021",
"mac": {
"category": "public.app-category.utilities",
"icon": "buildResources/icon.icns",
"target": [
"zip",
"dmg"
],
"publish": [
"github"
]
},
"win": {
"publisherName": "Azaaxin",
"icon": "buildResources/icon.png",
"publish": [
"github"
],
"target": [
"nsis"
]
},
"linux": {
"target": [
"AppImage",
"tar.gz"
]
},
"nsis": {
"oneClick": false,
"perMachine": false,
"allowToChangeInstallationDirectory": true,
"createDesktopShortcut": true,
"createStartMenuShortcut": true
},
"publish": [
{
"provider": "github",
"owner": "azaaxin",
"repo": "accurate",
"vPrefixedTagName": true,
"private": true,
"releaseType": "draft"
}
]
}
}