Screenshot for core dump (#2066)

* start of screenshot, need uploader

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* cleanup

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* some cleanup

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* most things working

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* bump the world

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* updates

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* updates

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* mime type

Signed-off-by: Jess Frazelle <github@jessfraz.com>

---------

Signed-off-by: Jess Frazelle <github@jessfraz.com>
This commit is contained in:
Jess Frazelle
2024-04-11 13:15:49 -07:00
committed by GitHub
parent a90fe3c066
commit c094d0ced1
23 changed files with 236 additions and 21 deletions

View File

@ -9,14 +9,39 @@ import {
} from '@tauri-apps/plugin-os'
import { APP_VERSION } from 'routes/Settings'
import { UAParser } from 'ua-parser-js'
import screenshot from 'lib/screenshot'
import React from 'react'
import { VITE_KC_API_BASE_URL } from 'env'
// This is a class for getting all the values from the JS world to pass to the Rust world
// for a core dump.
export class CoreDumpManager {
engineCommandManager: EngineCommandManager
htmlRef: React.RefObject<HTMLDivElement> | null
token: string | undefined
baseUrl: string = VITE_KC_API_BASE_URL
constructor(engineCommandManager: EngineCommandManager) {
constructor(
engineCommandManager: EngineCommandManager,
htmlRef: React.RefObject<HTMLDivElement> | null,
token: string | undefined
) {
this.engineCommandManager = engineCommandManager
this.htmlRef = htmlRef
this.token = token
}
// Get the token.
authToken(): string {
if (!this.token) {
throw new Error('Token not set')
}
return this.token
}
// Get the base url.
baseApiUrl(): string {
return this.baseUrl
}
// Get the version of the app from the package.json.
@ -111,4 +136,15 @@ export class CoreDumpManager {
return JSON.stringify(webrtcStats)
})
}
// Return a data URL (png format) of the screenshot of the current page.
screenshot(): Promise<string> {
return screenshot(this.htmlRef)
.then((screenshot: string) => {
return screenshot
})
.catch((error: any) => {
throw new Error(`Error getting screenshot: ${error}`)
})
}
}