Skip to content

Commit

Permalink
Improved main.js script.
Browse files Browse the repository at this point in the history
The main.js script were improved – the "About" panel shows now the version from `package.js` and I've also fixed the issue where the second session of the app would not un-minimize and focus the app (and now it shows the app when hidden in system tray too).
  • Loading branch information
SpacingBat3 committed Oct 26, 2020
1 parent c435960 commit acac4dd
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 15 deletions.
35 changes: 21 additions & 14 deletions main.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
// Load the functions that we need to have from the electron
const { app, BrowserWindow, Tray, Menu, MenuItem, shell } = require('electron')

// Read properties from package.json
var packageJson = require('./package.json');

// Vars to modify app behavior
var appName = 'Discord'
var appURL = 'https://discord.com/app'
var appIcon = 'icons/app.png'
var appTrayIcon = 'icons/tray.png'
var appTrayIconSmall = 'icons/tray-small.png'
var wWidth = '1000'
var wHeight = '600'
var winWidth = 1000
var winHeight = 600

// "About" information
var appFullName = 'Electron Discord WebApp'
var appVersion = '0.1.0'
var appVersion = packageJson.version;
var appAuthor = 'Spacingbat3'
var appCredits = "Thanks to GyozaGuy for his electron discord app – it was good source\nto learn about electron and making the Discord web app."
var appYear = '2020' // the year from app exists
var appRepo = "https://github.com/SpacingBat3/electron-discord-webapp"

const singleInstance = app.requestSingleInstanceLock()
var mainWindow
// Add yourself there if you're doing PR to this repository.
// The valid format if JavaScript array. ( = [var,"string"] )
// Removing any entry of array there will deny your PR!
Expand Down Expand Up @@ -56,10 +60,10 @@ function createWindow () {
//Browser window

const win = new BrowserWindow({
tittle: appName,
width: wWidth,
height: wHeight,
backgroundColor: "#202225",
title: appName,
height: winHeight,
width: winWidth,
backgroundColor: "#2F3136",
icon: appIcon,
webPreferences: {
nodeIntegration: false, // won't work with the true value
Expand Down Expand Up @@ -115,23 +119,26 @@ function createWindow () {
})

// Open external URLs in default browser

win.webContents.on('new-window', (event, externalURL) => {
event.preventDefault();
shell.openExternal(externalURL)
})
return win
}

const singleInstance = app.requestSingleInstanceLock()

if (!singleInstance) {
app.quit()
} else {
app.on('second-instance', (event, commandLine, workingDirectory) => {
if (win && win.isMinimized()) win.restore()
win.focus()
if (mainWindow){
if(!mainWindow.isVisible()) mainWindow.show()
if(mainWindow.isMinimized()) mainWindow.restore()
mainWindow.focus()
}
})
app.on('ready', () => {
createWindow()
mainWindow = createWindow() // catch window as mainWindow
})
}

Expand All @@ -143,7 +150,7 @@ app.on('window-all-closed', () => {

app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow()
mainWindow = createWindow()
}
})

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "electron-discord-webapp",
"version": "0.1.0",
"version": "0.1.1",
"description": "A Discord Web App based on the Electron Engine.",
"main": "main.js",
"scripts": {
Expand Down

0 comments on commit acac4dd

Please sign in to comment.