tswow/tswow-scripts/runtime/PositionsFile.ts
ihm-tswow 34bc5fac93 shell: expand use of nowatch shell parameter
- add nowatch-strict for not watching the positions file

- include crashlog watching in nowatch mode
2024-09-20 15:34:45 +02:00

31 lines
No EOL
1,022 B
TypeScript

import * as clipboardy from 'clipboardy';
import { wfs } from "../util/FileSystem";
import { ipaths } from '../util/Paths';
import { NodeConfig } from "./NodeConfig";
import { term } from '../util/Terminal';
export namespace PositionsFile {
let oldContent = ""
export function initialize() {
term.debug('misc', `Initializing positions file`)
if(!NodeConfig.WritePosToClipboard) {
return;
}
oldContent = ipaths.coredata.positions_txt.readString('')
if(!ipaths.coredata.positions_txt.exists()) {
ipaths.coredata.positions_txt.write('')
}
if (process.argv.includes('nowatch-strict'))
{
wfs.watch(ipaths.coredata.positions_txt.get(),(evt,filename)=>{
let value = ipaths.coredata.positions_txt.readString('')
if(value.length > oldContent.length) {
clipboardy.writeSync(value);
}
oldContent = value;
});
}
}
}