180 lines
5.0 KiB
TypeScript
180 lines
5.0 KiB
TypeScript
// Metro module 10875 (f10876).
|
|
import GatewayConnectionStore from "../gateway/GatewayConnectionStore";
|
|
import KeybindRouterStore from "./KeybindRouterStore";
|
|
import "../../Constants";
|
|
import * as _router_utils from "./router_utils";
|
|
import { replaceWith } from "./router_utils";
|
|
import { addBreadcrumb } from "../../_bundle/Module6363";
|
|
function $mk85698($env) {
|
|
return () => {
|
|
const r5 = $env;
|
|
const r2 = $env.$parent;
|
|
const isConnected = r2[2].isConnected();
|
|
const r8 = isConnected && !r5[0].connected;
|
|
const r10 = r5[0];
|
|
r10.connected = isConnected;
|
|
if (r8) {
|
|
r10.routeChangeCount = 0;
|
|
r10.executeRouteRewrites((0, r2[0])(r2[1][3]).getHistory().location, "REPLACE");
|
|
}
|
|
};
|
|
}
|
|
function $mk85699($env) {
|
|
return (a0, a1) => {
|
|
const r1 = $env;
|
|
if (a1 !== "POP") {
|
|
if (r1[0].executeRouteRewrites(a0, a1)) {
|
|
return void 0;
|
|
}
|
|
const r24 = $env.$parent;
|
|
const r7 = r24[0];
|
|
const r25 = r24[1];
|
|
if (!r7(r25[4]).convertRouteToNavigation(a0)) {
|
|
r7(r25[3]).replaceWith(r24[4].ME);
|
|
return void 0;
|
|
}
|
|
}
|
|
const state = $env.$parent[3].getState();
|
|
if (state.basePath !== a0.pathname) {
|
|
state.resetPath(a0.pathname);
|
|
}
|
|
for (const listener of r1[0].listeners) {
|
|
const r52 = listener;
|
|
try {
|
|
r52(a0, a1);
|
|
} catch ($e) {}
|
|
}
|
|
r1[0].routeChangeCount = 0;
|
|
};
|
|
}
|
|
function $mk85700($env) {
|
|
return ({ path }) => {
|
|
const r7 = $env[0];
|
|
if (r7.timer !== -1) {
|
|
clearTimeout(r7.timer);
|
|
}
|
|
if (path != null) {
|
|
r7.timer = setTimeout(r7.flushRoute, 200);
|
|
}
|
|
};
|
|
}
|
|
function $mk85701($env) {
|
|
return () => {
|
|
clearTimeout($env[0].timer);
|
|
const r9 = $env.$parent;
|
|
const state = r9[3].getState();
|
|
if (state.path != null) {
|
|
(0, r9[0])(r9[1][3]).transitionTo(state.path);
|
|
}
|
|
};
|
|
}
|
|
let c7316_0;
|
|
let env7315;
|
|
let env7316;
|
|
const r7 = env7315 = {};
|
|
class RouteManager {
|
|
constructor() {
|
|
let env18331;
|
|
const r3 = env18331 = {
|
|
$parent: env7315
|
|
};
|
|
env18331[0] = this;
|
|
this.rewrites = new Set();
|
|
this.listeners = new Set();
|
|
this.routeChangeCount = 0;
|
|
this.timer = -1;
|
|
this.connected = false;
|
|
this.handleConnectionChange = $mk85698(r3);
|
|
this.handleRouteChange = $mk85699(r3);
|
|
this.handleKeybindRouteChange = $mk85700(r3);
|
|
this.flushRoute = $mk85701(r3);
|
|
}
|
|
initialize() {
|
|
this.cleanup();
|
|
this.unlistenHistory = _router_utils.getHistory().listen(this.handleRouteChange);
|
|
const pathname = _router_utils.getHistory().location.pathname;
|
|
KeybindRouterStore.getState().resetPath(pathname);
|
|
this.unlistenKeyboardChange = KeybindRouterStore.subscribe(this.handleKeybindRouteChange);
|
|
GatewayConnectionStore.addChangeListener(this.handleConnectionChange);
|
|
}
|
|
executeRouteRewrites(a0, a1) {
|
|
this.routeChangeCount = this.routeChangeCount + 1;
|
|
if (!(this.routeChangeCount < 10)) {
|
|
throw new Error("RouteManager: Something has gone horribly wrong with rewrites");
|
|
}
|
|
for (const rewrite of this.rewrites) {
|
|
const pathname = _router_utils.getHistory().location.pathname;
|
|
const r45 = rewrite(a0, a1);
|
|
if (r45 == null) {
|
|
continue;
|
|
}
|
|
addBreadcrumb({
|
|
message: "RouteManager.handleRouteChange: A route rewrite is replacing the current route",
|
|
data: {
|
|
replacePath: r45.path,
|
|
previousPath: pathname
|
|
}
|
|
});
|
|
replaceWith(r45.path, r45.state);
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
cleanup() {
|
|
const unlistenHistory = this.unlistenHistory;
|
|
if (unlistenHistory != null) {
|
|
unlistenHistory.call(this);
|
|
}
|
|
this.unlistenHistory = void 0;
|
|
const unlistenKeyboardChange = this.unlistenKeyboardChange;
|
|
if (unlistenKeyboardChange != null) {
|
|
unlistenKeyboardChange.call(this);
|
|
}
|
|
this.unlistenKeyboardChange = void 0;
|
|
GatewayConnectionStore.removeChangeListener(this.handleConnectionChange);
|
|
}
|
|
addRouteChangeListener(a0) {
|
|
if (this.unlistenHistory != null) {
|
|
a0(_router_utils.getHistory().location, "REPLACE");
|
|
}
|
|
this.listeners.add(a0);
|
|
return () => this.removeRouteChangeListener(a0);
|
|
}
|
|
addRouteRewriter(a0) {
|
|
if (this.unlistenHistory != null) {
|
|
const r19 = a0(_router_utils.getHistory().location, _router_utils.getHistory().action);
|
|
if (r19 != null) {
|
|
replaceWith(r19.path, r19.state);
|
|
}
|
|
}
|
|
this.rewrites.add(a0);
|
|
return () => this.removeRouteRewriter(a0);
|
|
}
|
|
removeRouteChangeListener(a0) {
|
|
this.listeners.delete(a0);
|
|
}
|
|
removeRouteRewriter(a0) {
|
|
this.rewrites.delete(a0);
|
|
}
|
|
getHistory() {
|
|
return _router_utils.getHistory();
|
|
}
|
|
}
|
|
const r45 = {
|
|
__proto__: RouteManager.prototype
|
|
};
|
|
const r46 = env7316 = {
|
|
$parent: r7
|
|
};
|
|
c7316_0 = r45;
|
|
r45.rewrites = new Set();
|
|
r45.listeners = new Set();
|
|
r45.routeChangeCount = 0;
|
|
r45.timer = -1;
|
|
r45.connected = false;
|
|
r45.handleConnectionChange = $mk85698(r46);
|
|
r45.handleRouteChange = $mk85699(r46);
|
|
r45.handleKeybindRouteChange = $mk85700(r46);
|
|
r45.flushRoute = $mk85701(r46);
|
|
export default r45;
|