Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
bwp91 committed Nov 7, 2023
1 parent b5d6128 commit 3087249
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 29 deletions.
7 changes: 7 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
"@types/node": "^18.18.8",
"@types/node-schedule": "^2.1.2",
"@types/semver": "^7.5.4",
"@types/tail": "^2.2.2",
"@types/tar": "^6.1.7",
"@types/tcp-port-used": "^1.0.3",
"@types/unzipper": "^0.10.8",
Expand Down
32 changes: 14 additions & 18 deletions src/bin/hb-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,17 @@ export class HomebridgeServiceHelper {
public action: 'install' | 'uninstall' | 'start' | 'stop' | 'restart' | 'rebuild' | 'run' | 'add' | 'remove' | 'logs' | 'view' | 'update-node' | 'before-start' | 'status';
public selfPath = __filename;
public serviceName = 'Homebridge';
public storagePath;
public storagePath: string;
public usingCustomStoragePath = false;
public allowRunRoot = false;
public enableHbServicePluginManagement = false;
public asUser;
public asUser: string;
public addGroup: string;
private log: fs.WriteStream | NodeJS.WriteStream;
private homebridgeModulePath: string;
private homebridgePackage: { version: string; bin: { homebridge: string } };
private homebridgeBinary: string;
private homebridge: child_process.ChildProcessWithoutNullStreams;
private homebridgeStopped = true;
private homebridgeOpts = ['-I'];
private homebridgeCustomEnv = {};
private uiBinary: string;
Expand Down Expand Up @@ -204,7 +203,7 @@ export class HomebridgeServiceHelper {
/**
* Logger function, log to homebridge.log file when possible
*/
public logger(msg, type: 'info' | 'succeed' | 'fail' | 'warn' = 'info') {
public logger(msg: string, type: 'info' | 'succeed' | 'fail' | 'warn' = 'info') {
if (this.action === 'run') {
msg = `\x1b[37m[${new Date().toLocaleString()}]\x1b[0m ` +
'\x1b[36m[HB Supervisor]\x1b[0m ' + msg;
Expand Down Expand Up @@ -374,7 +373,7 @@ export class HomebridgeServiceHelper {
// start the ui
await this.runUi();

// tell the ui what homebridge we are running initialy (this is refreshed when Homebridge is restarted)
// tell the ui what homebridge we are running initially (this is refreshed when Homebridge is restarted)
if (this.ipcService && this.homebridgePackage) {
this.ipcService.setHomebridgeVersion(this.homebridgePackage.version);
}
Expand Down Expand Up @@ -416,8 +415,6 @@ export class HomebridgeServiceHelper {
* Starts homebridge as a child process, sending the log output to the homebridge.log
*/
private runHomebridge() {
this.homebridgeStopped = false;

if (!this.homebridgeBinary || !fs.pathExistsSync(this.homebridgeBinary)) {
this.logger('Could not find Homebridge. Make sure you have installed homebridge using the -g flag then restart.', 'fail');
this.logger('npm install -g --unsafe-perm homebridge', 'fail');
Expand Down Expand Up @@ -509,7 +506,6 @@ export class HomebridgeServiceHelper {
* @param signal
*/
private handleHomebridgeClose(code: number, signal: string) {
this.homebridgeStopped = true;
this.logger(`Homebridge Process Ended. Code: ${code}, Signal: ${signal}`);

this.checkForStaleHomebridgeProcess();
Expand Down Expand Up @@ -655,7 +651,7 @@ export class HomebridgeServiceHelper {
// See https://github.com/sebhildebrandt/systeminformation/issues/775#issuecomment-1741836906
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
const defaultInterface = (await si.networkInterfaces()).find(x => x.iface === defaultAdapter);
const defaultInterface = (await si.networkInterfaces()).find((x: any) => x.iface === defaultAdapter);

console.log('\nManage Homebridge by going to one of the following in your browser:\n');

Expand Down Expand Up @@ -724,7 +720,7 @@ export class HomebridgeServiceHelper {
if (!Array.isArray(currentConfig.platforms)) {
currentConfig.platforms = [];
}
let uiConfigBlock = currentConfig.platforms.find((x) => x.platform === 'config');
let uiConfigBlock = currentConfig.platforms.find((x: any) => x.platform === 'config');

// if the config block does not exist, then create it
if (!uiConfigBlock) {
Expand All @@ -743,7 +739,7 @@ export class HomebridgeServiceHelper {
restartRequired = true;
}

// if doing an install, make sure the port number matches the value passed in by the user
// if doing an installation, make sure the port number matches the value passed in by the user
if (this.action === 'install') {
// correct the port
if (uiConfigBlock.port !== this.uiPort) {
Expand Down Expand Up @@ -861,7 +857,7 @@ export class HomebridgeServiceHelper {
}

/**
* Returns true if running on the Homebridge Rasbpian Image
* Returns true if running on the Homebridge Raspbian Image
*/
private async isRaspbianImage(): Promise<boolean> {
return os.platform() === 'linux' && await fs.pathExists('/etc/hb-ui-port');
Expand All @@ -886,7 +882,7 @@ export class HomebridgeServiceHelper {
return envPort;
}

// otherwise return the defaul port
// otherwise return the default port
return this.uiPort;
}

Expand Down Expand Up @@ -1225,7 +1221,7 @@ export class HomebridgeServiceHelper {
const spinner = ora(`Installing Node.js ${targetVersion}`).start();

try {
await tar.x(extractConfig);
tar.x(extractConfig);
spinner.succeed(`Installed Node.js ${targetVersion}`);
} catch (e) {
spinner.fail(e.message);
Expand All @@ -1252,7 +1248,7 @@ export class HomebridgeServiceHelper {
}

/**
* Check the current status of the Homebridge UI by calling it's API
* Check the current status of the Homebridge UI by calling its API
*/
private async checkStatus() {
this.logger(`Testing hb-service is running on port ${this.uiPort}...`);
Expand All @@ -1272,7 +1268,7 @@ export class HomebridgeServiceHelper {
}

/**
* Parse an npm package and version string
* Parse an NPM package and version string
* Based on: https://github.com/egoist/parse-package-name
*/
private parseNpmPackageString(input: string) {
Expand All @@ -1296,7 +1292,7 @@ export class HomebridgeServiceHelper {
/**
* Install / Remove a plugin using pnpm (supported platforms only)
*/
private async npmPluginManagement(args) {
private async npmPluginManagement(args: any[]) {
if (!this.enableHbServicePluginManagement) {
this.logger('Plugin management is not supported on your platform using hb-service.', 'fail');
process.exit(1);
Expand Down Expand Up @@ -1326,7 +1322,7 @@ export class HomebridgeServiceHelper {
this.logger(`Path does not exist: "${cwd}"`, 'fail');
}

let cmd;
let cmd: string;

if (process.env.UIX_USE_PNPM === '1') {
cmd = `pnpm -C "${cwd}" ${action} ${target.name}`;
Expand Down
4 changes: 2 additions & 2 deletions src/bin/platforms/darwin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ export class DarwinInstaller extends BasePlatform {
}

/**
* Resolves the target user home directory when running the install command as SUDO
* Resolves the target user home directory when running the installation command as SUDO
*/
private getUserHomeDir() {
try {
Expand Down Expand Up @@ -253,7 +253,7 @@ export class DarwinInstaller extends BasePlatform {
const downloadUrl = `https://nodejs.org/dist/${job.target}/node-${job.target}-darwin-${process.arch}.tar.gz`;
const targetPath = path.dirname(path.dirname(process.execPath));

// only allow updates when installed using the offical Node.js installer / Homebridge package
// only allow updates when installed using the official Node.js installer / Homebridge package
if (targetPath !== '/usr/local' && !targetPath.startsWith('/Library/Application Support/Homebridge/node-')) {
this.hbService.logger(`Cannot update Node.js on your system. Non-standard installation path detected: ${targetPath}`, 'fail');
process.exit(1);
Expand Down
2 changes: 1 addition & 1 deletion src/bin/platforms/freebsd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ export class FreeBSDInstaller extends BasePlatform {
}

/**
* Allows the homebridge user to shutdown and restart the server from the UI
* Allows the homebridge user to shut down and restart the server from the UI
* There is no need for full sudo access when running using hb-service
*/
private setupSudo() {
Expand Down
6 changes: 3 additions & 3 deletions src/bin/platforms/linux.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ export class LinuxInstaller extends BasePlatform {
'/usr/local/lib/node_modules',
'/usr/lib/node_modules'
].includes(path.dirname(process.env.UIX_BASE_PATH))) {
// systemd has a 90 second default timeout in the pre-start jobs
// systemd has a 90-second default timeout in the pre-start jobs
// terminate this task after 60 seconds to be safe
setTimeout(() => {
process.exit(0);
Expand Down Expand Up @@ -553,7 +553,7 @@ export class LinuxInstaller extends BasePlatform {
}

/**
* Allows the homebridge user to shutdown and restart the server from the UI
* Allows the homebridge user to shut down and restart the server from the UI
* There is no need for full sudo access when running using hb-service
*/
private setupSudo() {
Expand Down Expand Up @@ -689,7 +689,7 @@ export class LinuxInstaller extends BasePlatform {
}

/**
* Setup the run-parts path and scripts
* Set up the run-parts path and scripts
* This allows users to define their own scripts to run before Homebridge starts/restarts
* The default script will ensure the homebridge storage path has the correct permissions each time Homebridge starts
*/
Expand Down
2 changes: 1 addition & 1 deletion src/bin/platforms/win32.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ export class Win32Installer extends BasePlatform {
.on('finish', () => {
return resolve(nssmPath);
})
.on('error', (err) => {
.on('error', (err: any) => {
return reject(err);
});
}).catch(async (e) => {
Expand Down
15 changes: 13 additions & 2 deletions src/modules/log/log.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export class LogService {
/**
* Socket handler
* @param client
* @param size
*/
public connect(client: EventEmitter, size: LogTermSize) {
this.ending = false;
Expand Down Expand Up @@ -203,8 +204,11 @@ export class LogService {
interval: 200,
},
});
} else if (this.nativeTail.listenerCount('line') === 0) {
this.nativeTail.watch();
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
} else { // @ts-expect-error
if (this.nativeTail.listenerCount('line') === 0) {
this.nativeTail.watch();
}
}

// watch for lines and emit to client
Expand All @@ -223,10 +227,17 @@ export class LogService {
const onEnd = () => {
this.ending = true;

// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
this.nativeTail.removeListener('line', onLine);

// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
this.nativeTail.removeListener('error', onError);

// stop watching the file if there are no other watchers
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
if (this.nativeTail.listenerCount('line') === 0) {
this.nativeTail.unwatch();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
<div class="modal-footer">
<div class="w-100 text-right">
<p class="small mb-0">
<a class="font-italic" href="https://github.com/homebridge/homebridge-config-ui-x/wiki/Developers:-Donation-Links"
<a class="font-italic" href="https://github.com/homebridge/homebridge/wiki/Donation-Links"
target="_blank" rel="noopener noreferrer" translate="plugins.donate.message_learn_more">
</a>
</p>
</div>
</div>
</form>
</div>
</div>

0 comments on commit 3087249

Please sign in to comment.