Caret/js/main.js

86 lines
2.4 KiB
JavaScript
Raw Normal View History

2013-12-23 18:27:33 +00:00
chrome.version = window.navigator.appVersion.match(/Chrome\/(\d+)/)[1] * 1 || 0;
2013-09-13 22:57:57 +00:00
require([
"command",
2014-01-21 06:14:46 +00:00
"storage/settingsProvider",
"ui/dialog",
"ui/projectManager",
"ui/keys",
"fileManager",
"ui/menus",
"ui/palette",
"api",
"storage/syncfile"
2013-09-16 20:52:54 +00:00
], function(command, Settings, dialog) {
2013-08-20 00:53:03 +00:00
2013-08-23 23:03:46 +00:00
var frame = chrome.app.window.current();
command.on("app:exit", function() {
frame.close();
});
2013-09-13 22:57:57 +00:00
var setTheme = function() {
2014-01-21 06:14:46 +00:00
Settings.pull("user").then(function(data) {
var themes = {
"dark": "css/caret-dark.css",
"light": "css/caret.css"
};
var theme = data.user.uiTheme || "light";
var url = themes[theme] || themes.dark;
document.find("#theme").setAttribute("href", url);
});
2013-09-13 22:57:57 +00:00
}
var loadedModules = {
"editor": false,
"fileManager": false,
"sessions": false
};
2013-09-13 22:57:57 +00:00
2013-09-02 01:28:31 +00:00
//the settings manager may also fire init:restart to re-init components after startup
command.fire("init:startup", function(mod) {
//ignore callback in non-essential modules
if (typeof loadedModules[mod] == "undefined") return;
loadedModules[mod] = true;
for (var key in loadedModules) {
if (!loadedModules[key]) {
return;
}
}
//all specified modules are loaded, app is ready for init:complete
command.fire("init:complete");
});
2013-09-13 22:57:57 +00:00
command.on("init:restart", setTheme);
setTheme();
var updateID = "caret:update";
var checkUpdates = function(isManual) {
chrome.runtime.requestUpdateCheck(function(status, details) {
if (status == "update_available") {
chrome.runtime.onUpdateAvailable.addListener(function() {
chrome.notifications.create(updateID, {
type: "basic",
iconUrl: "icon-128.png",
title: "Caret: Update Available",
message: "An update to Caret version " + details.version + " is available. Would you like to update and restart now?",
buttons: [ { title: "Yes, update and restart" }, { title: "No thanks" }]
}, function(id) { updateID = id });
});
}
});
};
2014-01-21 06:14:46 +00:00
Settings.pull("user").then(function(cfg) {
if (cfg.user.promptForUpdates !== false) checkUpdates();
});
command.on("app:check-for-updates", checkUpdates);
chrome.notifications.onButtonClicked.addListener(function(id, index) {
if (id != updateID) return;
if (index == 0) {
chrome.runtime.reload();
}
});
2013-08-20 00:53:03 +00:00
});