Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First attempt at browserify and aw-client-js
- Loading branch information
1 parent
6b7ed08
commit 26502f7
Showing
11 changed files
with
105 additions
and
123 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
[submodule "media"] | ||
path = media | ||
url = https://github.com/ActivityWatch/media.git | ||
[submodule "aw-client-js"] | ||
path = aw-client-js | ||
url = git@github.com:ActivityWatch/aw-client-js.git |
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,5 +1,13 @@ | ||
.PHONY: build | ||
.PHONY: build install | ||
|
||
install: | ||
npm install | ||
(cd aw-client-js; npm install; npm run compile) | ||
|
||
update: | ||
npm run build | ||
|
||
# This is what Google and Mozilla wants us to upload when we release a new version to the Addon "store" | ||
build: | ||
zip -r -FS ./aw-watcher-web.zip manifest.json app/ media/ | ||
build: install | ||
npm run build | ||
zip -r -FS ./aw-watcher-web.zip manifest.json static/ out/ media/ |
This file was deleted.
Oops, something went wrong.
Submodule aw-client-js
added at
bb6b5a
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"dependencies": { | ||
"browserify": "^16.2.2" | ||
}, | ||
"scripts": { | ||
"build": "browserify src/*.js > out/app.js" | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,74 @@ | ||
"use strict"; | ||
|
||
var AWClient = require("../aw-client-js/out/aw-client.js").AWClient; | ||
|
||
|
||
var client = { | ||
testing: null, | ||
awc: null, | ||
lastSyncSuccess: true, | ||
|
||
setup: function() { | ||
console.log("Setting up client"); | ||
// Check if in dev mode | ||
chrome.management.getSelf(function(info) { | ||
console.log(info); | ||
client.testing = info.installType === "development"; | ||
console.log("testing: " + client.testing); | ||
|
||
client.awc = new AWClient("aw-client-web", client.testing); | ||
client.createBucket(); | ||
|
||
// Needed in order to show testing information in popup | ||
chrome.storage.local.set({"testing": client.testing}); | ||
}); | ||
}, | ||
|
||
getBucketId: function() { | ||
// TODO: This works for Chrome and Firefox, but is a bit hacky and wont work in the general case | ||
var browserName = /(Chrome|Firefox)\/([0-9.]+)/.exec(navigator.userAgent)[1]; | ||
return "aw-watcher-web-" + browserName.toLowerCase(); | ||
}, | ||
|
||
createBucket: function(){ | ||
if (this.testing === null) | ||
return; | ||
// TODO: We might want to get the hostname somehow, maybe like this: | ||
// https://stackoverflow.com/questions/28223087/how-can-i-allow-firefox-or-chrome-to-read-a-pcs-hostname-or-other-assignable | ||
var bucket_id = this.getBucketId(); | ||
var eventtype = "web.tab.current"; | ||
var hostname = "unknown"; | ||
|
||
client.awc.createBucket(bucket_id, eventtype, hostname) | ||
.catch( (err) => { | ||
console.error("Failed to create bucket ("+err.response.status+"): "+err.response.data.message); | ||
} | ||
); | ||
}, | ||
|
||
sendHeartbeat: function(timestamp, data, pulsetime) { | ||
if (this.testing === null) | ||
return; | ||
|
||
var payload = {"data": data, "timestamp": timestamp.toISOString()}; | ||
this.awc.heartbeat(this.getBucketId(), pulsetime, payload).then( | ||
(res) => { | ||
client.lastSyncSuccess = true; | ||
chrome.storage.local.set({"lastSync": new Date().toISOString()}); | ||
}, (err) => { | ||
if(client.lastSyncSuccess) { | ||
chrome.notifications.create({ | ||
"type": "basic", | ||
"iconUrl": chrome.extension.getURL("media/logo/logo.png"), | ||
"title": "Unable to send event to server", | ||
"message": "Please ensure that ActivityWatch is running", | ||
}); | ||
client.lastSyncSuccess = false; | ||
} | ||
console.error("Status code: " + err.response.status + ", response: " + err.response.data.message); | ||
} | ||
); | ||
} | ||
}; | ||
|
||
module.exports = client; |
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
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
File renamed without changes.