Skip to content

Commit

Permalink
Correct binary file polling comparison
Browse files Browse the repository at this point in the history
  • Loading branch information
James-Yu committed Nov 25, 2024
1 parent e9f1afa commit 6698c41
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/core/watcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ class Watcher {
this.polling[uriString] = { size, time: firstChangeTime }

const pollingInterval = setInterval(() => {
void this.handlePolling(uri, size, firstChangeTime, pollingInterval)
void this.handlePolling(uri, firstChangeTime, pollingInterval)
}, vscode.workspace.getConfiguration('latex-workshop').get('latex.watch.pdf.delay') as number)
}

Expand All @@ -164,7 +164,7 @@ class Watcher {
* @param {number} firstChangeTime - The timestamp of the first change.
* @param {NodeJS.Timeout} interval - The polling interval.
*/
private async handlePolling(uri: vscode.Uri, size: number, firstChangeTime: number, interval: NodeJS.Timeout): Promise<void> {
private async handlePolling(uri: vscode.Uri, firstChangeTime: number, interval: NodeJS.Timeout): Promise<void> {
const uriString = uri.toString(true)
if (!await lw.file.exists(uri)) {
clearInterval(interval)
Expand All @@ -174,12 +174,18 @@ class Watcher {

const currentSize = (await lw.external.stat(uri)).size

if (currentSize !== size) {
if (currentSize !== this.polling[uriString].size) {
this.polling[uriString].size = currentSize
this.polling[uriString].time = Date.now()
return
}

// Resume vscode may cause accidental "change", do nothing
if (!(uriString in this.polling)) {
clearInterval(interval)
return
}

if (Date.now() - this.polling[uriString].time >= 200) {
logger.log(`"change" emitted on ${uriString} after polling for ${Date.now() - firstChangeTime} ms.`)
clearInterval(interval)
Expand Down

0 comments on commit 6698c41

Please sign in to comment.