Skip to content

Commit b53ffa3

Browse files
committed
Converted to use non experimental API
1 parent 01795a8 commit b53ffa3

File tree

2 files changed

+22
-12
lines changed

2 files changed

+22
-12
lines changed

Diff for: eventPage.js

+20-10
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,10 @@ initStorage();
66

77
// init storage engine on load
88
function initStorage() {
9-
storage.get('enabled', function(result){
10-
console.log(result);
11-
if(typeof result['enabled'] === 'undefined') {
9+
storage.get('enabled', function(result){
10+
//console.log(result['enabled']);
11+
if(result['enabled'] === undefined) {
1212
enabled = true;
13-
var not = webkitNotifications.createNotification('caffeineEnabled.png', 'Caffeine Enabled!', 'Your Chromebook now has a good supply of Caffeine and will stay awake forever! (meaning that automatic power management has been disabled) You can always take away the Caffeine (in effect turn back on the automatic power management) by clicking / toggling the Caffeine extension icon.');
14-
not.show();
1513
} else {
1614
enabled = result['enabled'];
1715
}
@@ -26,27 +24,39 @@ function initStorage() {
2624
function saveStorage() {
2725
storage.set({'enabled':enabled}, function() { console.log('saved in chrome.storage.local: '+enabled); });
2826
}
27+
//shows a notification telling the user that Caffeine has been enabled
28+
function showNotification() {
29+
chrome.notifications.create("welcome", {
30+
type: "basic",
31+
iconUrl: "caffeineEnabled.png",
32+
title: "Caffeine Enabled!",
33+
message: "Your Chromebook now has a good supply of Caffeine and will stay awake forever! (meaning that automatic power management has been disabled) You can always take away the Caffeine (in effect turn back on the automatic power management) by clicking / toggling the Caffeine extension icon."
34+
}, function (notificationId) {
35+
//callback needs to be included for notifications to work!
36+
});
37+
}
2938
// toggles the power management to off
3039
function caffeineEnable() {
31-
chrome.experimental.power.requestKeepAwake( function(result) {});
40+
chrome.power.requestKeepAwake("display");
3241
chrome.browserAction.setIcon({path: '/caffeineEnabled.png'});
3342
//chrome.browserAction.setBadgeText({ text: "c" });
34-
console.log('requestKeepAwake: '+enabled);
43+
//console.log('requestKeepAwake: '+enabled);
3544
saveStorage();
45+
showNotification();
3646
}
3747
// re-engages the system power management
3848
function caffeineDisable() {
39-
chrome.experimental.power.releaseKeepAwake( function(result) {});
49+
chrome.power.releaseKeepAwake();
4050
chrome.browserAction.setIcon({path: '/caffeineDisabled.png'});
4151
//chrome.browserAction.setBadgeText({ text: '0'});
42-
console.log('releaseKeepAwake: '+enabled);
52+
//console.log('releaseKeepAwake: '+enabled);
4353
saveStorage();
4454
}
4555
//listens for events when storage changes (debug)
4656
chrome.storage.onChanged.addListener(function(changes, namespace) {
4757
for (key in changes) {
4858
var storageChange = changes[key];
49-
console.log('Storage key "%s" in namespace "%s" changed. Old value was: %s, new value is: %s', key, namespace, storageChange.oldValue, storageChange.newValue);
59+
//console.log('Storage key "%s" in namespace "%s" changed. Old value was: %s, new value is: %s', key, namespace, storageChange.oldValue, storageChange.newValue);
5060
}
5161
});
5262
// listens for events when the button is toggled

Diff for: manifest.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "Caffeine",
3-
"version": "2",
3+
"version": "2.1",
44
"manifest_version": 2,
55

66
"description": "Gives your ChromeBook the juice to stay awake!",
@@ -18,7 +18,7 @@
1818

1919
"offline_enabled": true,
2020

21-
"permissions": ["experimental", "storage", "notifications"],
21+
"permissions": ["power", "storage", "notifications"],
2222

2323
"web_accessible_resources": ["caffeineEnabled.png"]
2424
}

0 commit comments

Comments
 (0)