Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(screenshotter): add setting to save as file & copy #227

Merged
merged 6 commits into from
Aug 12, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 21 additions & 6 deletions src/screenshoter/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,22 @@ class Screenshoter extends Addon {

this.settingsNamespace = 'addon.screenshoter'

this.settings.add(`${this.settingsNamespace}.clipboard`, {
default: false,
this.settings.add(`${this.settingsNamespace}.copy`, {
default: true,
ui: {
path: 'Add-Ons > Screenshoter >> Behavior',
title: 'Copy to clipboard',
description: 'By default, screenshots are saved as a file. Enable this to use clipboard instead (if supported by your browser).',
description: 'Enable this to copy the screenshot to the clipboard (if supported by your browser).',
component: 'setting-check-box'
}
});

this.settings.add(`${this.settingsNamespace}.download`, {
default: false,
ui: {
path: 'Add-Ons > Screenshoter >> Behavior',
title: 'Save as file',
description: 'Enable this if you wish to download the screenshot as a file.',
component: 'setting-check-box'
}
});
Expand Down Expand Up @@ -242,12 +252,17 @@ class Screenshoter extends Addon {
context.drawImage(video, 0, 0, canvas.width, canvas.height)

canvas.toBlob((blob) => {
const clipboard = this.settings.get(`${this.settingsNamespace}.clipboard`)
clipboard ? this.saveToClipboard(blob) : this.saveToFile(blob)
if (!this.settings.get(`$this.settingsNamespace}.download`) || !this.settings.get(`$this.settingsNamespace}.copy`)) return this.saveToClipboard(blob); // Default to clipboard if both settings r turned off for some reason
if (this.settings.get(`${this.settingsNamespace}.download`)) {
this.saveToFile(blob);
}
if (this.settings.get(`${this.settingsNamespace}.copy`)) {
this.saveToClipboard(blob);
}
})

canvas.remove()
}
}

Screenshoter.register()
Screenshoter.register()