diff --git a/gadget/images/logo.png b/gadget/images/logo.png index 4d40eac..aeabc26 100644 Binary files a/gadget/images/logo.png and b/gadget/images/logo.png differ diff --git a/gadget/index.html b/gadget/index.html index e275fc7..aa3803a 100644 --- a/gadget/index.html +++ b/gadget/index.html @@ -1,6 +1,22 @@ -

Wakatime Hangout

+
+
+ +
+
+ +
+
+ +
+
+ +
+
+
+ + + +
+
+
-
- - -
\ No newline at end of file diff --git a/gadget/scripts/wakatime.js b/gadget/scripts/wakatime.js index 7fed2cf..960b690 100644 --- a/gadget/scripts/wakatime.js +++ b/gadget/scripts/wakatime.js @@ -1,86 +1,139 @@ -/* global gapi, gadgets, $ */ - -var logoUrl = 'https://wakatime.com/static/img/wakatime-white-120.png'; -var overlayEffect = null; - -function sendHeartbeat(file, time, project, language, isWrite, lines) { - // TODO -} - -function createTextOverlay(string) { - // Create a canvas to draw on - var canvas = document.createElement('canvas'); - canvas.setAttribute('width', 166); - canvas.setAttribute('height', 100); - - var context = canvas.getContext('2d'); - - // Draw background - //context.fillStyle = '#BBB'; - //context.fillRect(0,0,166,50); - - // Draw text - context.font = '16pt Impact'; - context.lineWidth = 6; - context.lineStyle = '#000'; - context.fillStyle = '#FFF'; - context.textAlign = 'center'; - context.textBaseline = 'bottom'; - context.strokeText(string, canvas.width / 2, canvas.height / 2); - context.fillText(string, canvas.width / 2, canvas.height / 2); - - return canvas.toDataURL(); -} - -function showOverlay() { - var options = { - 'scale': { - 'magnitude': 0.5, - 'reference': gapi.hangout.av.effects.ScaleReference.WIDTH - } - }; - //var overlayImage = gapi.hangout.av.effects.createImageResource(logoUrl); - var overlayImage = gapi.hangout.av.effects.createImageResource(createTextOverlay('Time: 00:00:23')); - overlayEffect = overlayImage.createOverlay(options); - overlayEffect.setPosition(-0.5, 0.45); - overlayEffect.setVisible(true); -} - -function startApp() { - gapi.hangout.onair.onYouTubeLiveIdReady.add( - function(eventObject) { +/* global angular, gapi, gadgets, moment, $ */ + +(function() { + 'use strict'; + + angular.module('wakatime', ['ngCookies']).config(function ($rootScope) { + // Wait for gadget to load. + gadgets.util.registerOnLoadHandler(function() { + gapi.hangout.onApiReady.add( + function(e) { + $rootScope.$broadcast('hangout.ready', e); + }); }); + }).controller('WakatimeCtrl', function ($scope, $http, Hangout) { + $scope.edit = true; + $scope.running = false; + $scope.logo = 'https://avatars2.githubusercontent.com/u/4814844?v=3&s=200'; - gapi.hangout.onParticipantsChanged.add( - function(eventObject) { - }); + $scope.start = function() { + Hangout.start(); + }; - gapi.hangout.onair.onBroadcastingChanged.add( - function(eventObject) { - }); + $scope.stop = function() { + Hangout.stop(); + }; - gapi.hangout.onair.onNewParticipantInBroadcastChanged.add( - function(eventObject) { - }); + $scope.reset = function() { + Hangout.reset(); + }; - gapi.hangout.onTopicChanged.add( - function(eventObject) { + $scope.$watch('showLogo', function(newValue, oldValue) { + Hangout.showLogo(newValue); }); - gapi.hangout.onTopicChanged.add( - function(eventObject) { - }); - -} - -function init() { - // When API is ready... - gapi.hangout.onApiReady.add( - function(eventObj) { + $scope.sendHeartbeat = function(file, time, project, language, isWrite, lines) { // TODO - showOverlay(); + }; + }).factory('Hangout', function ($rootScope, $interval) { + var overlays = {}; + var watch; + var time = 0; + + function createTextOverlay(string) { + // Create a canvas to draw on + var canvas = document.createElement('canvas'); + canvas.setAttribute('width', 166); + canvas.setAttribute('height', 100); + + var context = canvas.getContext('2d'); + + // Draw text + context.font = '16pt Impact'; + context.lineWidth = 6; + context.lineStyle = '#000'; + context.fillStyle = '#FFF'; + context.textAlign = 'center'; + context.textBaseline = 'bottom'; + context.strokeText(string, canvas.width / 2, canvas.height / 2); + context.fillText(string, canvas.width / 2, canvas.height / 2); + + return canvas.toDataURL(); + } + + var Hangout = { + init: function() { + gapi.hangout.onParticipantsChanged.add( + function(e) { + $rootScope.$broadcast('hangout.participant', e); + }); + + gapi.hangout.onair.onBroadcastingChanged.add( + function(e) { + $rootScope.$broadcast('hangout.broadcasting', e); + }); + + gapi.hangout.onair.onNewParticipantInBroadcastChanged.add( + function(e) { + }); + + gapi.hangout.onTopicChanged.add( + function(e) { + $rootScope.$broadcast('hangout.topic', e); + }); + }, + start: function() { + if(watch) { + return; + } else { + watch = $interval(function() { + time += 5000; + Hangout.setTime(moment(time).format('HH:mm:ss')); + }, 5000) + } + }, + stop: function() { + if(watch) { + $interval.cancel(watch); + watch = undefined; + } + }, + reset: function() { + time = 0; + }, + setTime: function(time) { + if(overlays['time']) { + overlays['time'].dispose(); + } + overlays['time'] = gapi.hangout.av.effects.createImageResource(createTextOverlay(time)); + overlays['time'] = overlays['time'].createOverlay({ + 'scale': { + 'magnitude': 0.5, + 'reference': gapi.hangout.av.effects.ScaleReference.WIDTH + } + }); + overlays['time'].setPosition(-0.5, 0.45); + overlays['time'].setVisible(true); + }, + showLogo: function(show) { + if(!overlays['logo']) { + overlays['logo'] = gapi.hangout.av.effects.createImageResource('https://avatars2.githubusercontent.com/u/4814844?v=3&s=200'); + overlays['logo'] = overlays['logo'].createOverlay({ + 'scale': { + 'magnitude': 0.5, + 'reference': gapi.hangout.av.effects.ScaleReference.WIDTH + } + }); + overlays['logo'].setPosition(0.5, 0.45); + } + overlays['logo'].setVisible(show); + } + }; + + $rootScope.$on('hangout.ready', function(e) { + Hangout.init(); }); -} -// Wait for gadget to load. -gadgets.util.registerOnLoadHandler(init); + return Hangout; + }); +})(); \ No newline at end of file diff --git a/gadget/styles/wakatime.css b/gadget/styles/wakatime.css index 09e6b57..e69de29 100644 --- a/gadget/styles/wakatime.css +++ b/gadget/styles/wakatime.css @@ -1,4 +0,0 @@ -body { - color: #ffffff; - background-color: #000000; -} \ No newline at end of file diff --git a/gadget/wakatime.xml b/gadget/wakatime.xml index f02ee6c..b613e2e 100644 --- a/gadget/wakatime.xml +++ b/gadget/wakatime.xml @@ -20,14 +20,17 @@ + - + + + diff --git a/gulpfile.js b/gulpfile.js index 06049cc..3b99199 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -14,7 +14,7 @@ gulp.task('merge', function () { //.pipe($.inject(gulp.src(['./gadget/**/*.js', './gadget/**/*.css'], {read: false}))) return gulp.src('./gadget/wakatime.xml') - .pipe($.replace(/]*>/g, function(s, filename) { + .pipe($.replace(/]*>/g, function(s, filename) { var style = fs.readFileSync('./gadget/styles/' + filename, 'utf8'); return ''; })) diff --git a/public/wakatime.xml b/public/wakatime.xml index 211fc5f..4a53fcc 100644 --- a/public/wakatime.xml +++ b/public/wakatime.xml @@ -20,6 +20,7 @@ +