@@ -3,9 +3,10 @@ import { exec } from "child_process";
33import fs from "fs" ;
44import os from "os" ;
55import path from "path" ;
6- import sudo from "sudo-prompt" ;
6+ import sudo from "@vscode/ sudo-prompt" ;
77
88const isWindows = os . platform ( ) === "win32" ;
9+ const serviceName = "atest1" ;
910
1011const sudoOptions = {
1112 name : "Aorus Laptop Fan Control" ,
@@ -16,7 +17,15 @@ const sudoOutputHandler: Parameters<(typeof sudo)["exec"]>[2] = (
1617 stdout ,
1718) => {
1819 if ( error ) {
19- console . error ( error ) ;
20+ if ( error . message . includes ( "already exists" ) ) {
21+ console . log ( "Service already exists." ) ;
22+ } else if ( error . message . includes ( "grant permission" ) ) {
23+ console . log ( "Please re-run and give permission to run." ) ;
24+ } else if ( error . message . includes ( "does not exist" ) ) {
25+ console . log ( "Service doesn't exist." ) ;
26+ } else {
27+ console . error ( error ) ;
28+ }
2029 return ;
2130 }
2231
@@ -35,20 +44,22 @@ switch (process.argv[2]) {
3544 ) ;
3645 break ;
3746 case "install-as-sudo" :
47+ console . log ( "Registering the service..." ) ;
3848 service . add (
39- "alfc" ,
49+ serviceName ,
4050 {
41- args : [ "run" ] ,
51+ args : [ process . argv [ 1 ] , "run" ] ,
4252 dependencies : isWindows ? [ "Winmgmt" ] : [ "acpi_call" ] ,
4353 } ,
4454 ( error ) => {
4555 if ( error ) {
4656 throw error ;
4757 }
4858
59+ console . log ( "Starting service..." ) ;
4960 const serviceStartCommand = isWindows
50- ? "net start alfc"
51- : " service alfc start" ;
61+ ? "net start " + serviceName
62+ : ` service ${ serviceName } start` ;
5263 exec ( serviceStartCommand , async ( error ) => {
5364 if ( error ) {
5465 throw error ;
@@ -59,7 +70,9 @@ switch (process.argv[2]) {
5970 }
6071
6172 console . log ( "Done." ) ;
62- require ( "react-dev-utils/openBrowser" ) ( "http://localhost:5522" ) ;
73+ import ( "open" ) . then ( ( { default : open } ) => {
74+ open ( "http://localhost:5522" ) ;
75+ } ) ;
6376 } ) ;
6477 } ,
6578 ) ;
@@ -75,14 +88,16 @@ switch (process.argv[2]) {
7588 ) ;
7689 break ;
7790 case "uninstall-as-sudo" : {
91+ console . log ( "Stopping service..." ) ;
7892 const serviceStopCommand = isWindows
79- ? "net stop alfc"
80- : " service alfc stop" ;
93+ ? "net stop " + serviceName
94+ : ` service ${ serviceName } stop` ;
8195 exec ( serviceStopCommand , ( ) => {
8296 // exec would possibly error if the service is already stopped.
8397 // But we don't care about that and will simply attempt to remove the serivce.
8498
85- service . remove ( "alfc" , ( error ) => {
99+ console . log ( "Removing service..." ) ;
100+ service . remove ( serviceName , ( error ) => {
86101 if ( error ) {
87102 throw error ;
88103 }
@@ -93,6 +108,7 @@ switch (process.argv[2]) {
93108 break ;
94109 }
95110 case "run" :
111+ // Stop the service when the OS requests it.
96112 service . run ( function ( ) {
97113 service . stop ( 0 ) ;
98114 } ) ;
@@ -110,7 +126,11 @@ switch (process.argv[2]) {
110126
111127 process . chdir ( __dirname ) ;
112128 process . env . NODE_ENV = "production" ;
113- require ( "./fancontrol" ) ;
129+
130+ new Promise ( ( resolve ) => {
131+ setTimeout ( resolve , Number . MAX_SAFE_INTEGER ) ;
132+ } ) ;
133+ // require("./fancontrol");
114134 break ;
115135 default :
116136 console . error ( "If you can read this, either you or I did something wrong." ) ;
0 commit comments