Added config for extension, updated a lot of things to use config. Updated icons.

This commit is contained in:
Mario Basic
2015-06-13 19:27:35 +02:00
parent 1a2bac7cc3
commit 3331d187b6
11 changed files with 433 additions and 337 deletions

View File

@@ -3,20 +3,11 @@ import $ from 'jquery';
import currentTimestamp from './helpers/currentTimestamp.js';
import changeExtensionIcon from './helpers/changeExtensionIcon.js';
var in_array = require('./helpers/in_array');
var config = require('./config.js');
class WakaTime {
tabsWithDevtoolsOpen = [];
constructor(props) {
this.detectionIntervalInSeconds = 60; //default
this.loggingType = 'domain'; //default
this.heartbeatApiUrl = 'https://wakatime.com/api/v1/users/current/heartbeats';
this.currentUserApiUrl = 'https://wakatime.com/api/v1/users/current';
this.tabsWithDevtoolsOpen = [];
}
@@ -33,7 +24,7 @@ class WakaTime {
var deferredObject = $.Deferred();
$.ajax({
url: this.currentUserApiUrl,
url: config.currentUserApiUrl,
dataType: 'json',
success: (data) => {
@@ -42,7 +33,7 @@ class WakaTime {
},
error: (xhr, status, err) => {
console.error(this.currentUserApiUrl, status, err.toString());
console.error(config.currentUserApiUrl, status, err.toString());
deferredObject.resolve(false);
}
@@ -61,12 +52,12 @@ class WakaTime {
if (data !== false) {
chrome.storage.sync.get({
loggingEnabled: true
loggingEnabled: config.loggingEnabled
}, (items) => {
if (items.loggingEnabled === true) {
changeExtensionIcon();
changeExtensionIcon(config.colors.allGood);
chrome.idle.queryState(this.detectionIntervalInSeconds, (newState) => {
chrome.idle.queryState(config.detectionIntervalInSeconds, (newState) => {
if (newState === 'active') {
// Get current tab URL.
@@ -81,7 +72,7 @@ class WakaTime {
});
}
else {
changeExtensionIcon('red');
changeExtensionIcon(config.colors.notLogging);
}
});
}
@@ -89,7 +80,7 @@ class WakaTime {
// User is not logged in.
// Change extension icon to red color.
changeExtensionIcon('red');
changeExtensionIcon(config.colors.notSignedIn);
}
});
}
@@ -123,7 +114,7 @@ class WakaTime {
var deferredObject = $.Deferred();
chrome.storage.sync.get({
loggingType: this.loggingType
loggingType: config.loggingType
}, function (items) {
deferredObject.resolve(items.loggingType);
});
@@ -181,7 +172,7 @@ class WakaTime {
var deferredObject = $.Deferred();
$.ajax({
url: this.heartbeatApiUrl,
url: config.heartbeatApiUrl,
dataType: 'json',
contentType: 'application/json',
method: method,
@@ -193,7 +184,7 @@ class WakaTime {
},
error: (xhr, status, err) => {
console.error(this.heartbeatApiUrl, status, err.toString());
console.error(config.heartbeatApiUrl, status, err.toString());
deferredObject.resolve(this);

View File

@@ -62,7 +62,7 @@ class MainList extends React.Component {
</div>
);
}
else
else if(this.props.loggingEnabled === false && this.props.loggedIn === true)
{
return (
<div className="panel panel-default">

View File

@@ -6,22 +6,19 @@ import NavBar from './NavBar.react.js';
import MainList from './MainList.react.js';
import changeExtensionIcon from '../helpers/changeExtensionIcon.js';
import WakaTimeOriginal from '../WakaTime.js';
var config = require('../config.js');
class WakaTime extends React.Component {
constructor(props) {
super(props);
this.logoutUserUrl = 'https://wakatime.com/logout';
this.state = {
user: {
full_name: null,
email: null,
photo: null
},
loggedIn: false,
loggingEnabled: false
};
}
state = {
user: {
full_name: null,
email: null,
photo: null
},
loggedIn: false,
loggingEnabled: config.loggingEnabled
};
componentDidMount() {
@@ -32,14 +29,14 @@ class WakaTime extends React.Component {
if (data !== false) {
chrome.storage.sync.get({
loggingEnabled: false
loggingEnabled: config.loggingEnabled
}, (items) => {
this.setState({loggingEnabled: items.loggingEnabled});
if (items.loggingEnabled === true) {
changeExtensionIcon();
changeExtensionIcon(config.colors.allGood);
}
else {
changeExtensionIcon('red');
changeExtensionIcon(config.colors.notLogging);
}
});
@@ -53,7 +50,7 @@ class WakaTime extends React.Component {
});
}
else {
changeExtensionIcon('red');
changeExtensionIcon(config.colors.notSignedIn);
}
});
@@ -63,7 +60,7 @@ class WakaTime extends React.Component {
var deferredObject = $.Deferred();
$.ajax({
url: this.logoutUserUrl,
url: config.logoutUserUrl,
method: 'GET',
success: () => {
@@ -72,7 +69,7 @@ class WakaTime extends React.Component {
},
error: (xhr, status, err) => {
console.error(this.logoutUserUrl, status, err.toString());
console.error(config.logoutUserUrl, status, err.toString());
deferredObject.resolve(this);
}
@@ -94,7 +91,7 @@ class WakaTime extends React.Component {
loggingEnabled: false
});
changeExtensionIcon('red');
changeExtensionIcon(config.colors.notSignedIn);
});
}
@@ -104,7 +101,7 @@ class WakaTime extends React.Component {
loggingEnabled: false
});
changeExtensionIcon('red');
changeExtensionIcon(config.colors.notLogging);
chrome.storage.sync.set({
loggingEnabled: false
@@ -116,7 +113,7 @@ class WakaTime extends React.Component {
loggingEnabled: true
});
changeExtensionIcon();
changeExtensionIcon(config.colors.allGood);
chrome.storage.sync.set({
loggingEnabled: true

25
assets/js/config.js Normal file
View File

@@ -0,0 +1,25 @@
export default {
// Time for idle state of the browser
// The user is considered idle if there was
// no activity in the browser for x seconds
detectionIntervalInSeconds: 60,
//default logging type
loggingType: 'domain',
// By default logging is enabled
loggingEnabled: true,
// Url to which to send the heartbeat
heartbeatApiUrl: 'https://wakatime.com/api/v1/users/current/heartbeats',
// Url from which to detect if the user is logged in
currentUserApiUrl: 'https://wakatime.com/api/v1/users/current',
// The url to logout the user from wakatime
logoutUserUrl: 'https://wakatime.com/logout',
// Different colors for different states of the extension
colors: {
allGood: '',
notLogging: 'gray',
notSignedIn: 'red',
lightTheme: 'white'
},
// Default theme
theme: 'light'
};

View File

@@ -1,6 +1,6 @@
/**
* It changes the extension icon color.
* Supported values are: 'red', 'white' and ''.
* Supported values are: 'red', 'white', 'gray' and ''.
*/
export default function changeExtensionIcon(color = '') {
@@ -9,7 +9,7 @@ export default function changeExtensionIcon(color = '') {
if (color !== '') {
color = '-' + color;
path = './graphics/wakatime-logo-48' + color + '.png';
path = './graphics/wakatime-logo-38' + color + '.png';
chrome.browserAction.setIcon({
path: path
@@ -21,14 +21,14 @@ export default function changeExtensionIcon(color = '') {
theme: 'light'
}, function (items) {
if (items.theme == 'light') {
path = './graphics/wakatime-logo-48.png';
path = './graphics/wakatime-logo-38.png';
chrome.browserAction.setIcon({
path: path
});
}
else {
path = './graphics/wakatime-logo-48-white.png';
path = './graphics/wakatime-logo-38-white.png';
chrome.browserAction.setIcon({
path: path

View File

@@ -2,6 +2,8 @@
global.jQuery = require('jquery');
require('bootstrap');
var config = require('./config');
import $ from "jquery";
function detectCheckedRadio(name) {
@@ -47,9 +49,9 @@ function save_options(e) {
function restore_options() {
// Use default value color = 'red' and likesColor = true.
chrome.storage.sync.get({
theme: 'light',
theme: config.theme,
blacklist: '',
loggingType: 'domain'
loggingType: config.loggingType
}, function (items) {
document.getElementById('theme').value = items.theme;
document.getElementById('blacklist').value = items.blacklist;