Skip to content

Commit

Permalink
Fix and simplify license checking
Browse files Browse the repository at this point in the history
  • Loading branch information
JoelBesada committed Oct 12, 2013
1 parent d7a102f commit bbe05e3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 17 deletions.
25 changes: 12 additions & 13 deletions extension/background.coffee
@@ -1,3 +1,5 @@
# TOOO: Clean up and refactor this into a class

LICENSE_ID = "fdocciflgajbbcgmnfifnmoamjgiefip"
activeTab = null

Expand Down Expand Up @@ -31,6 +33,7 @@ Events.$.on

"ready.app": ->
CommandStore.init()
checkLicense()

"open.settings": ->
chrome.tabs.create url: "options.html"
Expand All @@ -45,17 +48,13 @@ Events.$.on

error: Events.sendTrigger.bind Events, "executionError.commands", command

isLicensed = (callback) ->
port = chrome.runtime.connect LICENSE_ID

done = (result) ->
port.onMessage.removeListener yep
port.onDisconnect.removeListener nope
callback result
checkLicense = ->
isLicensed (result) ->
console.log "licensed", result
return if result
Events.sendTrigger "unlicensedUse.app"

yep = done.bind this, true
nope = done.bind this, false

port.postMessage true
port.onMessage.addListener yep
port.onDisconnect.addListener nope
isLicensed = (callback) ->
console.log "testing license", LICENSE_ID
chrome.runtime.sendMessage LICENSE_ID, "ping", (response) ->
callback !!response
6 changes: 2 additions & 4 deletions license/background.js
@@ -1,5 +1,3 @@
chrome.runtime.onConnectExternal.addListener(function(port) {
port.onMessage.addListener(function(msg) {
if (msg) port.postMessage(true);
});
chrome.runtime.onMessageExternal.addListener(function(message, sender, respond) {
respond(true);
});

0 comments on commit bbe05e3

Please sign in to comment.