Put in console.errors on extension initialization.
This commit is contained in:
parent
338b219142
commit
0edd82479e
@ -48,87 +48,96 @@ export default class UWContent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
reloadSettings() {
|
reloadSettings() {
|
||||||
this.logger.log('info', 'debug', 'Things happened in the popup. Will reload extension settings.');
|
try {
|
||||||
this.init();
|
this.logger.log('info', 'debug', 'Things happened in the popup. Will reload extension settings.');
|
||||||
|
this.init();
|
||||||
|
} catch (e) {
|
||||||
|
console.warn('Ultrawidify: settings reload failed. This probably shouldn\'t outright kill the extension, but page reload is recommended.');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async init(){
|
async init(){
|
||||||
if (Debug.debug) {
|
|
||||||
console.log("[uw::main] loading configuration ...");
|
|
||||||
}
|
|
||||||
|
|
||||||
// logger init is the first thing that needs to run
|
|
||||||
try {
|
try {
|
||||||
if (!this.logger) {
|
if (Debug.debug) {
|
||||||
|
console.log("[uw::main] loading configuration ...");
|
||||||
this.logger = new Logger();
|
}
|
||||||
await this.logger.init(baseLoggingOptions);
|
|
||||||
|
// logger init is the first thing that needs to run
|
||||||
|
try {
|
||||||
|
if (!this.logger) {
|
||||||
|
|
||||||
|
this.logger = new Logger();
|
||||||
|
await this.logger.init(baseLoggingOptions);
|
||||||
|
|
||||||
// show popup if logging to file is enabled
|
// show popup if logging to file is enabled
|
||||||
if (this.logger.isLoggingAllowed() && this.logger.isLoggingToFile()) {
|
if (this.logger.isLoggingAllowed() && this.logger.isLoggingToFile()) {
|
||||||
console.info("[uw::init] Logging is allowed! Initalizing vue and UI!");
|
console.info("[uw::init] Logging is allowed! Initalizing vue and UI!");
|
||||||
|
|
||||||
// CommsClient is not initiated yet, so we use static comms to send the command
|
// CommsClient is not initiated yet, so we use static comms to send the command
|
||||||
Comms.sendMessage({cmd: 'show-logger'});
|
Comms.sendMessage({cmd: 'show-logger'});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.error("logger init failed!", e)
|
||||||
|
}
|
||||||
|
|
||||||
|
// init() is re-run any time settings change
|
||||||
|
if (this.comms) {
|
||||||
|
this.comms.destroy();
|
||||||
|
}
|
||||||
|
if (!this.settings) {
|
||||||
|
this.settings = new Settings({
|
||||||
|
onSettingsChanged: () => this.reloadSettings(),
|
||||||
|
logger: this.logger
|
||||||
|
});
|
||||||
|
await this.settings.init();
|
||||||
|
}
|
||||||
|
|
||||||
|
this.comms = new CommsClient('content-main-port', this.logger, this.commsHandlers);
|
||||||
|
|
||||||
|
// če smo razširitev onemogočili v nastavitvah, ne naredimo ničesar
|
||||||
|
// If extension is soft-disabled, don't do shit
|
||||||
|
|
||||||
|
var extensionMode = this.settings.getExtensionMode();
|
||||||
|
|
||||||
|
this.logger.log('info', 'debug', "[uw::init] Extension mode:" + (extensionMode < 0 ? "disabled" : extensionMode == '1' ? 'basic' : 'full'));
|
||||||
|
|
||||||
|
const isSiteDisabled = extensionMode === ExtensionMode.Disabled
|
||||||
|
|
||||||
|
if (isSiteDisabled) {
|
||||||
|
if (this.settings.getExtensionMode('@global') === ExtensionMode.Disabled) {
|
||||||
|
this.logger.log('info', 'debug', "[uw::init] EXTENSION DISABLED, THEREFORE WONT BE STARTED")
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (e) {
|
|
||||||
console.error("logger init failed!", e)
|
try {
|
||||||
}
|
if (this.pageInfo) {
|
||||||
|
this.logger.log('info', 'debug', '[uw.js::setup] An instance of pageInfo already exists and will be destroyed.');
|
||||||
// init() is re-run any time settings change
|
this.pageInfo.destroy();
|
||||||
if (this.comms) {
|
|
||||||
this.comms.destroy();
|
|
||||||
}
|
|
||||||
if (!this.settings) {
|
|
||||||
this.settings = new Settings({
|
|
||||||
onSettingsChanged: () => this.reloadSettings(),
|
|
||||||
logger: this.logger
|
|
||||||
});
|
|
||||||
await this.settings.init();
|
|
||||||
}
|
|
||||||
|
|
||||||
this.comms = new CommsClient('content-main-port', this.logger, this.commsHandlers);
|
|
||||||
|
|
||||||
// če smo razširitev onemogočili v nastavitvah, ne naredimo ničesar
|
|
||||||
// If extension is soft-disabled, don't do shit
|
|
||||||
|
|
||||||
var extensionMode = this.settings.getExtensionMode();
|
|
||||||
|
|
||||||
this.logger.log('info', 'debug', "[uw::init] Extension mode:" + (extensionMode < 0 ? "disabled" : extensionMode == '1' ? 'basic' : 'full'));
|
|
||||||
|
|
||||||
const isSiteDisabled = extensionMode === ExtensionMode.Disabled
|
|
||||||
|
|
||||||
if (isSiteDisabled) {
|
|
||||||
if (this.settings.getExtensionMode('@global') === ExtensionMode.Disabled) {
|
|
||||||
this.logger.log('info', 'debug', "[uw::init] EXTENSION DISABLED, THEREFORE WONT BE STARTED")
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
if (this.pageInfo) {
|
|
||||||
this.logger.log('info', 'debug', '[uw.js::setup] An instance of pageInfo already exists and will be destroyed.');
|
|
||||||
this.pageInfo.destroy();
|
|
||||||
}
|
|
||||||
this.pageInfo = new PageInfo(this.comms, this.settings, this.logger, extensionMode, isSiteDisabled);
|
|
||||||
this.logger.log('info', 'debug', "[uw.js::setup] pageInfo initialized.");
|
|
||||||
|
|
||||||
this.logger.log('info', 'debug', "[uw.js::setup] will try to initate ActionHandler.");
|
|
||||||
|
|
||||||
// start action handler only if extension is enabled for this site
|
|
||||||
if (!isSiteDisabled) {
|
|
||||||
if (this.actionHandler) {
|
|
||||||
this.actionHandler.destroy();
|
|
||||||
}
|
}
|
||||||
this.actionHandler = new ActionHandler(this.pageInfo);
|
this.pageInfo = new PageInfo(this.comms, this.settings, this.logger, extensionMode, isSiteDisabled);
|
||||||
this.actionHandler.init();
|
this.logger.log('info', 'debug', "[uw.js::setup] pageInfo initialized.");
|
||||||
|
|
||||||
this.logger.log('info', 'debug', "[uw.js::setup] ActionHandler initiated.");
|
this.logger.log('info', 'debug', "[uw.js::setup] will try to initate ActionHandler.");
|
||||||
}
|
|
||||||
|
|
||||||
|
// start action handler only if extension is enabled for this site
|
||||||
|
if (!isSiteDisabled) {
|
||||||
|
if (this.actionHandler) {
|
||||||
|
this.actionHandler.destroy();
|
||||||
|
}
|
||||||
|
this.actionHandler = new ActionHandler(this.pageInfo);
|
||||||
|
this.actionHandler.init();
|
||||||
|
|
||||||
|
this.logger.log('info', 'debug', "[uw.js::setup] ActionHandler initiated.");
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (e) {
|
||||||
|
console.error('Ultrawidify: failed to start extension. Error:', e)
|
||||||
|
this.logger.log('error', 'debug', "[uw::init] FAILED TO START EXTENSION. Error:", e);
|
||||||
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
this.logger.log('error', 'debug', "[uw::init] FAILED TO START EXTENSION. Error:", e);
|
console.error('Ultrawidify initalization failed for some reason:', e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -33,32 +33,35 @@ export default class UWServer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async setup() {
|
async setup() {
|
||||||
// logger is the first thing that goes up
|
try {
|
||||||
|
// logger is the first thing that goes up
|
||||||
|
const loggingOptions = {
|
||||||
|
isBackgroundScript: true,
|
||||||
|
allowLogging: false,
|
||||||
|
useConfFromStorage: true,
|
||||||
|
logAll: true,
|
||||||
|
fileOptions: {
|
||||||
|
enabled: false,
|
||||||
|
},
|
||||||
|
consoleOptions: {
|
||||||
|
enabled: false
|
||||||
|
}
|
||||||
|
};
|
||||||
|
this.logger = new Logger();
|
||||||
|
await this.logger.init(loggingOptions);
|
||||||
|
|
||||||
const loggingOptions = {
|
this.settings = new Settings({logger: this.logger});
|
||||||
isBackgroundScript: true,
|
await this.settings.init();
|
||||||
allowLogging: false,
|
this.comms = new CommsServer(this);
|
||||||
useConfFromStorage: true,
|
this.comms.subscribe('show-logger', async () => await this.initUiAndShowLogger());
|
||||||
logAll: true,
|
this.comms.subscribe('init-vue', async () => await this.initUi());
|
||||||
fileOptions: {
|
this.comms.subscribe('uwui-vue-initialized', () => this.uiLoggerInitialized = true);
|
||||||
enabled: false,
|
this.comms.subscribe('emit-logs', () => {}); // we don't need to do anything, this gets forwarded to UI content script as is
|
||||||
},
|
|
||||||
consoleOptions: {
|
|
||||||
enabled: false
|
|
||||||
}
|
|
||||||
};
|
|
||||||
this.logger = new Logger();
|
|
||||||
await this.logger.init(loggingOptions);
|
|
||||||
|
|
||||||
this.settings = new Settings({logger: this.logger});
|
browser.tabs.onActivated.addListener((m) => {this.onTabSwitched(m)});
|
||||||
await this.settings.init();
|
} catch (e) {
|
||||||
this.comms = new CommsServer(this);
|
console.error(`Ultrawidify [server]: failed to start. Reason:`, e);
|
||||||
this.comms.subscribe('show-logger', async () => await this.initUiAndShowLogger());
|
}
|
||||||
this.comms.subscribe('init-vue', async () => await this.initUi());
|
|
||||||
this.comms.subscribe('uwui-vue-initialized', () => this.uiLoggerInitialized = true);
|
|
||||||
this.comms.subscribe('emit-logs', () => {}); // we don't need to do anything, this gets forwarded to UI content script as is
|
|
||||||
|
|
||||||
browser.tabs.onActivated.addListener((m) => {this.onTabSwitched(m)});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async _promisifyTabsGet(browserObj, tabId){
|
async _promisifyTabsGet(browserObj, tabId){
|
||||||
@ -215,37 +218,42 @@ export default class UWServer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
console.warn('Ultrawidify [server]: UI setup failed. While problematic, this problem shouldn\'t completely crash the extension.');
|
||||||
this.logger.log('ERROR', 'uwbg', 'UI initialization failed. Reason:', e);
|
this.logger.log('ERROR', 'uwbg', 'UI initialization failed. Reason:', e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async initUiAndShowLogger() {
|
async initUiAndShowLogger() {
|
||||||
// this implementation is less than optimal and very hacky, but it should work
|
try {
|
||||||
// just fine for our use case.
|
// this implementation is less than optimal and very hacky, but it should work
|
||||||
this.uiLoggerInitialized = false;
|
// just fine for our use case.
|
||||||
|
this.uiLoggerInitialized = false;
|
||||||
|
|
||||||
await this.initUi();
|
await this.initUi();
|
||||||
|
|
||||||
await new Promise<void>( async (resolve, reject) => {
|
await new Promise<void>( async (resolve, reject) => {
|
||||||
// if content script doesn't give us a response within 5 seconds, something is
|
// if content script doesn't give us a response within 5 seconds, something is
|
||||||
// obviously wrong and we stop waiting,
|
// obviously wrong and we stop waiting,
|
||||||
|
|
||||||
// oh and btw, resolve/reject do not break the loops, so we need to do that
|
// oh and btw, resolve/reject do not break the loops, so we need to do that
|
||||||
// ourselves:
|
// ourselves:
|
||||||
// https://stackoverflow.com/questions/55207256/will-resolve-in-promise-loop-break-loop-iteration
|
// https://stackoverflow.com/questions/55207256/will-resolve-in-promise-loop-break-loop-iteration
|
||||||
let isRejected = false;
|
let isRejected = false;
|
||||||
setTimeout( async () => {isRejected = true; reject()}, 5000);
|
setTimeout( async () => {isRejected = true; reject()}, 5000);
|
||||||
|
|
||||||
// check whether UI has been initiated on the FE. If it was, we resolve the
|
// check whether UI has been initiated on the FE. If it was, we resolve the
|
||||||
// promise and off we go
|
// promise and off we go
|
||||||
while (!isRejected) {
|
while (!isRejected) {
|
||||||
if (this.uiLoggerInitialized) {
|
if (this.uiLoggerInitialized) {
|
||||||
resolve();
|
resolve();
|
||||||
return; // remember the bit about resolve() not breaking the loop?
|
return; // remember the bit about resolve() not breaking the loop?
|
||||||
|
}
|
||||||
|
await sleep(100);
|
||||||
}
|
}
|
||||||
await sleep(100);
|
});
|
||||||
}
|
} catch (e) {
|
||||||
})
|
console.warn('Ultrawidify [server]: failed to set up logger UI. While problematic, this problem shouldn\'t completely crash the extension.');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async getCurrentTab() {
|
async getCurrentTab() {
|
||||||
|
Loading…
Reference in New Issue
Block a user