Skip to content

Commit

Permalink
changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Maigo Erit committed May 27, 2016
1 parent 589f7a2 commit 53972fd
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 14 deletions.
9 changes: 7 additions & 2 deletions app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ var mb = require('./tray')
var pluginMgr = require('./plugin-manager')
var backgroundService = require('./background.service')
var ipcMain = require('electron').ipcMain;
var config = require('./config')
//require('./lib/crash-handler')

var AutoLaunch = require('auto-launch');
Expand All @@ -17,6 +18,7 @@ appLauncher.isEnabled().then(function (enabled) {
if (enabled) {
return;
}
console.log('Enabling app launcher');
return appLauncher.enable()
}).then(function (err) {

Expand Down Expand Up @@ -76,16 +78,19 @@ app.on('activate-with-no-open-windows', function () {

/* Single Instance Check */
var iShouldQuit = app.makeSingleInstance(function (commandLine, workingDirectory) {
if (pluginMgr.windows['main-window']) {
if (pluginMgr.windows && pluginMgr.windows['main-window']) {
if (pluginMgr.windows['main-window'].isMinimized()) {
pluginMgr.windows['main-window'].restore();
}
pluginMgr.windows['main-window'].show();
pluginMgr.windows['main-window'].focus();
console.log('Focusing main window');
}
return true;
});
if (iShouldQuit) {
if (iShouldQuit && !config.isDev) {
console.log('Quiting instance.');
pluginMgr.removeAll();
app.quit();
return;
}
Expand Down
2 changes: 2 additions & 0 deletions app/assistive-access-el-capitan.osa
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
set sh to "sqlite3 \"/Library/Application Support/com.apple.TCC/TCC.db\" \"INSERT or REPLACE INTO access VALUES('kTCCServiceAccessibility','ee.trimatech.BackerTimetracker',0,1,1,NULL,NULL);\""
do shell script sh with administrator privileges
2 changes: 2 additions & 0 deletions app/assistive-access-osx.osa
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
set sh to "sqlite3 \"/Library/Application Support/com.apple.TCC/TCC.db\" \"INSERT or REPLACE INTO access VALUES('kTCCServiceAccessibility','ee.trimatech.BackerTimetracker',0,1,1,NULL);\""
do shell script sh with administrator privileges
21 changes: 21 additions & 0 deletions app/background.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

var app = require('electron').app;

var compareVersion = require('compare-version');
var bunyan = require('bunyan');
var log;

Expand Down Expand Up @@ -317,6 +318,8 @@ BackgroundService.onResume = function () {
isSleeping = false;
};

var isOsxScriptRunned = false;

BackgroundService.saveForegroundWindowTitle = function () {

//'darwin', 'freebsd', 'linux', 'sunos' or 'win32'
Expand Down Expand Up @@ -344,6 +347,22 @@ BackgroundService.saveForegroundWindowTitle = function () {

if (typeof active_a[0] !== "undefined") {
active.app = active_a[0];
// isElCapitanScriptRunned = true;//some applications doe not have app, check only when started
}
if (active.app) {
isOsxScriptRunned = true;//some applications doe not have app, check only when started
}

if (process.platform === 'darwin' && isOsxScriptRunned === false) {
/*console.log('Running assistive-access-el-capitan.osa');
var access_script = "osascript " + path.join(__dirname, "assistive-access-el-capitan.osa");
if (compareVersion(require('os').release(), '10.11.0') === -1) {
access_script = "osascript " + path.join(__dirname, "assistive-access-osx.osa");
}
isOsxScriptRunned = true;
exec(access_script, function (error, stdout, stderr) {
console.log('Assistive access: ', stdout, error, stderr);
});*/
}

if (typeof active_a[1] !== "undefined") {
Expand Down Expand Up @@ -394,6 +413,8 @@ BackgroundService.saveUserIdleTime = function () {
script = "sh " + path.join(__dirname, "get-user-idle-time.mac.sh");
} else if (process.platform === 'win32') {
script = 'powershell.exe "& ""' + path.join(__dirname, "get-user-idle-time.ps1") + '"""';


} else if (process.platform === 'linux') {
script = "sh " + path.join(__dirname, "get-user-idle-time.linux.sh");
}
Expand Down
4 changes: 2 additions & 2 deletions app/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "backer-timetracker",
"version": "1.0.9",
"version": "1.0.12",
"description": "Track your time by monitoring your active windows and idle time",
"main": "app.js",
"author": "Maigo Erit <[email protected]>",
Expand All @@ -9,11 +9,11 @@
"type": "git",
"url": "[email protected]:MayGo/backer-timetracker.git"
},

"dependencies": {
"async": "^1.5.2",
"auto-launch": "^2.0.1",
"bunyan": "^1.7.1",
"compare-version": "^0.1.2",
"js-data": "^2.9.0",
"js-data-nedb": "^1.0.0",
"lodash": "^4.5.0",
Expand Down
26 changes: 17 additions & 9 deletions app/plugin-manager.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@

var path = require('path')
var ipc = require("electron").ipcMain;
var ipc = require("electron").ipcMain;
//var BrowserWindow = require("electron").browserWindow;
const {BrowserWindow} = require('electron');
var _ = require('lodash')
Expand Down Expand Up @@ -60,10 +59,13 @@ PluginManager.prototype.load = function (name, opt) {
});

oWindow.on('close', function () {
console.log("Closing window");
console.log(this.windows[name]);
this.windows[name] = null;
}.bind(this))
if (this.windows) {
console.log("Closing window");
console.log(this.windows[name]);
this.windows[name] = null;
}

}.bind(this));

// open devtools
if (config.isDev && opt.showDevtools !== false)
Expand Down Expand Up @@ -101,7 +103,7 @@ PluginManager.prototype.hide = function (name) {
*/
PluginManager.prototype.toggle = function (name) {
console.log(this.windows[name]);
if (this.windows[name] && this.windows[name].isVisible())
if (this.windows[name] && this.windows[name].isVisible())
this.hide(name)
else
this.show(name)
Expand Down Expand Up @@ -139,13 +141,19 @@ PluginManager.prototype._initEvents = function () {
ipc.on('set-on-top', function (ev, name, flag) {
self.setOnTop(name, flag)
})

}
};

/**
* Remove all windows objects
*/
PluginManager.prototype.removeAll = function () {
_.forIn(this.windows, function (win, k) {
if (win) {
console.log('Closing window...', win, k);
win.close();
}

});
this.windows = null
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "backer-timetracker",
"version": "1.0.9",
"version": "1.0.12",
"description": "Track your time by monitoring your active windows and idle time",
"main": "app/app.js",
"scripts": {
Expand Down

0 comments on commit 53972fd

Please sign in to comment.