ultrawidify/js/uw-bg.js

114 lines
3.1 KiB
JavaScript
Raw Normal View History

console.log("blabla");
async function main(){
if(Debug.debug)
console.log("[uw-bg::main] setting up background script");
await Settings.init();
browser.tabs.onActivated.addListener(_uwbg_onTabSwitched);
if(Debug.debug)
console.log("[uw-bg::main] listeners registered");
}
async function _uwbg_onTabSwitched(activeInfo){
if(Debug.debug)
console.log("[uw-bg::onTabSwitched] TAB CHANGED, GETTING INFO FROM MAIN TAB");
var tabId = activeInfo.tabId; // just for readability
2018-01-24 23:26:09 +01:00
Comms.sendToEach({"cmd":"has-videos"});
}
async function _uwbg_rcvmsg(message){
return;
if(Debug.debug){
2017-12-30 02:58:24 +01:00
console.log("[uw-bg::_uwbg_rcvmsg] received message", message);
}
2017-12-30 02:58:24 +01:00
message.sender = "uwbg";
2017-12-30 02:58:24 +01:00
message.receiver = "uw";
if(message.cmd == "has-videos"){
var response = await sendMessage(message);
if(Debug.debug){
console.log("[uw-bg::_uwbg_rcvmsg] received response for message", message, "response is this -->", response);
}
return Promise.resolve(response);
}
2017-12-30 18:36:08 +01:00
if(message.cmd == "get-config"){
var config = {};
config.videoAlignment = Settings.miscFullscreenSettings.videoFloat;
config.arConf = {};
config.arConf.enabled_global = Settings.arDetect.enabled == "global";
var keybinds = await Keybinds.fetch();
if(Debug.debug)
console.log("[uw-bg::_uwbg_rcvmsg] Keybinds.fetch returned this:", keybinds);
config.keyboardShortcuts = keybinds;
2017-12-30 18:36:08 +01:00
// predvidevajmo, da je enako. Če je drugače, bomo popravili ko dobimo odgovor
// assume current is same as global & change that when you get response from content script
config.arConf.enabled_current = Settings.arDetect.enabled == "global";
try{
message.cmd = "get-ardetect-active";
var response = await sendMessage(message);
if(Debug.debug){
console.log("[uw-bg::_uwbg_rcvmsg] received response to get-ardetect-active!", {message: message, response: response});
}
config.arConf.enabled_current = response.response.arDetect_active;
}
catch(ex){
if(Debug.debug)
console.log("%c[uw-bg::_uwbg_rcvmsg] there was something wrong with request for get-ardetect-active.", "color: #f00", ex);
2017-12-30 18:36:08 +01:00
}
return Promise.resolve({response: config});
2017-12-30 18:36:08 +01:00
}
else if(message.cmd == "force-ar"){
sendMessage(message); // args: {cmd: string, newAr: number/"auto"}
}
else if(message.cmd == "stop-autoar"){
sendMessage(message);
}
else if(message.cmd == "force-video-float"){
if(message.global){
Settings.miscFullscreenSettings.videoFloat = message.newFloat;
sendMessage(message);
}
else{
sendMessage(message);
}
}
else if(message.cmd == "disable-autoar"){
Settings.arDetect.enabled = "no";
Settings.save();
sendMessage("reload-settings");
}
else if(message.cmd == "disable-autoar-whitelist-only"){
Settings.arDetect.enabled = "whitelist";
Settings.save();
sendMessage("reload-settings");
}
else if(message.cmd == "enable-autoar"){
Settings.arDetect.enabled = "global";
Settings.save();
sendMessage("reload-settings");
}
}
main();