update and clean main process

This commit is contained in:
KorbsStudio 2023-03-30 21:53:16 -04:00
parent 58feb03f45
commit 27e4181a8b
No known key found for this signature in database
10 changed files with 5113 additions and 285 deletions

6
.env
View file

@ -17,7 +17,7 @@ SourceCode="https://github.com/company/app-name"
#######################
# Theming
## Splash
## Document: https://nexus-polestar.korbsstudio.com/basics/configuration/#splash
## Document: https://sudovanilla.com/nexus-polestar/docs/basics/configuration/#splash
LoadingIndicator="Spinner" # "Spinner" "ProgressBar" "JumpingBalls" "GlowingBars"
SplashBackground="#232323"
@ -25,8 +25,8 @@ SplashBackground="#232323"
NotificationType="Native" # "Custom" "Native"
# Pushy Notifications
# Document: https://nexus-polestar.korbsstudio.com/basics/notifications/
PushyAppId="63e9212d7446e48a2a0e8ec0"
# Document: https://sudovanilla.com/nexus-polestar/docs/basics/notifications/
PushyAppId="63e9212d7446e48a2a0e8ec0" ## Must change or users may recieve test notifications out of the blue (or this will happen: https://mastodon.social/@nixCraft/110103098153648217)
# Crash Reporter
CrashReportServer="https://nexuspolestar.bugsplat.com/post/electron/crash.php"

View file

@ -1,48 +1,12 @@
> This project is currently in development, this is NOT ready for production use
> As for auto updating features, Korbs Studio does offer it's own update server at a montly fee of $4.23/month
If you have any question concerning FalixNodes Desktop or Nexus Polestar development, you can either submit an issue or email me at [hello@korbsstudio.com](mailto:hello@korbsstudio.com).
___
# Nexus Polestar
A template replacement for FalixNodes Desktop.
![](https://cdn.korbsstudio.com/images/nexus-polestar-cover.png)
___
A [documentation website](https://nexus-polestar.korbsstudio.com) is in progress.
___
# Experiments
## Package Managers
Korbs Studio is currently looking other package managers to see which one is more or less efficient.
Final Choice: Korbs Studio has decided to use **PNPM** as it is techincally more space efficient when working with multiple projects and much faster in a lot of cases.
**Benchmark**
Speed:
- NPM - 1M 21S
- Yarn v1 - 53S
- Yarn Berry - 21S
- Yarn Canary - 18S
- PNPM - 32S (Can vary - Could be 3M if you're using PNPM for first time)
Disk Space:
- NPM - 28,099 items, totalling 591.9 MB
- Yarn v1 - 25,259 items, totalling 583.6 MB
- Yarn Berry - 1,230 items, totalling 510.9 MB
- Yarn Canary - 524 items, totalling 398.3 MB
- PNPM - 28,038 items, totalling 577.2 MB (33.5kb*)
> "*" The way PNPM works is by linking all node_modules folders on your drive to one folder, this way you don't have multiple node_modules folders through out your drive.
> Yarn Berry and Yarn Canary: With their Plug N Play option enabled. ElectronJS failed to launch resulting in a "path" argument issue. Astro launched with CSS not loading. Also, this adds like 4 extra files to the root directory, which I dis-encourage. Sad, it looked promisingly. The project may need some adjustments to make it all work.
___
## What was FalixNodes Desktop?
FalixNodes Desktop was developed by Korbs Studio, a FalixNodes Limited contractor. It was intended for its desktop customers to use FalixNodes more quickly and conveniently by allowing them to easily access both the client and game panels presented by FalixNodes. The capabilities of how the software works have progressed over time, and improved performance and security practices have been put in place to make the customer experience more efficient and trustworthy.
@ -153,7 +117,7 @@ You need to `App Name` in the following places:
Also, in the `electron-builder.yml` file, place update the App ID. As an example, if your company was called BunnyJet and your domain was BunnyJet.net, you would use `net.bunnyjet.bunnyjetdesktop`. Avoid using `-` in the app name as AppX seems to dislike it.
**Logo**
I highly recommend using the template file provided in the `/build` folder as it will help you follow the Apple and GNOME Human Interface Guidelines. The anme of file is `Nexus Polestsar - Assets.penpot`, it's designed in [Penpot](https://penpot.app).
I highly recommend using the template file provided in the `/build` folder as it will help you follow the Apple and GNOME Human Interface Guidelines. The name of file is `Nexus Polestsar - Assets.penpot`, it's designed in [Penpot](https://penpot.app).
This template also provides the backgrounds for the DMG installer and the EXE setup. ([macOS Preview](https://i.imgur.com/t1oQFgd.png) / [Windows Preview](https://i.imgur.com/ftiXdoR.png))
@ -195,9 +159,11 @@ yarn build
___
## Support
If you are having issues with the template, you can either submit an [issue](https://code.korbsstudio.com/KorbsStudio/nexus-polestar/-/issues) or [contact Korbs Studio by email](mailto:support@korbsstudio.com).
If you are having issues with the template, you can either submit an [issue](https://sudovanilla.com/code/KorbsStudio/nexus-polestar/-/issues) or [contact SudoVanilla by email](mailto:support@SudoVanilla.com).
> Disclaimer: Korbs Studio does not work for any projects or companies that use this template. So, if you're using a software built on Nexus Polestar, please contact the company or have the company contact Korbs Studio.
**Disclaimer**: SudoVanilla does not work for any projects or companies that use this template. So, if you're using a software built on Nexus Polestar, please contact the company or have the company contact SudoVanilla.
*If by any chance SudoVanilla is working on any projects with this template, it'll be listed below.
___
@ -227,7 +193,7 @@ ___
<div align="center"><img src="https://www.gnu.org/graphics/agplv3-with-text-162x68.png"></div>
```
Copyright (C) 2023 Korbs Studio
Copyright (C) 2023 SudoVanilla
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
@ -243,4 +209,4 @@ You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>
```
You can contact Korbs Studio by sending an email to [hello@korbsstudio.com](mailto:hello@korbsstudio.com).
You can contact Korbs Studio by sending an email to [hello@sudovanilla.com](mailto:hello@sudovanilla.com).

19
electron/crashreporter.js Normal file
View file

@ -0,0 +1,19 @@
const {crashReporter} = require('electron')
const bugsplat = require("bugsplat")
module.exports = {
Reporter: function() {
// Crash Reporter
crashReporter.start({
productName: process.env.Name,
submitURL: process.env.CrashReportServer,
})
const javaScriptErrorHandler = async (error) => {
// await bugsplat.post(error);
app.quit();
}
}
// If you want test the crash reporter, uncomment the code below and wait a few moments.
// setTimeout(() => {process.crash()}, 2400)
}

View file

@ -1,239 +1,17 @@
// ElectronJS
const {app, BrowserWindow, Menu, nativeTheme, Notification, crashReporter} = require('electron')
// Dependenies by Korbs Studio
const glasstron = require('glasstron-clarity')
const TitlebarRespect = require('electron-titlebar-respect')
// Other dependenies
const isDev = require('electron-is-dev')
const log = require('electron-log')
const Pushy = require('pushy-electron')
// Needed for other stuff
const path = require('path')
// const bugsplat = require("bugsplat");
let mainWindow
const {app} = require('electron')
// Grab .env options
require('dotenv').config()
// Override the console.log function with Electron Log
log.transports.console.format = '\x1b[34m[electron]:\x1b[37m'
console.log = log.log
// Import Functions
let MainWindow = require('./mainwindow')
let CrashReporter = require('./crashreporter')
// Use the correct icon depending on the operating system
if /* If macOS */ (process.platform === 'darwin') {global.AppIcon = 'public/images/icons/app/macOS.icns' }
else if /* If Windows */ (process.platform === 'win32') {global.AppIcon = 'public/images/icons/app/Windows.png' }
else /* If Linux */ {global.AppIcon = 'public/images/icons/app/Linux.png' }
// Functions
function createWindow () {
mainWindow = new glasstron.BrowserWindow({
title: process.env.Name,
minWidth: 400,
minHeight: 400,
width: 1200,
height: 800,
autoHideMenuBar: true,
show: false,
blur: true,
frame: global.frame,
titleBarStyle: global.titleBarStyle,
icon: path.join(global.AppIcon),
trafficLightPosition: { x: 25, y: 25 }, // Position of Traffic Light buttons on macOS
titleBarOverlay: { // Background and Height of Windows titlebar buttons
color: '#232323', // Background
symbolColor: 'white', // Icon
height: 44,
},
webPreferences: {
webviewTag: true
}
})
// Showing the window gracefuly
// Doc: https://www.electronjs.org/docs/latest/api/browser-window#showing-the-window-gracefully
mainWindow.once('ready-to-show', () => {mainWindow.show()})
// Set Platform Class
if /* If macOS */ (process.platform === 'darwin') { mainWindow.webContents.executeJavaScript(`document.querySelector('html').setAttribute('os', 'Mac')`) }
else if /* If Windows */ (process.platform === 'win32') { mainWindow.webContents.executeJavaScript(`document.querySelector('html').setAttribute('os', 'Windows')`) }
else /* If Linux */ { mainWindow.webContents.executeJavaScript(`document.querySelector('html').setAttribute('os', 'Linux')`) }
// Pushy - Pushy Notification System (PNS)
mainWindow.webContents.on('did-finish-load', () => {Pushy.listen()})
Pushy.register({ appId: process.env.PushyAppId }).then((deviceToken) => {}).catch((error) => {console.log('Pushy registration error: ' + error.message)})
setTimeout(() => {
Pushy.setNotificationListener((data) => {
new Notification({ title: data.title, body: data.message }).show()
if(process.env.NotificationType === 'Native') {
new Notification({ title: data.title, body: data.message }).show()
}
else if(process.env.NotificationType === 'Custom') {
mainWindow.webContents.executeJavaScript(`
document.querySelector("body > div > div.sidebar > div.sidebar-bottom").insertAdjacentHTML("afterBegin",'<li class="notification"><img class="notification-image" src="${data.image}"><i class="${data.icon}"></i><p class="notification-title">${data.title}</p><p class="notification-message">${data.message}</p><div class="notification-actions"><button id="primary" class="notification-action" onclick="shell.openExternal(${data.action})">Open</button><button id="secondary" class="notification-action">Dismiss</button></div></li>')
`)
}
})
}, 5000) // If this is triggered too soon, the notifications won't work.
if (Pushy.isRegistered()) {Pushy.subscribe('AppName').then(() => {}).catch((error) => {console.error(error)})}
// Load Content
if (isDev) {
mainWindow.loadURL('http://localhost:3000') // Use a URL in development mode
} else {
mainWindow.loadFile('app/index.html') // Do NOT use a URL in production mode, as that can create a security risk for your customers who will use this app
}
// Menu
const isMac = process.platform === 'darwin'
const template = [
...(isMac ? [{
label: app.name,
submenu: [
{ role: 'about' },
{ type: 'separator' },
{ role: 'hide' },
{ role: 'hideOthers' },
{ role: 'unhide' },
{ type: 'separator' },
{ role: 'quit' }
]
}] : []),
{
label: 'File',
submenu: [
isMac ? { role: 'close' } : { role: 'quit' }
]
},
{
label: 'Edit',
submenu: [
{ role: 'undo' },
{ role: 'redo' },
{ type: 'separator' },
{ role: 'cut' },
{ role: 'copy' },
{ role: 'paste' },
...(isMac ? [
{ role: 'pasteAndMatchStyle' },
{ role: 'delete' },
{ role: 'selectAll' },
{ type: 'separator' },
{
label: 'Speech',
submenu: [
{ role: 'startSpeaking' },
{ role: 'stopSpeaking' }
]
}
] : [
{ role: 'delete' },
{ type: 'separator' },
{ role: 'selectAll' }
])
]
},
{
label: 'View',
submenu: [
{ role: 'reload' },
{ role: 'forceReload' },
{ role: 'toggleDevTools' },
{
label: 'Open WebView Developer Tools',
accelerator: 'CmdOrCtrl+Shift+W',
click: async () => {if (isDev) {mainWindow.webContents.executeJavaScript(`document.querySelector('.active webview').openDevTools()`)}else {console.log('Not available in production mode.')}}
},
{ type: 'separator' },
{ role: 'resetZoom' },
{ role: 'zoomIn' },
{ role: 'zoomOut' },
{ type: 'separator' },
{ role: 'togglefullscreen' }
]
},
{
label: 'Window',
submenu: [
{ role: 'minimize' },
{ role: 'zoom' },
...(isMac ? [
{ type: 'separator' },
{ role: 'front' },
{ type: 'separator' },
{ role: 'window' }
] : [
{ role: 'close' }
])
]
},
{
role: 'help',
submenu: [
{
label: 'Website',
click: async () => {
const { shell } = require('electron')
await shell.openExternal(process.env.Website)
}
},
{
label: 'Support',
click: async () => {
const { shell } = require('electron')
await shell.openExternal(process.env.Support)
}
},
{
label: 'Source Code',
click: async () => {
const { shell } = require('electron')
await shell.openExternal(process.env.SourceCode)
}
}
]
}
]
const menu = Menu.buildFromTemplate(template)
Menu.setApplicationMenu(menu)
}
// Crash Reporter
if (process.platform === 'darwin') {
// Disable crash reporter
}
else {
crashReporter.start({
productName: process.env.Name,
submitURL: process.env.CrashReportServer,
})
const javaScriptErrorHandler = async (error) => {
// await bugsplat.post(error);
app.quit();
}
}
// If you want test the crash reporter, uncomment the code below and wait a few moments.
// setTimeout(() => {process.crash()}, 2400) // Wait a moment, then crash.z
CrashReporter.Reporter()
// App
app.whenReady().then(() => {
createWindow()
// DNS
// Docs: https://www.electronjs.org/docs/latest/api/app#appconfigurehostresolveroptions
app.configureHostResolver({
secureDnsMode: 'secure',
secureDnsServers: [
'https://cloudflare-dns.com/dns-query'
]
})
})
// app.disableHardwareAcceleration()
app.on('window-all-closed', () => {
app.quit()
})
app.whenReady().then(() => {MainWindow.Create()})
app.on('window-all-closed', () => {app.quit()})

54
electron/mainwindow.js Normal file
View file

@ -0,0 +1,54 @@
const {BrowserWindow} = require('electron')
const glasstron = require('glasstron-clarity') // By SudoVanilla
const path = require('path')
const {TitlebarRespect} = require('electron-titlebar-respect') // By SudoVanilla
let AppMenu = require('./menu')
let Notification = require('./notifications')
let Platform = require('./platform')
TitlebarRespect({})
module.exports = {
Create: function() {
mainWindow = new glasstron.BrowserWindow({
title: process.env.Name,
minWidth: 400,
minHeight: 400,
width: 1200,
height: 800,
autoHideMenuBar: true,
show: false,
blur: true,
frame: global.frame,
titleBarStyle: global.titleBarStyle,
icon: global.AppIcon,
trafficLightPosition: { x: 25, y: 25 }, // Position of Traffic Light buttons on macOS
titleBarOverlay: { // Background and Height of Windows titlebar buttons
color: '#232323', // Background
symbolColor: 'white', // Icon
height: 44,
},
webPreferences: {
webviewTag: true
}
})
// Load Content
if (process.env.NODE_ENV === "development") {
mainWindow.loadURL('http://localhost:3000') // Use a URL in development mode
} else if (process.env.NODE_ENV === 'production') {
mainWindow.loadFile('app/index.html') // Do NOT use a URL in production mode, as that can create a security risk for your users who will use this app
}
// Showing the window gracefuly
// Doc: https://www.electronjs.org/docs/latest/api/browser-window#showing-the-window-gracefully
mainWindow.once('ready-to-show', () => {mainWindow.show()})
// Functions
AppMenu.MainMenu()
Notification.Pushy()
Platform.Class()
Platform.Icon()
}
}

118
electron/menu.js Normal file
View file

@ -0,0 +1,118 @@
const {Menu} = require('electron')
module.exports = {
MainMenu: function() {
const isMac = process.platform === 'darwin'
const template = [
...(isMac ? [{
label: app.name,
submenu: [
{ role: 'about' },
{ type: 'separator' },
{ role: 'hide' },
{ role: 'hideOthers' },
{ role: 'unhide' },
{ type: 'separator' },
{ role: 'quit' }
]
}] : []),
{
label: 'File',
submenu: [
isMac ? { role: 'close' } : { role: 'quit' }
]
},
{
label: 'Edit',
submenu: [
{ role: 'undo' },
{ role: 'redo' },
{ type: 'separator' },
{ role: 'cut' },
{ role: 'copy' },
{ role: 'paste' },
...(isMac ? [
{ role: 'pasteAndMatchStyle' },
{ role: 'delete' },
{ role: 'selectAll' },
{ type: 'separator' },
{
label: 'Speech',
submenu: [
{ role: 'startSpeaking' },
{ role: 'stopSpeaking' }
]
}
] : [
{ role: 'delete' },
{ type: 'separator' },
{ role: 'selectAll' }
])
]
},
{
label: 'View',
submenu: [
{ role: 'reload' },
{ role: 'forceReload' },
{ role: 'toggleDevTools' },
{
label: 'Open WebView Developer Tools',
accelerator: 'CmdOrCtrl+Shift+W',
click: async () => {if (isDev) {mainWindow.webContents.executeJavaScript(`document.querySelector('.active webview').openDevTools()`)}else {console.log('Not available in production mode.')}}
},
{ type: 'separator' },
{ role: 'resetZoom' },
{ role: 'zoomIn' },
{ role: 'zoomOut' },
{ type: 'separator' },
{ role: 'togglefullscreen' }
]
},
{
label: 'Window',
submenu: [
{ role: 'minimize' },
{ role: 'zoom' },
...(isMac ? [
{ type: 'separator' },
{ role: 'front' },
{ type: 'separator' },
{ role: 'window' }
] : [
{ role: 'close' }
])
]
},
{
role: 'help',
submenu: [
{
label: 'Website',
click: async () => {
const { shell } = require('electron')
await shell.openExternal(process.env.Website)
}
},
{
label: 'Support',
click: async () => {
const { shell } = require('electron')
await shell.openExternal(process.env.Support)
}
},
{
label: 'Source Code',
click: async () => {
const { shell } = require('electron')
await shell.openExternal(process.env.SourceCode)
}
}
]
}
]
const menu = Menu.buildFromTemplate(template)
Menu.setApplicationMenu(menu)
}
}

25
electron/notifications.js Normal file
View file

@ -0,0 +1,25 @@
const Pushy = require('pushy-electron')
let MainWindow = require('./mainwindow')
module.exports = {
Pushy: function() {
// Pushy - Pushy Notification System (PNS)
mainWindow.webContents.on('did-finish-load', () => {Pushy.listen()})
Pushy.register({ appId: process.env.PushyAppId }).then((deviceToken) => {}).catch((error) => {console.log('Pushy registration error: ' + error.message)})
setTimeout(() => {
Pushy.setNotificationListener((data) => {
new Notification({ title: data.title, body: data.message }).show()
if(process.env.NotificationType === 'Native') {
new Notification({ title: data.title, body: data.message }).show()
}
else if(process.env.NotificationType === 'Custom') {
mainWindow.webContents.executeJavaScript(`
document.querySelector("body > div > div.sidebar > div.sidebar-bottom").insertAdjacentHTML("afterBegin",'<li class="notification"><img class="notification-image" src="${data.image}"><i class="${data.icon}"></i><p class="notification-title">${data.title}</p><p class="notification-message">${data.message}</p><div class="notification-actions"><button id="primary" class="notification-action" onclick="shell.openExternal(${data.action})">Open</button><button id="secondary" class="notification-action">Dismiss</button></div></li>')
`)
}
})
}, 5000) // If this is triggered too soon, the notifications won't work.
if (Pushy.isRegistered()) {Pushy.subscribe('AppName').then(() => {}).catch((error) => {console.error(error)})}
}
}

14
electron/platform.js Normal file
View file

@ -0,0 +1,14 @@
module.exports = {
Icon: function() {
// Use the correct icon depending on the operating system
if /* If macOS */ (process.platform === 'darwin') {global.AppIcon = 'public/images/icons/app/macOS.icns' }
else if /* If Windows */ (process.platform === 'win32') {global.AppIcon = 'public/images/icons/app/Windows.png'}
else /* If Linux */ {global.AppIcon = 'public/images/icons/app/Linux.png' }
},
Class: function() {
// Set Platform Class
if /* If macOS */ (process.platform === 'darwin') {mainWindow.webContents.executeJavaScript(`document.querySelector('html').setAttribute('os', 'Mac')`) }
else if /* If Windows */ (process.platform === 'win32') {mainWindow.webContents.executeJavaScript(`document.querySelector('html').setAttribute('os', 'Windows')`) }
else /* If Linux */ {mainWindow.webContents.executeJavaScript(`document.querySelector('html').setAttribute('os', 'Linux')`) }
}
}

View file

@ -4,27 +4,26 @@
"description": "",
"main": "./electron/index.js",
"scripts": {
"start": "concurrently \"astro dev\" \"electron .\"",
"start": "concurrently \"astro dev\" \"NODE_ENV=development electron .\"",
"start:delay": "concurrently \"astro dev\" \"sleep 5 && electron .\"",
"build": "astro build && node ./build/prepare-production.js && electron-builder build --config ./build/electron-builder.yml"
"build": "astro build && NODE_ENV=production node ./build/prepare-production.js && electron-builder build --config ./build/electron-builder.yml"
},
"author": "KorbsStudio",
"author": "SudoVanilla",
"license": "AGPL",
"devDependencies": {
"concurrently": "^7.6.0",
"electron": "^23.0.0-beta.5",
"concurrently": "^8.0.1",
"electron": "^23.2.1",
"electron-builder": "^23.6.0"
},
"dependencies": {
"astro": "^2.0.9",
"bugsplat-node": "^2.1.0",
"astro": "^2.1.8",
"bugsplat": "^8.0.0",
"bugsplat-node": "^3.0.0",
"dotenv": "^16.0.3",
"electron-is-dev": "^2.0.0",
"electron-log": "^5.0.0-beta.15",
"electron-titlebar-respect": "^1.0.0",
"electron-titlebar-respect": "^1.1.1",
"glasstron-clarity": "^0.1.26",
"pushy-electron": "^1.0.11",
"replace": "^1.2.2",
"sass": "^1.58.3"
"sass": "^1.60.0"
}
}

4855
pnpm-lock.yaml Normal file

File diff suppressed because it is too large Load diff