diff --git a/.babelrc b/.babelrc new file mode 100755 index 00000000..ed737afe --- /dev/null +++ b/.babelrc @@ -0,0 +1,5 @@ +{ + "presets": ["es2015"], + "minified": true, + "comments": false +} diff --git a/.gitignore b/.gitignore old mode 100644 new mode 100755 index 179f9be8..b917a025 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ node_modules/ *.lock release-builds/ -dist/ \ No newline at end of file +dest/ +dist/*.js \ No newline at end of file diff --git a/README.md b/README.md old mode 100644 new mode 100755 diff --git a/Screenshots/Screenshot-v1.0.2-1.png b/Screenshots/Screenshot-v1.0.2-1.png old mode 100644 new mode 100755 diff --git a/Screenshots/Screenshot-v1.0.2-2.png b/Screenshots/Screenshot-v1.0.2-2.png old mode 100644 new mode 100755 diff --git a/Screenshots/Screenshot-v1.0.2-3.png b/Screenshots/Screenshot-v1.0.2-3.png old mode 100644 new mode 100755 diff --git a/Screenshots/Screenshot-v1.0.2-4.png b/Screenshots/Screenshot-v1.0.2-4.png old mode 100644 new mode 100755 diff --git a/Screenshots/Screenshot-v1.0.2-5.png b/Screenshots/Screenshot-v1.0.2-5.png old mode 100644 new mode 100755 diff --git a/Screenshots/header1.png b/Screenshots/header1.png old mode 100644 new mode 100755 diff --git a/Screenshots/stacer.gif b/Screenshots/stacer.gif old mode 100644 new mode 100755 diff --git a/dist/index.html b/dist/index.html new file mode 100755 index 00000000..21c82be0 --- /dev/null +++ b/dist/index.html @@ -0,0 +1,286 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
+ + + + + + + + + + + + + + +
+ There are updates currently available. + +
+ +
+
+ + + +
+ +
+
+ + + +
+
+
+ System Startup Applications +
+ +
+
+
+ + + +
+ +
+
+ + + +
+ +
+
+ + +
+ Loading... + +
+ + + + + + + +
+ +
+ + + + + + +
+ + + diff --git a/libs/fast-search.js b/libs/fast-search.js deleted file mode 100644 index 6500b657..00000000 --- a/libs/fast-search.js +++ /dev/null @@ -1,52 +0,0 @@ -jQuery.fn.fastLiveFilter = function(list, options) { - // Options: input, list, timeout, callback - options = options || {}; - list = jQuery(list); - var input = this; - var lastFilter = ''; - var timeout = options.timeout || 0; - var callback = options.callback || function() {}; - - var keyTimeout; - - var lis = list.children(); - var len = lis.length; - var oldDisplay = len > 0 ? lis[0].style.display : "block"; - callback(len); // do a one-time callback on initialization to make sure everything's in sync - - input.change(function() { - // var startTime = new Date().getTime(); - var filter = input.val().toLowerCase(); - var li, innerText; - var numShown = 0; - for (var i = 0; i < len; i++) { - li = lis[i]; - innerText = !options.selector ? - (li.textContent || li.innerText || "") : - $(li).find(options.selector).text(); - - if (innerText.toLowerCase().indexOf(filter) >= 0) { - if (li.style.display == "none") { - li.style.display = oldDisplay; - } - numShown++; - } else { - if (li.style.display != "none") { - li.style.display = "none"; - } - } - } - callback(numShown); - // var endTime = new Date().getTime(); - // console.log('Search for ' + filter + ' took: ' + (endTime - startTime) + ' (' + numShown + ' results)'); - return false; - }).keydown(function() { - clearTimeout(keyTimeout); - keyTimeout = setTimeout(function() { - if( input.val() === lastFilter ) return; - lastFilter = input.val(); - input.change(); - }, timeout); - }); - return this; // maintain jQuery chainability -} diff --git a/package.json b/package.json old mode 100644 new mode 100755 index e8488d1e..16394f9b --- a/package.json +++ b/package.json @@ -1,15 +1,17 @@ { "name": "Stacer", "productName": "Stacer", - "version": "1.0.3", - "description": "Ubuntu System Optimizer", + "version": "1.0.4", + "description": "Ubuntu System Optimizer and Monitoring", "license": "MIT", "main": "main.js", "author": "Oguzhan Inan ", "keywords": [ + "linux", "ubuntu", "system", - "optimizer" + "optimizer", + "monitoring" ], "repository": { "type": "git", @@ -23,22 +25,28 @@ "appId": "Stacer" }, "dependencies": { - "cpu-usage": "^0.1.0", - "diskspace": "^1.0.3", + "chokidar": "^1.6.1", "electron": "^1.4.15", "jquery": "^3.1.1", "progressbar.js": "^1.0.1", + "properties-reader": "^0.0.15", "sudo-prompt": "^6.2.1", "systeminformation": "^3.13.0" }, "scripts": { "start": "electron .", + "build": "babel src/ -d dist/", + "clean": "rm dist/*.js", "package-x86": "electron-packager . --overwrite --platform=linux --arch=ia32 --icon=assets/img/icon.png --prune=true --out=release-builds --version=1.4.15", - "package-x64": "electron-packager . --overwrite --platform=linux --arch=x64 --icon=assets/img/icon.png --prune=true --out=release-builds --version=1.4.15", - "build-x86": "electron-installer-debian --src release-builds/Stacer-linux-ia32/ --arch i386 --dest dist/installers/ --icon assets/img/icon.png", - "build-x64": "electron-installer-debian --src release-builds/Stacer-linux-x64/ --arch amd64 --dest dist/installers/ --icon assets/img/icon.png", + "package-x64": "electron-packager . --overwrite --platform=linux --arch=x64 --icon=assets/img/icon.png --prune=true --out=release-builds --version=1.4.15", + "build-x86": "electron-installer-debian --src release-builds/Stacer-linux-ia32/ --arch i386 --dest dest/installers/ --icon assets/img/icon.png", + "build-x64": "electron-installer-debian --src release-builds/Stacer-linux-x64/ --arch amd64 --dest dest/installers/ --icon assets/img/icon.png", "release-x86": "npm run package-x86 && npm run build-x86", "release-x64": "npm run package-x64 && npm run build-x64", - "clean": "rm -r release-builds/ dist/" + "clean-package": "rm -r release-builds/ dest/" + }, + "devDependencies": { + "babel-cli": "^6.22.2", + "babel-preset-es2015": "^6.22.0" } -} +} \ No newline at end of file diff --git a/pages/startup-apps.html b/pages/startup-apps.html deleted file mode 100644 index 195be424..00000000 --- a/pages/startup-apps.html +++ /dev/null @@ -1,11 +0,0 @@ -
-
- System Startup Applications -
- -
-
    - -
-
-
diff --git a/pages/system-cleaner.html b/pages/system-cleaner.html deleted file mode 100644 index 00dd30db..00000000 --- a/pages/system-cleaner.html +++ /dev/null @@ -1,34 +0,0 @@ -
- -
- -
-
-
    - -
-
-
- - - diff --git a/pages/system-services.html b/pages/system-services.html deleted file mode 100644 index 433c45a2..00000000 --- a/pages/system-services.html +++ /dev/null @@ -1,12 +0,0 @@ -
-
- System Services - -
- -
-
    - -
-
-
diff --git a/pages/uninstaller.html b/pages/uninstaller.html deleted file mode 100644 index 405cd5f1..00000000 --- a/pages/uninstaller.html +++ /dev/null @@ -1,12 +0,0 @@ -
-
- System Installed Packages - -
- -
-
    - -
-
-
diff --git a/src/stacer.js b/src/stacer.js deleted file mode 100644 index 78478652..00000000 --- a/src/stacer.js +++ /dev/null @@ -1,725 +0,0 @@ -const {app, ipcRenderer} = require('electron') - -const fs = require('fs') -const os = require('os') -const libCpuUsage = require('cpu-usage') -const diskspace = require('diskspace') -const si = require('systeminformation') -const { spawn, spawnSync } = require('child_process') -const prog = require('progressbar.js') -const sudo = require('sudo-prompt') - -var { prop, commands } = require('./src/config') -require('./libs/fast-search') -require('./libs/amaran.min') - -var memInfo = "" -var dTotal = "" -var dUsed = "" - -var down = 0 -var up = 0 - -/* - * Functions - */ -function setCount( id , count ) -{ - $(id).parent("label").find("span").find("span").text("(" + count + ")") -} - -function removeElement( element ) -{ - $(element).parent("label").parent("li").remove() -} - -function getFileName( element ) -{ - return $(element).parent("label").find("span").text() -} - -function getCheckeds( name ) -{ - return $(".tdl-content input[name=" + name + "]:checked") -} - -function getLength( name ) -{ - return $(".tdl-content input[name=" + name + "]").length -} - -function Command( command ) -{ - return 'bash -c "' + command + '"' -} - -function selectAllCheckbox( allId , checkName ) -{ - $("#" + allId).change(function() { - if ($("#" + allId).is(':checked')) - $("input[name=" + checkName + "]").prop("checked", true) - else - $("input[name=" + checkName + "]").prop("checked", false) - }) -} - -function addListTitle( checkID , title ) -{ - $("#cleaner-table > .tdl-content > ul") - .append( '
  • ' ) -} - -function addListElement( name , text ) -{ - $("#cleaner-table > .tdl-content > ul") - .append( '
  • ' ) -} - -function showMessage( message ) -{ - $.amaran({ - 'message': message, - 'position': 'top right' - }) -} - -function addSystemClearAnimate( id ) -{ - $( id ).parent("label").append( systemClearAnimate() ).find("i").hide() - return $( id ).parent("label") -} - - -function circleBar(id, clr, durat) -{ - var cBar = new prog.SemiCircle(id, { - strokeWidth: 12, - color: clr, - trailColor: prop.trailColor, - easing: 'easeInOut', - duration: durat, - svgStyle: { - marginTop: '10px' - }, - step: function(state, bar) - { - if(id == "#cpu-cont") - { - bar.setText(Math.round(bar.value() * 100) + "%") - } - else if(id == "#mem-cont") - { - bar.setText(memInfo) - } - else if(id == "#disk-cont") - { - bar.setText(dUsed + "/" + dTotal) - } - } - }); - cBar.text.style.color = "#fff" - cBar.text.style.paddingBottom = "20px" - - return cBar -} - - -//---- Page Functions -----// - -function networkBars() -{ - - /* - * Get default network interface name - */ - var defaultNetwork = ""; - si.networkInterfaceDefault(function ( name ) { defaultNetwork = name }) - - /* - * Network down speed - */ - var downBar = new prog.Line("#down-bar", { - strokeWidth: 5, - easing: 'easeInOut', - duration: prop.networkBarsDuration, - color: prop.netwrokBarColor, - trailColor: prop.trailColor, - text: { - style: { - color: '#999', - position: 'absolute', - right: '0', - marginTop: '5px' - } - }, - step: function(state, bar) - { - bar.setText(Math.abs(down).toString() + ' kB/s') - } - }); - - /* - * Network upload speed - */ - var upBar = new prog.Line("#up-bar", { - strokeWidth: 5, - easing: 'easeInOut', - duration: prop.networkBarsDuration, - color: prop.netwrokBarColor, - trailColor: prop.trailColor, - text: { - style: { - color: '#999', - position: 'absolute', - right: '0', - marginTop: '5px' - } - }, - step: function(state, bar) - { - bar.setText(Math.abs(up).toString() + ' kB/s') - } - }); - - /* - * Network down and upload speed setter - */ - setInterval( () => - { - si.networkStats(defaultNetwork, (data) => - { - down = (data.rx_sec / 1024).toFixed(2) - up = (data.tx_sec / 1024).toFixed(2) - downBar.animate(down / 2000) - upBar.animate(up / 2000) - }) - }, prop.networkBarsDuration); -} - -function systemInformationBars() -{ - /* - * Create the circle bars - */ - var cpuBar = circleBar("#cpu-cont", prop.cpuBarColor , prop.cpuDuration) - - var memBar = circleBar("#mem-cont", prop.memBarColor , prop.memDuration) - - var diskBar = circleBar("#disk-cont",prop.diskBarColor , prop.diskDuration) - - /* - * Cpu value setter - */ - libCpuUsage(prop.cpuDuration, function(val) { cpuBar.animate(val / 100) }); - - /* - * Memory value setter - */ - function prettySize( size ){ - return ( size / ( Math.pow(1024, 3) ) ).toFixed(2) - } - - setInterval( function() - { - si.mem( ( ram ) => - { - var usedMem = ram.total - ram.available - var totalMem = ram.total - - - memInfo = prettySize(usedMem) + ' / ' + prettySize(totalMem) + "GB" - memBar.animate(usedMem / totalMem) - }) - - }, prop.memDuration); - - /* - * Disk value setter - */ - function diskInfo() - { - diskspace.check('/', function(err, total, free, status) - { - var used = total-free - dUsed = (used / 1000000000).toFixed(1) - dTotal = (total / 1000000000).toFixed(1) + "GB" - diskBar.animate( used / total ); - }); - } - diskInfo() - setInterval(diskInfo, prop.diskDuration) - - - //System info - si.osInfo(function(sys) - { - $(".system-info ul").append($("
  • ").append("Hostname: " + os.hostname())) - $(".system-info ul").append($("
  • ").append("Platform: " + os.platform() + os.arch())) - $(".system-info ul").append($("
  • ").append("Distribution: " + sys.distro )) - $(".system-info ul").append($("
  • ").append("Total RAM: " + prettySize( os.totalmem() ) + " GB")) - $(".system-info ul").append($("
  • ").append("CPU Model: " + os.cpus()[0].model)) - $(".system-info ul").append($("
  • ").append("CPU Cores: " + os.cpus().length)) - }) -} - -/* - * Stacer Navigation Menu - */ -function navigationClicks() -{ - var active = "nav-active" - $("#nav > li > label").click( function() - { - if( ! $(this).hasClass(active) ) - { - var data = $(this).attr("id") - $(".content").hide("fast") - $('div[data-nav=' + data + ']').show("fast") - - $("#nav > li > label").removeClass( active ) - $(this).addClass( active ) - } - }) -} - -/* - * Dashboard Page - */ -function dashboardPage() -{ - systemInformationBars() - - networkBars() -} - -/* - * System Cleaner Page - */ -function systemCleanerPage() -{ - /* - * System Scan Button Click - */ - $("#system-scan-btn").click(function() - { - // Reset Scan Results - setCount("#crash-rep-choose" , 0) - setCount("#apt-cache-choose" , 0) - setCount("#sys-logs-choose" , 0) - setCount("#app-cache-choose" , 0) - - // Clear List - $("#cleaner-table > .tdl-content > ul").html(""); - - /* - * System apt cache scanning - */ - if ($("#apt-cache-choose").is(":checked")) - { - fs.readdir( commands.aptCacheScanning , 'utf8', (err, files) => - { - addListTitle( "select-all-cache" , "Select All (Apt Caches)" ) - - if ( ! err ) - { - var i = 1 - files.filter( ( file ) => file.endsWith('.deb') ) - .forEach( ( file ) => - { - addListElement( "apt-cache-check" , file ) - setCount("#apt-cache-choose" , i++) - }) - - selectAllCheckbox('select-all-cache', 'apt-cache-check') - } - else - { - console.log(err); - } - }) - } - - /* - * System crash reports scanning - */ - if ($("#crash-rep-choose").is(":checked")) - { - fs.readdir( commands.crashReportsScanning , 'utf8', (err, files) => - { - addListTitle( "select-all-crash" , "Select All (Crash Reports)" ) - - if ( ! err ) - { - var i = 1 - files.forEach( ( file ) => - { - addListElement( "crash-check" , file ) - setCount("#crash-rep-choose" , i++) - }) - - selectAllCheckbox('select-all-crash', 'crash-check') - } - else - { - console.log(err); - } - }) - } - - /* - * System logs scanning - */ - if ($("#sys-logs-choose").is(":checked")) - { - fs.readdir( commands.systemLogsScanning , 'utf8', (err, files) => - { - addListTitle( "select-all-logs" , "Select All (System Logs)" ) - - if ( ! err ) - { - var i = 1 - files.forEach( ( file ) => - { - addListElement( "log-check" , file ) - setCount("#sys-logs-choose" , i++) - }) - - selectAllCheckbox('select-all-logs', 'log-check') - } - else - { - console.log(err); - } - }) - } - - /* - * System app cache scanning - */ - if ($("#app-cache-choose").is(":checked")) - { - fs.readdir( commands.appCacheScanning , 'utf8', (err, files) => - { - addListTitle( "select-all-app-cache" , "Select All (App Caches)" ) - - if ( ! err ) - { - var i = 1 - files.forEach( ( file ) => - { - addListElement( "app-cache-check" , file ) - setCount("#app-cache-choose" , i++) - }) - - selectAllCheckbox('select-all-app-cache', 'app-cache-check') - } - else - { - console.log(err); - } - }) - } - }) - - /* - * Clean Button Click - */ - $("#clean-btn").click(function() - { - /* - * App Cache Clean - */ - var appCheckeds = getCheckeds("app-cache-check") - var appLen = getLength("app-cache-check") - - if( appCheckeds.length != 0 ) - { - var filesToRemove = '' - appCheckeds.each(function(c, check) - { - const appCacheFile = getFileName(check) - - filesToRemove += ' rm -r ' + commands.appCacheScanning + appCacheFile + ';' - - removeElement(check) - setCount("#app-cache-choose" , --appLen) - }) - - sudo.exec( Command(filesToRemove) , {name: 'Stacer'}, - (error, stdout, stderr) => - { - - }) - } - - /* - * Apt Cache Clean - */ - var aptCheckeds = getCheckeds("apt-cache-check") - var aptLen = getLength("apt-cache-check") - - if( aptCheckeds.length != 0 ) - { - var filesToRemove = '' - aptCheckeds.each( (c, check) => - { - const cacheFile = getFileName(check) - - filesToRemove += ' rm ' + commands.aptCacheScanning + cacheFile + ';' - - setCount("#apt-cache-choose" , --aptLen) - removeElement(check) - }) - - sudo.exec( Command(filesToRemove) , {name: 'Stacer'}, - (error, stdout, stderr) => - { - - }) - } - - /* - * Logs Clean - */ - var logCheckeds = getCheckeds("log-check") - var logLen = getLength("log-check") - - if( logCheckeds.length != 0 ) - { - var filesToRemove = '' - logCheckeds.each(function(c, check) - { - const logFile = getFileName(check) - - filesToRemove += ' rm -r ' + commands.systemLogsScanning + logFile + ';' - - removeElement(check) - setCount("#sys-logs-choose" , --logLen) - }) - - sudo.exec( Command(filesToRemove) , {name: 'Stacer'}, - (error, stdout, stderr) => - { - - }) - } - - /* - * System Crash Clean - */ - var crashCheckeds = getCheckeds("crash-check") - var crashLen = getLength("crash-check") - - if( crashCheckeds.length != 0 ) - { - var filesToRemove = '' - crashCheckeds.each(function(c, check) - { - const crashFile = getFileName(check) - - filesToRemove += ' rm ' + commands.crashReportsScanning + crashFile + ';' - - removeElement(check) - setCount("#crash-rep-choose" , --crashLen) - }) - - sudo.exec( Command(filesToRemove) , {name: 'Stacer'}, - (error, stdout, stderr) => - { - - }) - } - }) -} - -/* - * Startup Apps Page - */ -function startupAppsPage() -{ - try - { - fs.readdir( commands.autostartApps, (err, files) => { - - files.filter( ( file ) => file.endsWith('.desktop') ) - .forEach(( file ) => - { - try - { - var data = fs.readFileSync(commands.autostartApps + '/' + file).toString() - - var appName = data.match(/\Name=.*/g)[0].replace('Name=', '') - $('#startup-apps-list').append( $("
  • ").append( appName , $("").attr("name" , file) ) ) - } - catch(err){} - }) - - $("#startup-apps-list li a").click( function() - { - var _this = $(this) - var startupApp = _this.attr("name") - var appName = _this.parent("li").text() - - try - { - fs.unlink( commands.autostartApps + startupApp ) - - _this.parent("li").remove() - showMessage( appName + " is deleted." ) - } - catch(er){} - - }) - }) - } - catch (error) { - console.log(error) - } - -} - -/* - * Services Page - */ -function servicesPage() -{ - var isServ = false - - const services = spawn('bash', ['-c', commands.getAllService]) - - services.stdout.on('data', ( data ) => { - data = data.toString().split('\n').filter( ( s ) => s != '') - - const serviceCount = data.length - - data.forEach( ( serv ) => - { - var service = serv.substring(1) - var isRun = serv.substring(0, 1) == "+" ? "checked" : "" - - $("#system-service-list").append( - '
  • ' + service + - ''+ - '
  • ') - }) - - $("#system-service-list li .switch").change(function() - { - if ( ! isServ) - { - isServ = true - var _this = $(this) - var task = _this.is(":checked") ? "start" : "stop" - var service = _this.parent("li").text() - - sudo.exec( Command( "service " + service + " " + task ) , {name: 'Stacer'}, - (error, stdout, stderr) => - { - if(stderr) - showMessage( "Operation not successful." ) - else - showMessage( service + ' service ' + task + (_this.is(":checked") ? 'ed' : 'ped') ) - - isServ = false - }) - - $("#system-service-title span").text("System Services (" + serviceCount + ")") - } - else - { - showMessage( "Another process continues." ) - } - }) - - $('#system-service-search').fastLiveFilter('#system-service-list') - }) - -} - -/* - * Uninstaller Page - */ -function uninstallerPage() -{ - var isInstalling = false - - const packages = spawn('bash', ['-c', commands.getInstalledPackages]) - - packages.stdout.on('data', (data) => { - data = data.toString().split('\n').filter( ( s ) => s != '') - - var packagesCount = data.length - - data.forEach( ( package ) => - { - $("#installed-packages-list") - .append( $("
  • ").append( package , $("") ) ) - - }) - - $("#installed-packages-list li a").click(function() - { - if ( ! isInstalling) - { - isInstalling = true - var _this = $(this) - _this.addClass("loader") - var appName = _this.parent("li").text() - - - sudo.exec( Command( commands.removePackage + appName ) , {name: 'Stacer'}, - (error, stdout, stderr) => - { - if(stderr) - showMessage( "Operation not successful." ) - else - { - _this.parent("li").remove() - showMessage( appName + " package uninstalled." ) - $("#installed-packages-title span").text("System Installed Packages (" + --packagesCount + ")") - } - - isInstalling = false - }) - } - else - { - showMessage( "Another process continues." ) - } - }) - - $("#installed-packages-title span").text("System Installed Packages (" + packagesCount + ")") - $('#packages-search').fastLiveFilter('#installed-packages-list') - }) - - -} - -//---- Page Functions -----// - -/* - * Main - */ -$( document ).ready(function() -{ - navigationClicks() - - dashboardPage() - - $("#system-cleaner-content").load( "./pages/system-cleaner.html", () => { systemCleanerPage() }) - - $("#startup-apps-content").load( "./pages/startup-apps.html", () => { startupAppsPage() }) - - $("#system-service-content").load( "./pages/system-services.html", () => { servicesPage() }) - - $("#uninstaller-content").load( "./pages/uninstaller.html", () => { uninstallerPage() }) - - setTimeout( ( ) => { - $('#loading').remove() - }, 3500); - -})