"Hanging issues with select mode"
This commit is contained in:
parent
f5e3b47245
commit
1d5a6bd364
|
@ -32,8 +32,8 @@
|
||||||
<input type=radio name=mode value=serve id=serve>
|
<input type=radio name=mode value=serve id=serve>
|
||||||
Serve
|
Serve
|
||||||
</label>
|
</label>
|
||||||
<label disabled>
|
<label>
|
||||||
<input disabled type=radio name=mode value=select id=select>
|
<input type=radio name=mode value=select id=select>
|
||||||
Select (<em>Bookmark mode</em>)
|
Select (<em>Bookmark mode</em>)
|
||||||
</label>
|
</label>
|
||||||
<output name=notification>
|
<output name=notification>
|
||||||
|
|
|
@ -31,7 +31,7 @@
|
||||||
|
|
||||||
import args from './args.js';
|
import args from './args.js';
|
||||||
import {
|
import {
|
||||||
sleep, DEBUG,
|
sleep, DEBUG as debug,
|
||||||
MAX_TITLE_LENGTH,
|
MAX_TITLE_LENGTH,
|
||||||
MAX_URL_LENGTH,
|
MAX_URL_LENGTH,
|
||||||
clone,
|
clone,
|
||||||
|
@ -43,6 +43,7 @@
|
||||||
import {bookmarkChanges} from './bookmarker.js';
|
import {bookmarkChanges} from './bookmarker.js';
|
||||||
|
|
||||||
// search related state: constants and variables
|
// search related state: constants and variables
|
||||||
|
const DEBUG = debug || true;
|
||||||
// common
|
// common
|
||||||
/* eslint-disable no-control-regex */
|
/* eslint-disable no-control-regex */
|
||||||
const STRIP_CHARS = /[\u0001-\u001a\0\v\f\r\t\n]/g;
|
const STRIP_CHARS = /[\u0001-\u001a\0\v\f\r\t\n]/g;
|
||||||
|
@ -193,7 +194,6 @@ export default Archivist;
|
||||||
const ConfirmedInstalls = new Set();
|
const ConfirmedInstalls = new Set();
|
||||||
const DELAY = 100; // 500 ?
|
const DELAY = 100; // 500 ?
|
||||||
Close = close;
|
Close = close;
|
||||||
Mode = mode;
|
|
||||||
|
|
||||||
let requestStage;
|
let requestStage;
|
||||||
|
|
||||||
|
@ -201,7 +201,7 @@ export default Archivist;
|
||||||
|
|
||||||
clearSavers();
|
clearSavers();
|
||||||
|
|
||||||
if ( Mode == 'save' ) {
|
if ( mode == 'save' || mode == 'select' ) {
|
||||||
requestStage = "Response";
|
requestStage = "Response";
|
||||||
// in case we get a updateBasePath call before an interval
|
// in case we get a updateBasePath call before an interval
|
||||||
// and we don't clear it in time, leading us to erroneously save the old
|
// and we don't clear it in time, leading us to erroneously save the old
|
||||||
|
@ -212,11 +212,13 @@ export default Archivist;
|
||||||
// only 1 call at 1 time
|
// only 1 call at 1 time
|
||||||
State.indexSaver = setTimeout(() => saveIndex(State.SavedIndexFilePath), 11001);
|
State.indexSaver = setTimeout(() => saveIndex(State.SavedIndexFilePath), 11001);
|
||||||
State.ftsIndexSaver = setTimeout(() => saveFTS(State.SavedFTSIndexDirPath), 31001);
|
State.ftsIndexSaver = setTimeout(() => saveFTS(State.SavedFTSIndexDirPath), 31001);
|
||||||
} else if ( Mode == 'serve' ) {
|
} else if ( mode == 'serve' ) {
|
||||||
requestStage = "Request";
|
requestStage = "Request";
|
||||||
|
clearSavers();
|
||||||
} else {
|
} else {
|
||||||
throw new TypeError(`Must specify mode`);
|
throw new TypeError(`Must specify mode, and must be one of: save, serve, select`);
|
||||||
}
|
}
|
||||||
|
Mode = mode;
|
||||||
|
|
||||||
//on("Target.targetInfoChanged", displayTargetInfo);
|
//on("Target.targetInfoChanged", displayTargetInfo);
|
||||||
on("Target.targetInfoChanged", attachToTarget);
|
on("Target.targetInfoChanged", attachToTarget);
|
||||||
|
@ -695,21 +697,23 @@ export default Archivist;
|
||||||
const DEBUG = true;
|
const DEBUG = true;
|
||||||
for await ( const change of bookmarkChanges() ) {
|
for await ( const change of bookmarkChanges() ) {
|
||||||
console.error(`Publish map needs implement!`);
|
console.error(`Publish map needs implement!`);
|
||||||
switch(change.type) {
|
if ( Mode == 'select' ) {
|
||||||
case 'publish-map': {
|
switch(change.type) {
|
||||||
// clone the map to avoid mutable shared data
|
case 'publish-map': {
|
||||||
State.BMarks = new Map([...change.map.entries()]);
|
// clone the map to avoid mutable shared data
|
||||||
DEBUG && console.log(`Loaded bookmarks. ${State.BMarks.size} marks loaded.`);
|
State.BMarks = new Map([...change.map.entries()]);
|
||||||
|
DEBUG && console.log(`Loaded bookmarks. ${State.BMarks.size} marks loaded.`);
|
||||||
|
} break;
|
||||||
|
case 'new': {
|
||||||
|
archiveAndIndexURL(change.url);
|
||||||
|
} break;
|
||||||
|
case 'delete': {
|
||||||
|
deleteFromIndexAndSearch(change.url);
|
||||||
|
} break;
|
||||||
|
default: {
|
||||||
|
console.log(`We don't do anything about this bookmark change, currently`, change);
|
||||||
} break;
|
} break;
|
||||||
case 'new': {
|
}
|
||||||
archiveAndIndexURL(change.url);
|
|
||||||
} break;
|
|
||||||
case 'delete': {
|
|
||||||
deleteFromIndexAndSearch(change.url);
|
|
||||||
} break;
|
|
||||||
default: {
|
|
||||||
console.log(`We don't do anything about this bookmark change, currently`, change);
|
|
||||||
} break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -738,7 +742,6 @@ export default Archivist;
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// helpers
|
// helpers
|
||||||
|
@ -999,7 +1002,7 @@ export default Archivist;
|
||||||
|
|
||||||
function saveIndex(path) {
|
function saveIndex(path) {
|
||||||
//const DEBUG = true;
|
//const DEBUG = true;
|
||||||
if ( State.saveInProgress ) return;
|
if ( State.saveInProgress || Mode == 'serve' ) return;
|
||||||
State.saveInProgress = true;
|
State.saveInProgress = true;
|
||||||
|
|
||||||
clearTimeout(State.indexSaver);
|
clearTimeout(State.indexSaver);
|
||||||
|
@ -1121,7 +1124,7 @@ export default Archivist;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function saveFTS(path = undefined, {forceSave:forceSave = false} = {}) {
|
async function saveFTS(path = undefined, {forceSave:forceSave = false} = {}) {
|
||||||
if ( State.ftsSaveInProgress ) return;
|
if ( State.ftsSaveInProgress || Mode == 'serve' ) return;
|
||||||
State.ftsSaveInProgress = true;
|
State.ftsSaveInProgress = true;
|
||||||
|
|
||||||
clearTimeout(State.ftsIndexSaver);
|
clearTimeout(State.ftsIndexSaver);
|
||||||
|
@ -1360,37 +1363,48 @@ export default Archivist;
|
||||||
return args.flex_fts_index_dir(basePath);
|
return args.flex_fts_index_dir(basePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
function addFrameNode(frameAttached) {
|
function addFrameNode(observedFrame) {
|
||||||
const {frameId, parentFrameId} = frameAttached;
|
const {frameId, parentFrameId} = observedFrame;
|
||||||
const node = {
|
const node = {
|
||||||
id: frameId,
|
id: frameId,
|
||||||
parentId: parentFrameId,
|
parentId: parentFrameId,
|
||||||
parent: State.FrameNodes.get(parentFrameId)
|
parent: State.FrameNodes.get(parentFrameId)
|
||||||
};
|
};
|
||||||
State.FrameNodes.set(node.id, node);
|
State.FrameNodes.set(node.id, node);
|
||||||
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateFrameNode(frameNavigated) {
|
function updateFrameNode(frameNavigated) {
|
||||||
const {
|
const {
|
||||||
frame: {
|
frame: {
|
||||||
id: frameId,
|
id: frameId,
|
||||||
parentId, url, urlFragment,
|
parentId, url: rawUrl, urlFragment,
|
||||||
/*
|
/*
|
||||||
domainAndRegistry, unreachableUrl,
|
domainAndRegistry, unreachableUrl,
|
||||||
adFrameStatus
|
adFrameStatus
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
} = frameNavigated;
|
} = frameNavigated;
|
||||||
const frameNode = State.FrameNodes.get(frameId);
|
const url = urlFragment?.startsWith(rawUrl.slice(0,4)) ? urlFragment : rawUrl;
|
||||||
|
let frameNode = State.FrameNodes.get(frameId);
|
||||||
|
|
||||||
if ( ! frameNode ) {
|
if ( ! frameNode ) {
|
||||||
throw new TypeError(
|
// Note
|
||||||
`Sanity check failed: frameId ${
|
// This is not actually a panic because
|
||||||
frameId
|
// it can happen. It may just mean
|
||||||
} is not in our FrameNodes data, which currently has ${
|
// this isn't a sub frame.
|
||||||
State.FrameNodes.size
|
// So rather than panicing:
|
||||||
} entries.`
|
/*
|
||||||
);
|
throw new TypeError(
|
||||||
|
`Sanity check failed: frameId ${
|
||||||
|
frameId
|
||||||
|
} is not in our FrameNodes data, which currently has ${
|
||||||
|
State.FrameNodes.size
|
||||||
|
} entries.`
|
||||||
|
);
|
||||||
|
*/
|
||||||
|
// We do this instead (just add it):
|
||||||
|
frameNode = addFrameNode({frameId, parentFrameId: parentId});
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( frameNode.id !== frameId ) {
|
if ( frameNode.id !== frameId ) {
|
||||||
|
@ -1408,12 +1422,12 @@ export default Archivist;
|
||||||
// only if it's actually a URL
|
// only if it's actually a URL
|
||||||
|
|
||||||
// Update frame node url (and possible parent)
|
// Update frame node url (and possible parent)
|
||||||
frameNode.url = urlFragment?.startsWith(url.slice(0,4)) ? urlFragment : url;
|
frameNode.url = url;
|
||||||
if ( parentId !== frameNode.parentId ) {
|
if ( parentId !== frameNode.parentId ) {
|
||||||
console.info(`Interesting. Frame parent changed from ${frameNode.parentId} to ${parentId}`);
|
console.info(`Interesting. Frame parent changed from ${frameNode.parentId} to ${parentId}`);
|
||||||
frameNode.parentId = parentId;
|
frameNode.parentId = parentId;
|
||||||
frameNode.parent = State.FrameNodes.get(parentId);
|
frameNode.parent = State.FrameNodes.get(parentId);
|
||||||
if ( ! frameNode.parent ) {
|
if ( parentId && !frameNode.parent ) {
|
||||||
throw new TypeError(
|
throw new TypeError(
|
||||||
`!! FrameNode ${
|
`!! FrameNode ${
|
||||||
frameId
|
frameId
|
||||||
|
@ -1443,8 +1457,8 @@ export default Archivist;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function getRootFrameURL(frameId) {
|
function getRootFrameURL(frameId) {
|
||||||
let childNode = State.FrameNodes.get(frameId);
|
let frameNode = State.FrameNodes.get(frameId);
|
||||||
if ( ! childNode ) {
|
if ( ! frameNode ) {
|
||||||
throw new TypeError(
|
throw new TypeError(
|
||||||
`Sanity check failed: frameId ${
|
`Sanity check failed: frameId ${
|
||||||
frameId
|
frameId
|
||||||
|
@ -1453,17 +1467,17 @@ export default Archivist;
|
||||||
} entries.`
|
} entries.`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if ( childNode.frameId !== frameId ) {
|
if ( frameNode.id !== frameId ) {
|
||||||
throw new TypeError(
|
throw new TypeError(
|
||||||
`Sanity check failed: Child frameId ${
|
`Sanity check failed: Child frameId ${
|
||||||
childNode.frameId
|
frameNode.id
|
||||||
} was supposed to be ${
|
} was supposed to be ${
|
||||||
frameId
|
frameId
|
||||||
}`
|
}`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
while(childNode.parent) {
|
while(frameNode.parent) {
|
||||||
childNode = childNode.parent;
|
frameNode = frameNode.parent;
|
||||||
}
|
}
|
||||||
return childNode.url;
|
return frameNode.url;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue