feat: take screenshot (#11591)

* feat: take screenshot

Signed-off-by: fufesou <linlong1266@gmail.com>

* screenshot, vram temp switch capturer

Signed-off-by: fufesou <linlong1266@gmail.com>

* fix: misspelling

Signed-off-by: fufesou <linlong1266@gmail.com>

* screenshot, taking

Signed-off-by: fufesou <linlong1266@gmail.com>

* screenshot, rgba stride

Signed-off-by: fufesou <linlong1266@gmail.com>

* Bumps 1.4.0

Signed-off-by: fufesou <linlong1266@gmail.com>

---------

Signed-off-by: fufesou <linlong1266@gmail.com>
This commit is contained in:
fufesou
2025-04-30 17:23:35 +08:00
committed by GitHub
parent 2864e1984a
commit c626c2414d
82 changed files with 948 additions and 96 deletions

View File

@@ -230,6 +230,7 @@ class Header: Reactor.Component {
{restart_enabled && (pi.platform == "Linux" || pi.platform == "Windows" || pi.platform == "Mac OS") ? <li #restart_remote_device>{translate('Restart remote device')}</li> : ""}
{keyboard_enabled ? <li #lock-screen>{translate('Insert Lock')}</li> : ""}
{keyboard_enabled && pi.platform == "Windows" && pi.sas_enabled ? <li #block-input>{translate("Block user input")}</li> : ""}
{handler.is_screenshot_supported() ? <li #take-screenshot>{translate('Take screenshot')}</li> : "" }
<li #refresh>{translate('Refresh')}</li>
</menu>
</popup>;
@@ -376,6 +377,10 @@ class Header: Reactor.Component {
event click $(#lock-screen) {
handler.lock_screen();
}
event click $(#take-screenshot) {
handler.take_screenshot(pi.current_display, "");
}
event click $(#refresh) {
// 0 is just a dummy value. It will be ignored by the handler.
@@ -546,6 +551,26 @@ handler.setCurrentDisplay = function(v) {
}
}
handler.screenshot = function(msg) {
if (msg) {
msgbox(
"custom-nocancel-nook-hasclose-error",
translate("Take screenshot"),
msg,
"",
function() {}
);
} else {
msgbox(
"custom-take-screenshot-nocancel-nook",
translate("Take screenshot"),
translate("screenshot-action-tip"),
"",
function() {}
);
}
}
function updatePrivacyMode() {
var el = $(li#privacy-mode);
if (el) {

View File

@@ -132,6 +132,17 @@ class MsgboxComponent: Reactor.Component {
return this.type.indexOf("skip") >= 0;
}
function getScreenshotButtons() {
var isScreenshot = this.type.indexOf("take-screenshot") >= 0;
return isScreenshot
? <div>
<button .button #screenshotSaveAs .outline>{translate('Save as')}...</button>
<button .button #screenshotCopyToClip .outline>{translate('Copy to clipboard')}</button>
<button .button #screenshotCancel .outline>{translate('Cancel')}</button>
</div>
: "";
}
function render() {
this.set_outline_focus();
var color = this.getColor();
@@ -170,6 +181,7 @@ class MsgboxComponent: Reactor.Component {
{hasOk || this.hasRetry ? <button .button #submit>{translate(this.hasRetry ? "Retry" : "OK")}</button> : ""}
{hasLink ? <button .button #jumplink .outline>{translate('JumpLink')}</button> : ""}
{hasClose ? <button .button #cancel .outline>{translate('Close')}</button> : ""}
{this.getScreenshotButtons()}
</div>
</div>
</div>
@@ -245,6 +257,39 @@ class MsgboxComponent: Reactor.Component {
this.close();
}
}
event click $(button#screenshotSaveAs) {
this.close();
handler.leave(handler.get_keyboard_mode());
const filter = "Png file (*.png)";
const defaultExt = "png";
const initialPath = System.path(#USER_DOCUMENTS, "screenshot");
const caption = "Save as";
var url = view.selectFile(#save, filter, defaultExt, initialPath, caption);
handler.enter(handler.get_keyboard_mode());
if(url) {
var res = handler.handle_screenshot("0:" + URL.toPath(url));
if (res) {
msgbox("custom-error-nocancel-nook-hasclose", "Take screenshot", res, "", function() {});
}
} else {
handler.handle_screenshot("2");
}
}
event click $(button#screenshotCopyToClip) {
this.close();
var res = handler.handle_screenshot("1");
if (res) {
msgbox("custom-error-nocancel-nook-hasclose", "Take screenshot", res, "", function() {});
}
}
event click $(button#screenshotCancel) {
this.close();
handler.handle_screenshot("2");
}
event keydown (evt) {
if (!evt.shortcutKey) {

View File

@@ -383,6 +383,10 @@ impl InvokeUiSession for SciterHandler {
fn printer_request(&self, id: i32, path: String) {
self.call("printerRequest", &make_args!(id, path));
}
fn handle_screenshot_resp(&self, _sid: String, msg: String) {
self.call("screenshot", &make_args!(msg));
}
}
pub struct SciterSession(Session<SciterHandler>);
@@ -529,6 +533,9 @@ impl sciter::EventHandler for SciterSession {
fn save_custom_image_quality(i32);
fn refresh_video(i32);
fn record_screen(bool);
fn is_screenshot_supported();
fn take_screenshot(i32, String);
fn handle_screenshot(String);
fn get_toggle_option(String);
fn is_privacy_mode_supported();
fn toggle_option(String);
@@ -866,6 +873,10 @@ impl SciterSession {
fn on_printer_selected(&self, id: i32, path: String, printer_name: String) {
self.printer_response(id, path, printer_name);
}
fn handle_screenshot(&self, action: String) -> String {
crate::client::screenshot::handle_screenshot(action)
}
}
pub fn make_fd(id: i32, entries: &Vec<FileEntry>, only_count: bool) -> Value {