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