9
9
*/
10
10
11
11
'use strict'
12
+ require ( './global.js' ) ;
12
13
13
14
// import * as Sentry from '@sentry/electron'
14
15
// import { init } from '@sentry/electron/dist/main';
@@ -21,19 +22,17 @@ import {
21
22
installVueDevtools ,
22
23
createProtocol ,
23
24
} from 'vue-cli-plugin-electron-builder/lib' ;
24
- require ( './global.js' ) ;
25
25
import path from 'path' ;
26
- const { shell } = require ( 'electron' ) ;
27
- const { dialog } = require ( 'electron' ) ;
26
+ const { shell, dialog } = require ( 'electron' ) ;
28
27
const electronDlMain = require ( 'electron-dl' ) ;
29
28
const { readdirSync } = require ( 'fs' ) ;
30
29
const { forEach } = require ( 'p-iteration' ) ;
31
30
const hasha = require ( 'hasha' ) ;
32
31
const compareVersions = require ( 'compare-versions' ) ;
33
- const isAdmin = require ( 'is-admin' ) ;
34
32
const glob = require ( 'glob' ) ;
35
33
const cp = require ( 'child_process' ) ;
36
34
const log = require ( 'electron-log' ) ;
35
+ import { autoUpdater } from 'electron-updater'
37
36
const tasklist = require ( 'tasklist' ) ; // This is specific to Windows.
38
37
// For tasklist to work correctly on some systems...
39
38
// if (process.platform === "win32") {
@@ -43,6 +42,7 @@ const tasklist = require('tasklist'); // This is specific to Windows.
43
42
import * as versionPaths from './electron_modules/versionPaths.js' ;
44
43
import * as migrateLauncher from './electron_modules/migrateLauncher.js' ;
45
44
import * as download from './electron_modules/networking/download.js' ;
45
+ import * as privileges from './electron_modules/privileges.js'
46
46
47
47
function initialize ( ) {
48
48
if ( pantheonConfig . app . storagePath ) {
@@ -111,7 +111,9 @@ function createWindow () {
111
111
if ( process . env . WEBPACK_DEV_SERVER_URL ) {
112
112
// Load the url of the dev server if in development mode
113
113
win . loadURL ( process . env . WEBPACK_DEV_SERVER_URL )
114
- if ( ! process . env . IS_TEST ) win . webContents . openDevTools ( )
114
+ if ( ! process . env . IS_TEST ) {
115
+ win . webContents . openDevTools ( )
116
+ }
115
117
} else {
116
118
createProtocol ( 'app' )
117
119
// Load the index.html when not in development
@@ -338,6 +340,28 @@ function setLibraryDialog() {
338
340
} )
339
341
}
340
342
343
+ function requestLauncherAsAdmin ( ) {
344
+ var appPathSplit = app . getPath ( 'exe' ) . split ( '\\' ) ;
345
+ var appPathCleaned = appPathSplit . slice ( 0 , appPathSplit . length - 1 ) . join ( '\\' ) ;
346
+
347
+ var pathToLauncher = appPathCleaned + '\\' + PRODUCT_NAME ;
348
+ var pathToElevator = '"' + appPathCleaned + '\\resources\\elevate.exe' + '"' ;
349
+ var launchParameter = '-k "' + pathToLauncher + '"' ;
350
+ var interface_exe = require ( 'child_process' ) . spawn ;
351
+
352
+ // console.info(dialog.showMessageBox({ message: pathToElevator }))
353
+ // console.info(dialog.showMessageBox({ message: launchParameter }))
354
+ // console.info(dialog.showMessageBox({ message: appPathCleaned }))
355
+
356
+ var elevateExe = interface_exe ( pathToElevator , [ launchParameter ] , {
357
+ windowsVerbatimArguments : true ,
358
+ shell : true ,
359
+ detached : true
360
+ } ) ;
361
+
362
+ app . exit ( ) ;
363
+ }
364
+
341
365
// async function getCurrentInterfaceJSON() {
342
366
// var interfacePackageJSON = storagePath.interfaceSettings + '/interface_package.json';
343
367
//
@@ -384,16 +408,6 @@ async function checkForInterfaceUpdates() {
384
408
}
385
409
}
386
410
387
- async function isRunningAsAdministrator ( ) {
388
- var requestIsAdmin = await isAdmin ( ) ;
389
-
390
- if ( requestIsAdmin ) {
391
- return true ;
392
- } else {
393
- return false ;
394
- }
395
- }
396
-
397
411
async function checkForUpdates ( checkSilently ) {
398
412
if ( storagePath . interfaceSettings ) {
399
413
// This means to update because an interface exists and is selected.
@@ -683,7 +697,7 @@ async function silentInstall(useOldInstaller) {
683
697
var executablePath ; // This is the location that the installer exe is located in after being downloaded.
684
698
var exeLocToInstall ; // This is what gets installed.
685
699
var checkPrereqs = await checkRunningApps ( ) ;
686
- var isAdmin = await isRunningAsAdministrator ( ) ;
700
+ var isAdmin = await privileges . isRunningAsAdministrator ( ) ;
687
701
688
702
if ( checkPrereqs . sandbox === true ) {
689
703
win . webContents . send ( 'silent-installer-failed' , { "message" : 'Your server sandbox is running. Please close it before proceeding.' } ) ;
@@ -970,7 +984,7 @@ ipcMain.on('download-vircadia', async (event, arg) => {
970
984
var libraryPath ;
971
985
var downloadURL = await getDownloadURL ( ) ;
972
986
var vircadiaMetaJSON = await download . cdn . meta ( ) ;
973
- var isAdmin = await isRunningAsAdministrator ( ) ;
987
+ var isAdmin = await privileges . isRunningAsAdministrator ( ) ;
974
988
var checkPrereqs = await checkRunningApps ( ) ;
975
989
var installerName = pantheonConfig . manager . preInstallerName ;
976
990
var installerNamePost = pantheonConfig . manager . postInstallerName ;
@@ -1107,27 +1121,53 @@ ipcMain.on('request-close', async (event, arg) => {
1107
1121
} ) ;
1108
1122
1109
1123
ipcMain . on ( 'request-launcher-as-admin' , async ( event , arg ) => {
1110
- var appPathSplit = app . getPath ( 'exe' ) . split ( '\\' ) ;
1111
- var appPathCleaned = appPathSplit . slice ( 0 , appPathSplit . length - 1 ) . join ( '\\' ) ;
1112
-
1113
- var pathToLauncher = appPathCleaned + '\\' + PRODUCT_NAME ;
1114
- var pathToElevator = '"' + appPathCleaned + '\\resources\\elevate.exe' + '"' ;
1115
- var launchParameter = '-k "' + pathToLauncher + '"' ;
1116
- var interface_exe = require ( 'child_process' ) . spawn ;
1117
-
1118
- // console.info(dialog.showMessageBox({ message: pathToElevator }))
1119
- // console.info(dialog.showMessageBox({ message: launchParameter }))
1120
- // console.info(dialog.showMessageBox({ message: appPathCleaned }))
1121
-
1122
- var elevateExe = interface_exe ( pathToElevator , [ launchParameter ] , {
1123
- windowsVerbatimArguments : true ,
1124
- shell : true ,
1125
- detached : true
1126
- } ) ;
1127
-
1128
- app . exit ( ) ;
1124
+ requestLauncherAsAdmin ( ) ;
1125
+ } ) ;
1126
+
1127
+ ipcMain . on ( 'get-is-launcher-admin' , async ( event , arg ) => {
1128
+ var isAdmin = await privileges . isRunningAsAdministrator ( ) ;
1129
+ win . webContents . send ( 'send-is-launcher-admin' , isAdmin ) ;
1129
1130
} ) ;
1130
1131
1131
1132
ipcMain . on ( 'close-launcher' , ( event , arg ) => {
1132
1133
app . exit ( ) ;
1133
1134
} ) ;
1135
+
1136
+ // LAUNCHER AUTO UPDATER //
1137
+
1138
+ autoUpdater . autoDownload = false ;
1139
+ const autoUpdaterLoggingPrefix = '[Launcher AutoUpdater]' ;
1140
+
1141
+ autoUpdater . on ( 'checking-for-update' , ( ) => {
1142
+ console . info ( autoUpdaterLoggingPrefix , 'checking-for-update' ) ;
1143
+ } )
1144
+ autoUpdater . on ( 'update-available' , ( ev , info ) => {
1145
+ console . info ( autoUpdaterLoggingPrefix , 'update-available' , info ) ;
1146
+ win . webContents . send ( 'checked-for-launcher-updates' , { 'updateAvailable' : true } ) ;
1147
+ } )
1148
+ autoUpdater . on ( 'update-not-available' , ( ev , info ) => {
1149
+ console . info ( autoUpdaterLoggingPrefix , 'update-not-available' , info ) ;
1150
+ win . webContents . send ( 'checked-for-launcher-updates' , { 'updateAvailable' : false } ) ;
1151
+ } )
1152
+ autoUpdater . on ( 'error' , ( ev , err ) => {
1153
+ console . info ( autoUpdaterLoggingPrefix , 'error' , err ) ;
1154
+ } )
1155
+ autoUpdater . on ( 'download-progress' , ( ev , progressObj ) => {
1156
+ console . info ( autoUpdaterLoggingPrefix , 'download-progress' , progressObj ) ;
1157
+ } )
1158
+ autoUpdater . on ( 'update-downloaded' , ( ev , info ) => {
1159
+ console . info ( autoUpdaterLoggingPrefix , 'update-downloaded' ) ;
1160
+ console . info ( autoUpdaterLoggingPrefix , 'Attempting to install.' ) ;
1161
+ autoUpdater . quitAndInstall ( true , true ) ;
1162
+ } ) ;
1163
+
1164
+ ipcMain . on ( 'check-for-launcher-updates' , async ( event , arg ) => {
1165
+ autoUpdater . checkForUpdates ( ) ;
1166
+ } ) ;
1167
+
1168
+ ipcMain . on ( 'request-launcher-auto-update' , async ( event , arg ) => {
1169
+ win . webContents . send ( 'launcher-auto-updater-running' ) ;
1170
+ autoUpdater . downloadUpdate ( ) ;
1171
+ } ) ;
1172
+
1173
+ // END LAUNCHER AUTO UPDATER //
0 commit comments