mirror of
https://github.com/misskey-dev/misskey.git
synced 2026-06-25 17:10:43 +00:00
wip
This commit is contained in:
parent
cdbf5c843f
commit
8f9be8c735
2 changed files with 25 additions and 1 deletions
|
|
@ -520,7 +520,7 @@ async function refresh() {
|
|||
}
|
||||
|
||||
async function takeScreenshot() {
|
||||
console.log(await controller.takeScreenshot());
|
||||
await controller.downloadScreenshot();
|
||||
}
|
||||
|
||||
// TODO: ちゃんと書く
|
||||
|
|
|
|||
|
|
@ -333,6 +333,30 @@ export abstract class EngineControllerBase<T extends EngineBase<EngineBaseEvents
|
|||
return this.callAndWaitReturn('takeScreenshot');
|
||||
}
|
||||
|
||||
public async downloadScreenshot() {
|
||||
//const blob = await this.takeScreenshot();
|
||||
const blob = await new Promise<Blob>((resolve, reject) => {
|
||||
if (this.canvas == null) return reject(new Error('Canvas is not initialized'));
|
||||
this.canvas.toBlob((blob) => {
|
||||
if (blob == null) return reject(new Error('Failed to create blob from canvas'));
|
||||
resolve(blob);
|
||||
});
|
||||
});
|
||||
|
||||
const url = URL.createObjectURL(blob);
|
||||
|
||||
const a = window.document.createElement('a');
|
||||
a.href = url;
|
||||
a.download = `misskey-world-${Date.now()}.png`;
|
||||
a.style.display = 'none';
|
||||
|
||||
window.document.body.appendChild(a);
|
||||
a.click();
|
||||
|
||||
window.document.body.removeChild(a);
|
||||
URL.revokeObjectURL(url);
|
||||
}
|
||||
|
||||
public resize() {
|
||||
if (this.canvas == null) return;
|
||||
const width = this.canvas.clientWidth;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue