1- const { exec } = require ( "child_process" ) ;
2- const fs = require ( "fs" ) ;
3- const os = require ( "os" ) ;
4- const service = require ( "os-service" ) ;
5- const path = require ( "path" ) ;
6- const sudo = require ( "sudo-prompt" ) ;
1+ import service from "@neuralegion/os-service" ;
2+ import { exec } from "child_process" ;
3+ import fs from "fs" ;
4+ import os from "os" ;
5+ import path from "path" ;
6+ import sudo from "sudo-prompt" ;
77
88const isWindows = os . platform ( ) === "win32" ;
99
1010const sudoOptions = {
1111 name : "Aorus Laptop Fan Control" ,
1212} ;
1313
14- const errorHandler = ( onSuccess ) => ( error ) => {
15- if ( error ) {
16- throw error ;
17- }
18-
19- onSuccess ( ) ;
20- } ;
21-
22- function sudoOutputHandler ( error , stdout ) {
14+ const sudoOutputHandler : Parameters < ( typeof sudo ) [ "exec" ] > [ 2 ] = (
15+ error ,
16+ stdout ,
17+ ) => {
2318 if ( error ) {
2419 console . error ( error ) ;
2520 return ;
2621 }
2722
2823 console . log ( stdout ) ;
29- }
24+ } ;
3025
3126switch ( process . argv [ 2 ] ) {
3227 case "install" :
@@ -43,25 +38,30 @@ switch (process.argv[2]) {
4338 service . add (
4439 "alfc" ,
4540 {
46- programArgs : [ "run" ] ,
41+ args : [ "run" ] ,
4742 dependencies : isWindows ? [ "Winmgmt" ] : [ "acpi_call" ] ,
4843 } ,
49- errorHandler ( ( ) => {
44+ ( error ) => {
45+ if ( error ) {
46+ throw error ;
47+ }
48+
5049 const serviceStartCommand = isWindows
5150 ? "net start alfc"
5251 : "service alfc start" ;
53- exec (
54- serviceStartCommand ,
55- errorHandler ( async ( ) => {
56- if ( isWindows ) {
57- await new Promise ( ( resolve ) => setTimeout ( resolve , 1000 * 25 ) ) ;
58- }
52+ exec ( serviceStartCommand , async ( error ) => {
53+ if ( error ) {
54+ throw error ;
55+ }
56+
57+ if ( isWindows ) {
58+ await new Promise ( ( resolve ) => setTimeout ( resolve , 1000 * 25 ) ) ;
59+ }
5960
60- console . log ( "Done." ) ;
61- require ( "react-dev-utils/openBrowser" ) ( "http://localhost:5522" ) ;
62- } ) ,
63- ) ;
64- } ) ,
61+ console . log ( "Done." ) ;
62+ require ( "react-dev-utils/openBrowser" ) ( "http://localhost:5522" ) ;
63+ } ) ;
64+ } ,
6565 ) ;
6666 break ;
6767 case "uninstall" :
@@ -82,12 +82,13 @@ switch (process.argv[2]) {
8282 // exec would possibly error if the service is already stopped.
8383 // But we don't care about that and will simply attempt to remove the serivce.
8484
85- service . remove (
86- "alfc" ,
87- errorHandler ( ( ) => {
88- console . log ( "Done." ) ;
89- } ) ,
90- ) ;
85+ service . remove ( "alfc" , ( error ) => {
86+ if ( error ) {
87+ throw error ;
88+ }
89+
90+ console . log ( "Done." ) ;
91+ } ) ;
9192 } ) ;
9293 break ;
9394 }
@@ -100,6 +101,7 @@ switch (process.argv[2]) {
100101 // On Linux, it'll go to the systemd logs.
101102 if ( isWindows ) {
102103 const access = fs . createWriteStream ( path . join ( __dirname , "service.log" ) ) ;
104+ // @ts -expect-error Undefined/null type mismatch: Type 'Error | null | undefined' is not assignable to type 'Error | undefined'.
103105 process . stdout . write = process . stderr . write = access . write . bind ( access ) ;
104106 process . on ( "uncaughtException" , function ( err ) {
105107 console . error ( err && err . stack ? err . stack : err ) ;
0 commit comments