make login window closable
This commit is contained in:
parent
efe3a4e643
commit
b4249e7108
@ -307,12 +307,25 @@ loginMSButton.addEventListener('click', (event) => {
|
|||||||
|
|
||||||
ipcRenderer.on('MSALoginWindowReply', (event, ...args) => {
|
ipcRenderer.on('MSALoginWindowReply', (event, ...args) => {
|
||||||
if (args[0] === 'error') {
|
if (args[0] === 'error') {
|
||||||
setOverlayContent('ERROR', 'There is already a login window open!', 'OK')
|
switch (args[1]){
|
||||||
setOverlayHandler(() => {
|
case 'AlreadyOpenException': {
|
||||||
toggleOverlay(false)
|
setOverlayContent('ERROR', 'There is already a login window open!', 'OK')
|
||||||
})
|
setOverlayHandler(() => {
|
||||||
toggleOverlay(true)
|
toggleOverlay(false)
|
||||||
return
|
})
|
||||||
|
toggleOverlay(true)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
case 'AuthNotFinished': {
|
||||||
|
setOverlayContent('ERROR', 'You have to finish the login process to use Helios Launcher. The window will close by itself when you have successfully logged in.', 'OK')
|
||||||
|
setOverlayHandler(() => {
|
||||||
|
toggleOverlay(false)
|
||||||
|
})
|
||||||
|
toggleOverlay(true)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const queryMap = args[0]
|
const queryMap = args[0]
|
||||||
|
55
index.js
55
index.js
@ -1,12 +1,12 @@
|
|||||||
// Requirements
|
// Requirements
|
||||||
const { app, BrowserWindow, ipcMain, Menu } = require('electron')
|
const { app, BrowserWindow, ipcMain, Menu } = require('electron')
|
||||||
const autoUpdater = require('electron-updater').autoUpdater
|
const autoUpdater = require('electron-updater').autoUpdater
|
||||||
const ejse = require('ejs-electron')
|
const ejse = require('ejs-electron')
|
||||||
const fs = require('fs')
|
const fs = require('fs')
|
||||||
const isDev = require('./app/assets/js/isdev')
|
const isDev = require('./app/assets/js/isdev')
|
||||||
const path = require('path')
|
const path = require('path')
|
||||||
const semver = require('semver')
|
const semver = require('semver')
|
||||||
const url = require('url')
|
const url = require('url')
|
||||||
|
|
||||||
const redirectUriPrefix = 'https://login.microsoftonline.com/common/oauth2/nativeclient?'
|
const redirectUriPrefix = 'https://login.microsoftonline.com/common/oauth2/nativeclient?'
|
||||||
const clientID = 'client id here'
|
const clientID = 'client id here'
|
||||||
@ -14,18 +14,18 @@ const clientID = 'client id here'
|
|||||||
// Setup auto updater.
|
// Setup auto updater.
|
||||||
function initAutoUpdater(event, data) {
|
function initAutoUpdater(event, data) {
|
||||||
|
|
||||||
if(data){
|
if (data) {
|
||||||
autoUpdater.allowPrerelease = true
|
autoUpdater.allowPrerelease = true
|
||||||
} else {
|
} else {
|
||||||
// Defaults to true if application version contains prerelease components (e.g. 0.12.1-alpha.1)
|
// Defaults to true if application version contains prerelease components (e.g. 0.12.1-alpha.1)
|
||||||
// autoUpdater.allowPrerelease = true
|
// autoUpdater.allowPrerelease = true
|
||||||
}
|
}
|
||||||
|
|
||||||
if(isDev){
|
if (isDev) {
|
||||||
autoUpdater.autoInstallOnAppQuit = false
|
autoUpdater.autoInstallOnAppQuit = false
|
||||||
autoUpdater.updateConfigPath = path.join(__dirname, 'dev-app-update.yml')
|
autoUpdater.updateConfigPath = path.join(__dirname, 'dev-app-update.yml')
|
||||||
}
|
}
|
||||||
if(process.platform === 'darwin'){
|
if (process.platform === 'darwin') {
|
||||||
autoUpdater.autoDownload = false
|
autoUpdater.autoDownload = false
|
||||||
}
|
}
|
||||||
autoUpdater.on('update-available', (info) => {
|
autoUpdater.on('update-available', (info) => {
|
||||||
@ -42,12 +42,12 @@ function initAutoUpdater(event, data) {
|
|||||||
})
|
})
|
||||||
autoUpdater.on('error', (err) => {
|
autoUpdater.on('error', (err) => {
|
||||||
event.sender.send('autoUpdateNotification', 'realerror', err)
|
event.sender.send('autoUpdateNotification', 'realerror', err)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Open channel to listen for update actions.
|
// Open channel to listen for update actions.
|
||||||
ipcMain.on('autoUpdateAction', (event, arg, data) => {
|
ipcMain.on('autoUpdateAction', (event, arg, data) => {
|
||||||
switch(arg){
|
switch (arg) {
|
||||||
case 'initAutoUpdater':
|
case 'initAutoUpdater':
|
||||||
console.log('Initializing auto updater.')
|
console.log('Initializing auto updater.')
|
||||||
initAutoUpdater(event, data)
|
initAutoUpdater(event, data)
|
||||||
@ -60,9 +60,9 @@ ipcMain.on('autoUpdateAction', (event, arg, data) => {
|
|||||||
})
|
})
|
||||||
break
|
break
|
||||||
case 'allowPrereleaseChange':
|
case 'allowPrereleaseChange':
|
||||||
if(!data){
|
if (!data) {
|
||||||
const preRelComp = semver.prerelease(app.getVersion())
|
const preRelComp = semver.prerelease(app.getVersion())
|
||||||
if(preRelComp != null && preRelComp.length > 0){
|
if (preRelComp != null && preRelComp.length > 0) {
|
||||||
autoUpdater.allowPrerelease = true
|
autoUpdater.allowPrerelease = true
|
||||||
} else {
|
} else {
|
||||||
autoUpdater.allowPrerelease = data
|
autoUpdater.allowPrerelease = data
|
||||||
@ -89,11 +89,13 @@ ipcMain.on('distributionIndexDone', (event, res) => {
|
|||||||
app.disableHardwareAcceleration()
|
app.disableHardwareAcceleration()
|
||||||
|
|
||||||
let MSALoginWindow = null
|
let MSALoginWindow = null
|
||||||
|
let login = false
|
||||||
|
|
||||||
// Open the Microsoft Account Login window
|
// Open the Microsoft Account Login window
|
||||||
ipcMain.on('openMSALoginWindow', (ipcEvent, args) => {
|
ipcMain.on('openMSALoginWindow', (ipcEvent, args) => {
|
||||||
if(MSALoginWindow != null){
|
login = false
|
||||||
ipcEvent.sender.send('MSALoginWindowNotification', 'error', 'AlreadyOpenException')
|
if (MSALoginWindow != null) {
|
||||||
|
ipcEvent.reply('MSALoginWindowReply', 'error', 'AlreadyOpenException')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
MSALoginWindow = new BrowserWindow({
|
MSALoginWindow = new BrowserWindow({
|
||||||
@ -101,16 +103,23 @@ ipcMain.on('openMSALoginWindow', (ipcEvent, args) => {
|
|||||||
backgroundColor: '#222222',
|
backgroundColor: '#222222',
|
||||||
width: 520,
|
width: 520,
|
||||||
height: 600,
|
height: 600,
|
||||||
frame: false,
|
frame: true,
|
||||||
icon: getPlatformIcon('SealCircle')
|
icon: getPlatformIcon('SealCircle')
|
||||||
})
|
})
|
||||||
|
|
||||||
MSALoginWindow.on('closed', () => {
|
MSALoginWindow.on('closed', () => {
|
||||||
|
|
||||||
MSALoginWindow = null
|
MSALoginWindow = null
|
||||||
})
|
})
|
||||||
|
|
||||||
|
MSALoginWindow.on('close', event => {
|
||||||
|
ipcEvent.reply('MSALoginWindowReply', 'error', 'AuthNotFinished')
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
MSALoginWindow.webContents.on('did-navigate', (event, uri, responseCode, statusText) => {
|
MSALoginWindow.webContents.on('did-navigate', (event, uri, responseCode, statusText) => {
|
||||||
if(uri.startsWith(redirectUriPrefix)) {
|
login = true
|
||||||
|
if (uri.startsWith(redirectUriPrefix)) {
|
||||||
let querys = uri.substring(redirectUriPrefix.length).split('#', 1).toString().split('&')
|
let querys = uri.substring(redirectUriPrefix.length).split('#', 1).toString().split('&')
|
||||||
let queryMap = new Map()
|
let queryMap = new Map()
|
||||||
|
|
||||||
@ -177,8 +186,8 @@ function createWindow() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function createMenu() {
|
function createMenu() {
|
||||||
|
|
||||||
if(process.platform === 'darwin') {
|
if (process.platform === 'darwin') {
|
||||||
|
|
||||||
// Extend default included application menu to continue support for quit keyboard shortcut
|
// Extend default included application menu to continue support for quit keyboard shortcut
|
||||||
let applicationSubMenu = {
|
let applicationSubMenu = {
|
||||||
@ -240,9 +249,9 @@ function createMenu() {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function getPlatformIcon(filename){
|
function getPlatformIcon(filename) {
|
||||||
let ext
|
let ext
|
||||||
switch(process.platform) {
|
switch (process.platform) {
|
||||||
case 'win32':
|
case 'win32':
|
||||||
ext = 'ico'
|
ext = 'ico'
|
||||||
break
|
break
|
||||||
|
Loading…
Reference in New Issue
Block a user