Skip to content

Commit 31f2260

Browse files
If the screenshot have different size the script will now treat this as a change, notifying the user instead of an error
1 parent 93466ea commit 31f2260

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

urlwatcher/Sources/urlwatcher/Functions.swift

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ func sendTelegramMessage(_ message: String, to chatID: Int, image: String? = nil
8484
}
8585

8686
func handleScreenshotError(entry: URLEntry) throws {
87-
print("Handling error.")
8887
let errorFile = "\(directory(for: entry))/error"
8988
// If the errorReportMinutes are not set, we immediately notify the user
9089
guard errorReportMinutes > 0 else {
@@ -143,15 +142,23 @@ func screenshotNCC(_ oldImage: String, _ latestImage: String, diffFile: String)
143142
diffFile
144143
], standardOutput: nccPipe, standardError: nccPipe)
145144

145+
let nccData = nccPipe.fileHandleForReading.readDataToEndOfFile()
146+
guard let nccString = String(data: nccData, encoding: .utf8) else {
147+
return nil
148+
}
149+
150+
// If the images are different-sized, we don't need to treat this as an error.
151+
// Instead, we just notify the user about it by setting the NCC to 0
152+
if nccString.contains("compare: image widths or heights differ") {
153+
return 0
154+
}
155+
146156
// The compare command returns 0, if the images are similar, 1 if they are dissimilar and something else on an error
157+
// The error case of different sizes was already handled by the above statement
147158
if case .failure(let code) = result,
148159
code != 1 && code != 0 {
149160
return nil
150161
}
151162

152-
let nccData = nccPipe.fileHandleForReading.readDataToEndOfFile()
153-
guard let nccString = String(data: nccData, encoding: .utf8) else {
154-
return nil
155-
}
156163
return Double(nccString)
157164
}

0 commit comments

Comments
 (0)