mirror of
https://github.com/FrankerFaceZ/FrankerFaceZ.git
synced 2025-07-05 18:48:31 +00:00
Rewrite Switchboard in a way that will hopefully make it more robust. Make sure Switchboard works on every Twitch page we can think of.
This commit is contained in:
parent
3df7f0472d
commit
6b2b734ef9
4 changed files with 55 additions and 79 deletions
|
@ -1,3 +1,9 @@
|
||||||
|
<div class="list-header">4.0.0-rc1.12<span>@b04d3c600e5260fcd7cd</span> <time datetime="2018-05-25">(2018-05-25)</time></div>
|
||||||
|
<ul class="chat-menu-content menu-side-padding">
|
||||||
|
<li>Changed: Disable including user IDs in error reports by default.</li>
|
||||||
|
<li>Fixed: Rewrite Switchboard to be more robust and to hook into the router on all known pages, including dashboard pages.</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
<div class="list-header">4.0.0-rc1.11<span>@eed9eb9f5eb9acdb58ac</span> <time datetime="2018-05-22">(2018-05-22)</time></div>
|
<div class="list-header">4.0.0-rc1.11<span>@eed9eb9f5eb9acdb58ac</span> <time datetime="2018-05-22">(2018-05-22)</time></div>
|
||||||
<ul class="chat-menu-content menu-side-padding">
|
<ul class="chat-menu-content menu-side-padding">
|
||||||
<li>Added: Setting to always display deleted chat messages.</li>
|
<li>Added: Setting to always display deleted chat messages.</li>
|
||||||
|
|
|
@ -100,7 +100,7 @@ class FrankerFaceZ extends Module {
|
||||||
FrankerFaceZ.Logger = Logger;
|
FrankerFaceZ.Logger = Logger;
|
||||||
|
|
||||||
const VER = FrankerFaceZ.version_info = {
|
const VER = FrankerFaceZ.version_info = {
|
||||||
major: 4, minor: 0, revision: 0, extra: '-rc1.11',
|
major: 4, minor: 0, revision: 0, extra: '-rc1.12',
|
||||||
build: __webpack_hash__,
|
build: __webpack_hash__,
|
||||||
toString: () =>
|
toString: () =>
|
||||||
`${VER.major}.${VER.minor}.${VER.revision}${VER.extra || ''}${DEBUG ? '-dev' : ''}`
|
`${VER.major}.${VER.minor}.${VER.revision}${VER.extra || ''}${DEBUG ? '-dev' : ''}`
|
||||||
|
|
|
@ -70,7 +70,7 @@ export default class RavenLogger extends Module {
|
||||||
});
|
});
|
||||||
|
|
||||||
this.settings.add('reports.error.include-user', {
|
this.settings.add('reports.error.include-user', {
|
||||||
default: true,
|
default: false,
|
||||||
ui: {
|
ui: {
|
||||||
path: 'Data Management > Reporting >> Error Reports',
|
path: 'Data Management > Reporting >> Error Reports',
|
||||||
title: 'Include user IDs in reports.',
|
title: 'Include user IDs in reports.',
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
|
|
||||||
import Module from 'utilities/module';
|
import Module from 'utilities/module';
|
||||||
|
import pathToRegexp from 'path-to-regexp';
|
||||||
|
|
||||||
|
|
||||||
export default class Switchboard extends Module {
|
export default class Switchboard extends Module {
|
||||||
|
@ -19,7 +20,12 @@ export default class Switchboard extends Module {
|
||||||
|
|
||||||
|
|
||||||
awaitRouter() {
|
awaitRouter() {
|
||||||
const router = this.fine.searchTree(null, n => n.logger && n.logger.category === 'default-root-router', 100);
|
const router = this.fine.searchTree(null,
|
||||||
|
n => (n.logger && n.logger.category === 'default-root-router') ||
|
||||||
|
(n.onHistoryChange && n.reportInteractive) ||
|
||||||
|
(n.onHistoryChange && n.props && n.props.location),
|
||||||
|
100);
|
||||||
|
|
||||||
if ( router )
|
if ( router )
|
||||||
return Promise.resolve(router);
|
return Promise.resolve(router);
|
||||||
|
|
||||||
|
@ -27,95 +33,59 @@ export default class Switchboard extends Module {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
awaitMinimalRouter() {
|
|
||||||
const router = this.fine.searchTree(null, n => n.onHistoryChange && n.reportInteractive);
|
|
||||||
if ( router )
|
|
||||||
return Promise.resolve(router);
|
|
||||||
|
|
||||||
return new Promise(r => setTimeout(r, 50)).then(() => this.awaitMinimalRouter());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
hijinx(da_switch, path) {
|
|
||||||
const real_context = da_switch.context;
|
|
||||||
let output;
|
|
||||||
|
|
||||||
try {
|
|
||||||
da_switch.context = {
|
|
||||||
router: {
|
|
||||||
route: {
|
|
||||||
location: {
|
|
||||||
pathname: path
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
output = da_switch.render();
|
|
||||||
|
|
||||||
} catch(err) {
|
|
||||||
this.log.error('Error forcing router to render another page.', err);
|
|
||||||
da_switch.context = real_context;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
da_switch.context = real_context;
|
|
||||||
|
|
||||||
if ( ! output || ! output.props || ! output.props.component )
|
|
||||||
return this.log.warn('Unexpected output from router render.');
|
|
||||||
|
|
||||||
let component;
|
|
||||||
|
|
||||||
try {
|
|
||||||
component = new output.props.component;
|
|
||||||
} catch(err) {
|
|
||||||
this.log.error('Error instantiating component for forced loading of another chunk.', err);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
component.props.children.props.loader().then(() => {
|
|
||||||
this.log.info('Successfully forced a chunk to load.');
|
|
||||||
});
|
|
||||||
} catch(err) {
|
|
||||||
this.log.warn('Unexpected result trying to use component loader to force loading of another chunk.', err);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
async onEnable() {
|
async onEnable() {
|
||||||
const root = await this.parent.awaitElement('.twilight-minimal-root,.twilight-root'),
|
await this.parent.awaitElement('.twilight-minimal-root,.twilight-root');
|
||||||
is_minimal = root && root.classList.contains('twilight-minimal-root');
|
|
||||||
|
|
||||||
if ( this.web_munch._require || this.web_munch.v4 === false )
|
if ( this.web_munch._require || this.web_munch.v4 === false )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if ( is_minimal )
|
|
||||||
return this.enableMinimal();
|
|
||||||
|
|
||||||
const router = await this.awaitRouter(),
|
const router = await this.awaitRouter(),
|
||||||
child = router && this.fine.getFirstChild(router),
|
da_switch = router && this.fine.searchTree(router, n => n.context && n.context.router && n.props && n.props.children && n.componentWillMount && n.componentWillMount.toString().includes('Switch'));
|
||||||
da_switch = child && child.stateNode;
|
|
||||||
|
|
||||||
if ( ! da_switch )
|
if ( ! da_switch )
|
||||||
return new Promise(r => setTimeout(r, 50)).then(() => this.onEnable());
|
return new Promise(r => setTimeout(r, 50)).then(() => this.onEnable());
|
||||||
|
|
||||||
const on_settings = da_switch.context.router.route.location.pathname.includes('settings');
|
|
||||||
return this.hijinx(da_switch, on_settings ? '/inventory' : '/settings');
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// Identify Router
|
||||||
|
this.log.info(`Found Router and Switch with ${da_switch.props.children.length} routes.`);
|
||||||
|
|
||||||
async enableMinimal() {
|
const location = da_switch.context.router.route.location.pathname;
|
||||||
const router = await this.awaitMinimalRouter(),
|
|
||||||
da_switch = router && this.fine.searchTree(router, n => n.context && n.context.router);
|
|
||||||
|
|
||||||
if ( this.web_munch._require || this.web_munch.v4 === false )
|
for(const route of da_switch.props.children) {
|
||||||
return;
|
if ( ! route.props || ! route.props.component )
|
||||||
|
continue;
|
||||||
|
|
||||||
if ( ! da_switch )
|
try {
|
||||||
return new Promise(r => setTimeout(r, 50)).then(() => this.enableMinimal());
|
const reg = pathToRegexp(route.props.path);
|
||||||
|
if ( ! reg.exec || reg.exec(location) )
|
||||||
|
continue;
|
||||||
|
|
||||||
const on_prime = da_switch.context.router.route.location.pathname.includes('prime');
|
} catch(err) {
|
||||||
return this.hijinx(da_switch, on_prime ? '/subs' : '/prime')
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.log.info('Found Non-Matching Route', route.props.path);
|
||||||
|
|
||||||
|
let component;
|
||||||
|
|
||||||
|
try {
|
||||||
|
component = new route.props.component;
|
||||||
|
} catch(err) {
|
||||||
|
this.log.error('Error instantiating component for forced chunk loading.', err);
|
||||||
|
component = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( ! component || ! component.props || ! component.props.children || ! component.props.children.props || ! component.props.children.props.loader )
|
||||||
|
continue;
|
||||||
|
|
||||||
|
try {
|
||||||
|
component.props.children.props.loader().then(() => {
|
||||||
|
this.log.info('Successfully forced a chunk to load using route', route.props.path)
|
||||||
|
});
|
||||||
|
} catch(err) {
|
||||||
|
this.log.warn('Unexpected result trying to use component loader to force loading of another chunk.');
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Add table
Add a link
Reference in a new issue