forked from Automattic/studio
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Generate site thumbnail when server starts (Automattic#128)
* Prototype screenshot generation * Each screenshot has a fresh browser session * Screenshot captured and cached each time server starts * Hide adminbar in thumbnails * Wait a short amount of time before taking screenshot * Taking screenshots doesn't prevent UI from reporting server is ready * Thumbnail cache deleted when site is deleted from Studio --------- Co-authored-by: Wojtek Naruniec <wojtek@naruniec.me>
- Loading branch information
Showing
5 changed files
with
73 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
export const MAIN_MIN_WIDTH = 900; | ||
export const MAIN_MIN_HEIGHT = 600; | ||
export const SCREENSHOT_WIDTH = 1040; | ||
export const SCREENSHOT_HEIGHT = 1248; | ||
export const LIMIT_OF_ZIP_SITES_PER_USER = 10; | ||
export const AUTO_UPDATE_INTERVAL_MS = 60 * 60 * 1000; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import crypto from 'crypto'; | ||
import { BrowserWindow, session } from 'electron'; | ||
import { SCREENSHOT_HEIGHT, SCREENSHOT_WIDTH } from './constants'; | ||
|
||
export function createScreenshotWindow( captureUrl: string ) { | ||
const newSession = session.fromPartition( crypto.randomUUID() ); | ||
|
||
const window = new BrowserWindow( { | ||
height: SCREENSHOT_HEIGHT, | ||
width: SCREENSHOT_WIDTH, | ||
show: false, | ||
webPreferences: { session: newSession }, | ||
} ); | ||
|
||
const finishedLoading = new Promise< void >( ( resolve ) => { | ||
window.webContents.on( 'did-finish-load', () => resolve() ); | ||
} ); | ||
|
||
window.loadURL( captureUrl ); | ||
|
||
const waitForCapture = async () => { | ||
await finishedLoading; | ||
await new Promise( ( resolve ) => setTimeout( resolve, 500 ) ); | ||
return window.webContents.capturePage(); | ||
}; | ||
|
||
return { window, waitForCapture }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters