-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Switched to ES Module - Allow service parameters to be specified in settings
- Loading branch information
Showing
7 changed files
with
202 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
{ | ||
"name": "disk-space-monitor", | ||
"version": "1.1.0", | ||
"type": "module", | ||
"version": "2.0.0", | ||
"description": "Monitor disk space usage and notify user by email or system notification", | ||
"main": "src/app.js", | ||
"exports": "src/app.js", | ||
"scripts": { | ||
"start": "node src/app.js", | ||
"preinstall": "npm install npm-platform-dependencies && npmpd", | ||
|
@@ -11,8 +12,7 @@ | |
}, | ||
"keywords": [ | ||
"disk space", | ||
"disk monitor", | ||
"disk space monitor" | ||
"monitor" | ||
], | ||
"author": "blu3mania <[email protected]>", | ||
"license": "Apache-2.0", | ||
|
@@ -25,7 +25,7 @@ | |
"url": "https://github.com/blu3mania/disk-space-monitor.git" | ||
}, | ||
"dependencies": { | ||
"chalk": "^4.1.2", | ||
"chalk": "^5.0.1", | ||
"diskusage": "^1.1.3", | ||
"node-notifier": "^10.0.1", | ||
"nodemailer": "^6.7.8" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,82 @@ | ||
'use strict'; | ||
import path from 'path'; | ||
import url from 'url'; | ||
|
||
const path = require('path'); | ||
const Service = require(process.platform === 'win32' ? 'node-windows' : process.platform === 'darwin' ? 'node-mac' : 'node-linux').Service; | ||
const { | ||
import { | ||
warning, | ||
info, | ||
verbose } = require('./print.js'); | ||
|
||
// Create a new service object. | ||
const svc = new Service({ | ||
name: 'Disk Space Monitor', | ||
description: 'Monotr disk space usage and notify user by email or Windows Toast.', | ||
script: `${path.join(__dirname, 'app.js')}`, | ||
nodeOptions: [ | ||
'--harmony', | ||
'--max_old_space_size=4096' | ||
] | ||
}); | ||
|
||
// Listen for the "install" event, which indicates the process is available as a service. | ||
svc.on('install', () => { | ||
verbose('Service installed.'); | ||
info('Starting service, please accept UAC prompts if any...'); | ||
svc.start(); | ||
}); | ||
|
||
svc.on('start', () => { | ||
verbose('Service started.'); | ||
}); | ||
|
||
svc.on('alreadyinstalled', () => { | ||
warning('Service is already installed!'); | ||
info('Starting the service in case it is not running, please accept UAC prompts if any...'); | ||
svc.start(); | ||
}); | ||
|
||
info('Installing service, please accept UAC prompts if any...'); | ||
svc.install(); | ||
verbose } from './print.js'; | ||
import settings from './settings.json' assert {type: 'json'}; | ||
|
||
main(); | ||
|
||
function main() { | ||
// Dynamically import the module we need depending on current OS | ||
switch (process.platform) { | ||
case 'win32': | ||
import('node-windows') | ||
.then(module => installService(module.Service)); | ||
break; | ||
|
||
case 'darwin': | ||
import('node-mac') | ||
.then(module => installService(module.Service)); | ||
break; | ||
|
||
default: | ||
import('node-linux') | ||
.then(module => installService(module.Service)); | ||
break; | ||
} | ||
} | ||
|
||
function installService(Service) { | ||
// Create a new service object. | ||
const __dirname = url.fileURLToPath(new URL('.', import.meta.url)); | ||
const svc = new Service({ | ||
name: settings.service?.name ?? 'Disk Space Monitor', | ||
description: 'Monotr disk space usage and notify user by email or Windows Toast.', | ||
script: `${path.join(__dirname, 'app.js')}`, | ||
nodeOptions: [ | ||
'--harmony', | ||
'--max_old_space_size=4096' | ||
] | ||
}); | ||
|
||
if (process.platform === 'win32') { | ||
if (settings.service?.account?.name && settings.service?.account?.password) { | ||
svc.logOnAs.account = settings.service.account.name; | ||
svc.logOnAs.password = settings.service.account.password; | ||
if (settings.service?.account?.domain) { | ||
svc.logOnAs.domain = settings.service.account.domain; | ||
} | ||
} | ||
} else if (process.platform !== 'darwin') { | ||
if (settings.service?.account?.user) { | ||
svc.user = settings.service.account.user; | ||
} | ||
|
||
if (settings.service?.account?.group) { | ||
svc.group = settings.service.account.group; | ||
} | ||
} | ||
|
||
// Listen for the "install" event, which indicates the process is available as a service. | ||
svc.on('install', () => { | ||
verbose('Service installed.'); | ||
info('Starting service, please accept UAC prompts if any...'); | ||
svc.start(); | ||
}); | ||
|
||
svc.on('start', () => { | ||
verbose('Service started.'); | ||
}); | ||
|
||
svc.on('alreadyinstalled', () => { | ||
warning('Service is already installed!'); | ||
info('Starting the service in case it is not running, please accept UAC prompts if any...'); | ||
svc.start(); | ||
}); | ||
|
||
info('Installing service, please accept UAC prompts if any...'); | ||
svc.install(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,7 @@ | ||
{ | ||
"service": { | ||
"name": "Disk Space Monitor" | ||
}, | ||
"disks": [ | ||
{ | ||
"path": "C:", | ||
|
Oops, something went wrong.