mirror of
https://github.com/MatMoul/quickdial-webext.git
synced 2024-12-23 07:26:11 +00:00
Improvement: Speed start
This commit is contained in:
parent
1dd5409dd0
commit
55521d2d53
@ -3,60 +3,74 @@ var app = {}; // Shared app object with pages
|
||||
|
||||
core.init = function(){ // Init module
|
||||
core.Settings.init(function(){
|
||||
core.Messages.init();
|
||||
browser.runtime.sendMessage({ cmd: core.Messages.Commands.settingsChanged });
|
||||
core.GridNodes.sync(core.node, core.settings.grid.root, function(){
|
||||
core.Messages.init();
|
||||
browser.runtime.sendMessage({ cmd: 'SettingsChanged' });
|
||||
browser.runtime.sendMessage({ cmd: 'GridNodesLoaded' });
|
||||
browser.runtime.sendMessage({ cmd: core.Messages.Commands.gridNodesLoaded });
|
||||
core.Bookmarks.initListener();
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
core.Messages = {}; // Messages helper object
|
||||
core.Messages.Commands = {
|
||||
getSettings: 0,
|
||||
setSettings: 1,
|
||||
getNode: 2,
|
||||
setNodeIndex: 3,
|
||||
createBookmark: 4,
|
||||
createFolder: 5,
|
||||
deleteNode: 6,
|
||||
refreshNode: 7,
|
||||
capturePage: 8,
|
||||
settingsChanged: 100,
|
||||
gridNodesLoaded: 101
|
||||
};
|
||||
core.Messages.init = function(){ // Init Messages Listeners
|
||||
browser.runtime.onMessage.addListener(function(request, sender, sendResponse){
|
||||
console.log(request.cmd);
|
||||
switch(request.cmd){
|
||||
case 'GetSettings':
|
||||
case core.Messages.Commands.getSettings:
|
||||
sendResponse(core.settings);
|
||||
break;
|
||||
case 'SetSettings':
|
||||
case core.Messages.Commands.setSettings:
|
||||
core.settings = request.settings;
|
||||
core.Settings.save();
|
||||
sendResponse(core.settings);
|
||||
browser.runtime.sendMessage( { cmd: 'SettingsChanged' } );
|
||||
browser.runtime.sendMessage( { cmd: 'GridNodesLoaded' } );
|
||||
browser.runtime.sendMessage( { cmd: core.Messages.Commands.settingsChanged } );
|
||||
browser.runtime.sendMessage( { cmd: core.Messages.Commands.gridNodesLoaded } );
|
||||
break;
|
||||
case 'GetNode':
|
||||
case core.Messages.Commands.getNode:
|
||||
sendResponse(core.GridNodes.getNode(core.node, request.path.substr(1)));
|
||||
break;
|
||||
case 'SetNodeIndex':
|
||||
case core.Messages.Commands.setNodeIndex:
|
||||
core.GridNodes.setNodeIndex(core.GridNodes.getNode(core.node, request.path.substr(1)), request.index, request.newIndex, function(){
|
||||
browser.runtime.sendMessage( { cmd: 'GridNodesLoaded' } );
|
||||
browser.runtime.sendMessage( { cmd: core.Messages.Commands.gridNodesLoaded } );
|
||||
});
|
||||
break;
|
||||
case 'CreateBookmark':
|
||||
case core.Messages.Commands.createBookmark:
|
||||
core.GridNodes.createBookmark(core.GridNodes.getNode(core.node, request.path.substr(1)), request.url, request.title, function(){
|
||||
browser.runtime.sendMessage( { cmd: 'GridNodesLoaded' } );
|
||||
browser.runtime.sendMessage( { cmd: core.Messages.Commands.gridNodesLoaded } );
|
||||
});
|
||||
break;
|
||||
case 'CreateFolder':
|
||||
case core.Messages.Commands.createFolder:
|
||||
core.GridNodes.createFolder(core.GridNodes.getNode(core.node, request.path.substr(1)), request.name, function(){
|
||||
browser.runtime.sendMessage( { cmd: 'GridNodesLoaded' } );
|
||||
browser.runtime.sendMessage( { cmd: core.Messages.Commands.gridNodesLoaded } );
|
||||
});
|
||||
break;
|
||||
case 'DeleteNode':
|
||||
case core.Messages.Commands.deleteNode:
|
||||
core.GridNodes.deleteNode(core.GridNodes.getNode(core.node, request.path.substr(1)), request.id, function(){
|
||||
browser.runtime.sendMessage( { cmd: 'GridNodesLoaded' } );
|
||||
browser.runtime.sendMessage( { cmd: core.Messages.Commands.gridNodesLoaded } );
|
||||
});
|
||||
break;
|
||||
case 'RefreshNode':
|
||||
case core.Messages.Commands.refreshNode:
|
||||
core.GridNodes.refreshNode(core.GridNodes.getChildNode(core.GridNodes.getNode(core.node, request.path.substr(1)), request.id), function(){
|
||||
browser.runtime.sendMessage( { cmd: 'GridNodesLoaded' } );
|
||||
browser.runtime.sendMessage( { cmd: core.Messages.Commands.gridNodesLoaded } );
|
||||
});
|
||||
break;
|
||||
case 'CapturePage':
|
||||
case core.Messages.Commands.capturePage:
|
||||
core.GridNodes.capturePage(core.GridNodes.getChildNode(core.GridNodes.getNode(core.node, request.path.substr(1)), request.id), function(){
|
||||
browser.runtime.sendMessage( { cmd: 'GridNodesLoaded' } );
|
||||
browser.runtime.sendMessage( { cmd: core.Messages.Commands.gridNodesLoaded } );
|
||||
});
|
||||
break;
|
||||
}
|
||||
|
@ -6,11 +6,11 @@ var dial = {
|
||||
};
|
||||
|
||||
|
||||
|
||||
window.onload = function(){
|
||||
document.addEventListener("DOMContentLoaded", function(event) {
|
||||
app.init();
|
||||
dial.init();
|
||||
};
|
||||
});
|
||||
|
||||
window.onresize = function(){
|
||||
if(app && app.settings) dial.updateGridLayout();
|
||||
}
|
||||
@ -41,48 +41,63 @@ utils.getPath = function(){
|
||||
|
||||
|
||||
app.init = function(){
|
||||
dial.path = utils.getPath();
|
||||
app.Messages.getSettings(app.Settings._changed);
|
||||
app.Messages.getNode(dial.path, app.GridNodes._changed);
|
||||
app.Messages.init();
|
||||
app.Messages.getSettings(function(settings){
|
||||
if(settings && settings.grid) app.Settings._changed(settings);
|
||||
dial.path = utils.getPath();
|
||||
app.Messages.getNode(dial.path, app.GridNodes._changed);
|
||||
app.Messages.init();
|
||||
});
|
||||
};
|
||||
|
||||
app.Messages = {};
|
||||
app.Messages.Commands = {
|
||||
getSettings: 0,
|
||||
setSettings: 1,
|
||||
getNode: 2,
|
||||
setNodeIndex: 3,
|
||||
createBookmark: 4,
|
||||
createFolder: 5,
|
||||
deleteNode: 6,
|
||||
refreshNode: 7,
|
||||
capturePage: 8,
|
||||
settingsChanged: 100,
|
||||
gridNodesLoaded: 101
|
||||
};
|
||||
app.Messages.init = function(){
|
||||
browser.runtime.onMessage.addListener(function(request, sender, sendResponse){
|
||||
switch(request.cmd){
|
||||
case 'SettingsChanged':
|
||||
case app.Messages.Commands.settingsChanged:
|
||||
app.Messages.getSettings(app.Settings._changed);
|
||||
break;
|
||||
case 'GridNodesLoaded':
|
||||
case app.Messages.Commands.gridNodesLoaded:
|
||||
app.Messages.getNode(dial.path, app.GridNodes._changed);
|
||||
break;
|
||||
}
|
||||
});
|
||||
};
|
||||
app.Messages.getSettings = function(callback){
|
||||
browser.runtime.sendMessage({ cmd: 'GetSettings' }).then(callback);
|
||||
browser.runtime.sendMessage({ cmd: app.Messages.Commands.getSettings }).then(callback, callback);
|
||||
};
|
||||
app.Messages.getNode = function(path, callback){
|
||||
browser.runtime.sendMessage({ cmd: 'GetNode', path: path }).then(callback);
|
||||
browser.runtime.sendMessage({ cmd: app.Messages.Commands.getNode, path: path }).then(callback);
|
||||
};
|
||||
app.Messages.setNodeIndex = function(index, newIndex, callback){
|
||||
browser.runtime.sendMessage({ cmd: 'SetNodeIndex', path: dial.path, index: index, newIndex: newIndex }).then(callback);
|
||||
browser.runtime.sendMessage({ cmd: app.Messages.Commands.setNodeIndex, path: dial.path, index: index, newIndex: newIndex }).then(callback);
|
||||
};
|
||||
app.Messages.createBookmark = function(url, callback){
|
||||
browser.runtime.sendMessage({ cmd: 'CreateBookmark', path: dial.path, url: url, title: url }).then(callback);
|
||||
browser.runtime.sendMessage({ cmd: app.Messages.Commands.createBookmark, path: dial.path, url: url, title: url }).then(callback);
|
||||
};
|
||||
app.Messages.createFolder = function(name, callback){
|
||||
browser.runtime.sendMessage({ cmd: 'CreateFolder', path: dial.path, name: name }).then(callback);
|
||||
browser.runtime.sendMessage({ cmd: app.Messages.Commands.createFolder, path: dial.path, name: name }).then(callback);
|
||||
};
|
||||
app.Messages.deleteNode = function(id, callback){
|
||||
browser.runtime.sendMessage({ cmd: 'DeleteNode', path: dial.path, id: id }).then(callback);
|
||||
browser.runtime.sendMessage({ cmd: app.Messages.Commands.deleteNode, path: dial.path, id: id }).then(callback);
|
||||
};
|
||||
app.Messages.refreshNode = function(id, callback){
|
||||
browser.runtime.sendMessage({ cmd: 'RefreshNode', path: dial.path, id: id }).then(callback);
|
||||
browser.runtime.sendMessage({ cmd: app.Messages.Commands.refreshNode, path: dial.path, id: id }).then(callback);
|
||||
}
|
||||
app.Messages.capturePage = function(id, callback){
|
||||
browser.runtime.sendMessage({ cmd: 'CapturePage', path: dial.path, id: id }).then(callback);
|
||||
browser.runtime.sendMessage({ cmd: app.Messages.Commands.capturePage, path: dial.path, id: id }).then(callback);
|
||||
}
|
||||
|
||||
app.Settings = {};
|
||||
@ -107,6 +122,7 @@ app.GridNodes._changed = function(node){
|
||||
|
||||
|
||||
|
||||
|
||||
dial.init = function(){
|
||||
dial.initMenus();
|
||||
dial.Title = document.createElement('title');
|
||||
|
@ -79,7 +79,7 @@ app.init = function(){
|
||||
else app.settings.grid.cells.titleBackgroundColor = GridCellsTitleBackgroundColor.value;
|
||||
if(GridCellsTitleBackgroundTransparentHover.checked == true) app.settings.grid.cells.titleBackgroundColorHover = null;
|
||||
else app.settings.grid.cells.titleBackgroundColorHover = GridCellsTitleBackgroundColorHover.value;
|
||||
browser.runtime.sendMessage( { cmd: 'SetSettings', settings: app.settings } );
|
||||
browser.runtime.sendMessage( { cmd: app.Messages.Commands.setSettings, settings: app.settings } );
|
||||
}
|
||||
BtnCancel.onclick = function(){
|
||||
window.frameElement.popup.close();
|
||||
@ -157,8 +157,21 @@ app.init = function(){
|
||||
};
|
||||
|
||||
app.Messages = {};
|
||||
app.Messages.Commands = {
|
||||
getSettings: 0,
|
||||
setSettings: 1,
|
||||
getNode: 2,
|
||||
setNodeIndex: 3,
|
||||
createBookmark: 4,
|
||||
createFolder: 5,
|
||||
deleteNode: 6,
|
||||
refreshNode: 7,
|
||||
capturePage: 8,
|
||||
settingsChanged: 100,
|
||||
gridNodesLoaded: 101
|
||||
};
|
||||
app.Messages.getSettings = function(callback){
|
||||
browser.runtime.sendMessage({ cmd: 'GetSettings' }).then(callback);
|
||||
browser.runtime.sendMessage({ cmd: app.Messages.Commands.getSettings }).then(callback);
|
||||
};
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user