Skip to content

Commit

Permalink
Move logic for blackoutRegions into config file to allow end client t…
Browse files Browse the repository at this point in the history
…o define regions that are unstable
  • Loading branch information
paddlefish committed Aug 2, 2024
1 parent 4efdfb0 commit ae2653d
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 42 deletions.
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"**/dist": true
},
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
"source.fixAll.eslint": "explicit"
},
"workbench.colorCustomizations": {
"activityBar.background": "#3280a1",
Expand Down
59 changes: 30 additions & 29 deletions .vscode/snap.code-snippets
Original file line number Diff line number Diff line change
@@ -1,31 +1,32 @@
{
// Place your Miller workspace snippets here. Each snippet is defined under a snippet name and has a scope, prefix, body and
// description. Add comma separated ids of the languages where the snippet is applicable in the scope field. If scope
// is left empty or omitted, the snippet gets applied to all languages. The prefix is what is
// used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders.
// Placeholders with the same ids are connected.
// Example:
// "Print to console": {
// "scope": "javascript,typescript",
// "prefix": "log",
// "body": [
// "console.log('$1');",
// "$2"
// ],
// "description": "Log output to console"
// }
"Copyright": {
"prefix": "copy",
"body": [
"//",
"// $TM_FILENAME",
"// Modern Logic",
"//",
"// Created by Modern Logic on $CURRENT_YEAR-$CURRENT_MONTH-$CURRENT_DATE",
"// Copyright © $CURRENT_YEAR Modern Logic, LLC. All Rights Reserved.",
"",
]
}

// Place your Miller workspace snippets here. Each snippet is defined under a snippet name and has a scope, prefix, body and
// description. Add comma separated ids of the languages where the snippet is applicable in the scope field. If scope
// is left empty or omitted, the snippet gets applied to all languages. The prefix is what is
// used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders.
// Placeholders with the same ids are connected.
// Example:
// "Print to console": {
// "scope": "javascript,typescript",
// "prefix": "log",
// "body": [
// "console.log('$1');",
// "$2"
// ],
// "description": "Log output to console"
// }
"Copyright": {
"prefix": "copy",
"body": [
"//",
"// $TM_FILENAME",
"// Modern Logic",
"//",
"// Created by Modern Logic on $CURRENT_YEAR-$CURRENT_MONTH-$CURRENT_DATE",
"// Copyright © $CURRENT_YEAR Modern Logic, LLC. All Rights Reserved.",
"//",
"// This file is part of @modernlogic/snap",
""
]
}
}
12 changes: 12 additions & 0 deletions lib/cli/Config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ export interface Config {
bundleIdentifier: string
simulator: string
appName: string
blackoutRegions?: Array<{
top: number
left: number
width: number
height: number
}>
}
android: {
package: string
Expand All @@ -22,5 +28,11 @@ export interface Config {
sdkId?: string // e.g. system-images;android-25;google_apis;x86_64
deviceDefinition?: string // e.g. pixel_xl
}
blackoutRegions?: Array<{
top: number
left: number
width: number
height: number
}>
}
}
22 changes: 11 additions & 11 deletions lib/cli/diffImages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,6 @@ export const diffImages = async (
const { filePath: baselinePath, dirPath: baselineDir } = imagePath(screenshotsDir, pal.name, 'reference', filename)
await fs.mkdir(baselineDir, { recursive: true })

if (update) {
await fs.copyFile(latestFilePath, baselinePath)
console.log('Updated reference')
return {
message: 'Updated baseline',
pass: true,
diffPixelsCount: 0,
diffPath
}
}

await fs.mkdir(diffDir, { recursive: true })

const baselineData = await fs.readFile(baselinePath)
Expand Down Expand Up @@ -109,6 +98,17 @@ export const diffImages = async (
}
}

if (update) {
await fs.writeFile(baselinePath, PNG.sync.write(latestImage))
console.log('Updated reference')
return {
message: 'Updated baseline',
pass: true,
diffPixelsCount: 0,
diffPath
}
}

// Create and save the diff image
await fs.writeFile(diffPath, PNG.sync.write(diffImage))
await fs.writeFile(latestFilePath, PNG.sync.write(latestImage))
Expand Down
3 changes: 3 additions & 0 deletions lib/cli/pal/android/AndroidPlatformAbstraction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,9 @@ export class AndroidPlatformAbstraction implements PlatformAbstractionLayer {
}

async maskedRects (width: number, height: number): Promise<Rect[]> {
if (this.config.android.blackoutRegions !== undefined) {
return this.config.android.blackoutRegions
}
if (this.config.android.device.name === 'MoLo_SNAP_Pixel_XL_API_32') {
const pixelXL = { width: 1440, height: 2560 }
const clockReadout = { top: 20, left: 20, width: 190, height: 45 }
Expand Down
3 changes: 3 additions & 0 deletions lib/cli/pal/ios/IOSPlatformAbstraction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ export class IOSPlatformAbstraction implements PlatformAbstractionLayer {
}

async maskedRects (width: number, height: number): Promise<Rect[]> {
if (this.config.ios.blackoutRegions !== undefined) {
return this.config.ios.blackoutRegions
}
if (this.device === 'iPhone 13') {
const iPhone13 = { width: 1170, height: 2532 }
const homeButton = { top: 2492, left: 374, width: 424, height: 20 }
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,5 +89,5 @@
"tar": "npm run build && mkdir -p package && cp -r dist package && cp package.json package && cp README.md package && tar -czf package.tgz package && rm -rf package"
},
"types": "./dist/index.d.ts",
"version": "0.0.19+1"
"version": "0.0.20+6"
}

0 comments on commit ae2653d

Please sign in to comment.