mirror of
https://github.com/rustdesk/rustdesk.git
synced 2025-05-11 10:26:19 +02:00
feat: remote printer (#11231)
Signed-off-by: fufesou <linlong1266@gmail.com>
This commit is contained in:
parent
1cb53c1f7a
commit
f4bbf82363
101 changed files with 3707 additions and 211 deletions
|
@ -9,7 +9,6 @@ import 'package:desktop_multi_window/desktop_multi_window.dart';
|
|||
import 'package:flutter/gestures.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:flutter_hbb/common/widgets/peers_view.dart';
|
||||
import 'package:flutter_hbb/consts.dart';
|
||||
import 'package:flutter_hbb/models/ab_model.dart';
|
||||
|
@ -19,6 +18,7 @@ import 'package:flutter_hbb/models/file_model.dart';
|
|||
import 'package:flutter_hbb/models/group_model.dart';
|
||||
import 'package:flutter_hbb/models/peer_model.dart';
|
||||
import 'package:flutter_hbb/models/peer_tab_model.dart';
|
||||
import 'package:flutter_hbb/models/printer_model.dart';
|
||||
import 'package:flutter_hbb/models/server_model.dart';
|
||||
import 'package:flutter_hbb/models/user_model.dart';
|
||||
import 'package:flutter_hbb/models/state_model.dart';
|
||||
|
@ -412,12 +412,186 @@ class FfiModel with ChangeNotifier {
|
|||
isMobile) {
|
||||
parent.target?.recordingModel.updateStatus(evt['start'] == 'true');
|
||||
}
|
||||
} else if (name == "printer_request") {
|
||||
_handlePrinterRequest(evt, sessionId, peerId);
|
||||
} else {
|
||||
debugPrint('Event is not handled in the fixed branch: $name');
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
_handlePrinterRequest(
|
||||
Map<String, dynamic> evt, SessionID sessionId, String peerId) {
|
||||
final id = evt['id'];
|
||||
final path = evt['path'];
|
||||
final dialogManager = parent.target!.dialogManager;
|
||||
dialogManager.show((setState, close, context) {
|
||||
PrinterOptions printerOptions = PrinterOptions.load();
|
||||
final saveSettings = mainGetLocalBoolOptionSync(kKeyPrinterSave).obs;
|
||||
final dontShowAgain = false.obs;
|
||||
final Rx<String> selectedPrinterName = printerOptions.printerName.obs;
|
||||
final printerNames = printerOptions.printerNames;
|
||||
final defaultOrSelectedGroupValue =
|
||||
(printerOptions.action == kValuePrinterIncomingJobDismiss
|
||||
? kValuePrinterIncomingJobDefault
|
||||
: printerOptions.action)
|
||||
.obs;
|
||||
|
||||
onRatioChanged(String? value) {
|
||||
defaultOrSelectedGroupValue.value =
|
||||
value ?? kValuePrinterIncomingJobDefault;
|
||||
}
|
||||
|
||||
onSubmit() {
|
||||
final printerName = defaultOrSelectedGroupValue.isEmpty
|
||||
? ''
|
||||
: selectedPrinterName.value;
|
||||
bind.sessionPrinterResponse(
|
||||
sessionId: sessionId, id: id, path: path, printerName: printerName);
|
||||
if (saveSettings.value || dontShowAgain.value) {
|
||||
bind.mainSetLocalOption(key: kKeyPrinterSelected, value: printerName);
|
||||
bind.mainSetLocalOption(
|
||||
key: kKeyPrinterIncommingJobAction,
|
||||
value: defaultOrSelectedGroupValue.value);
|
||||
}
|
||||
if (dontShowAgain.value) {
|
||||
mainSetLocalBoolOption(kKeyPrinterAllowAutoPrint, true);
|
||||
}
|
||||
close();
|
||||
}
|
||||
|
||||
onCancel() {
|
||||
if (dontShowAgain.value) {
|
||||
bind.mainSetLocalOption(
|
||||
key: kKeyPrinterIncommingJobAction,
|
||||
value: kValuePrinterIncomingJobDismiss);
|
||||
}
|
||||
close();
|
||||
}
|
||||
|
||||
final printerItemHeight = 30.0;
|
||||
final selectionAreaHeight =
|
||||
printerItemHeight * min(8.0, max(printerNames.length, 3.0));
|
||||
final content = Column(
|
||||
children: [
|
||||
Text(translate('print-incoming-job-confirm-tip')),
|
||||
Row(
|
||||
children: [
|
||||
Obx(() => Radio<String>(
|
||||
value: kValuePrinterIncomingJobDefault,
|
||||
groupValue: defaultOrSelectedGroupValue.value,
|
||||
onChanged: onRatioChanged)),
|
||||
GestureDetector(
|
||||
child: Text(translate('use-the-default-printer-tip')),
|
||||
onTap: () => onRatioChanged(kValuePrinterIncomingJobDefault)),
|
||||
],
|
||||
),
|
||||
Column(
|
||||
children: [
|
||||
Row(children: [
|
||||
Obx(() => Radio<String>(
|
||||
value: kValuePrinterIncomingJobSelected,
|
||||
groupValue: defaultOrSelectedGroupValue.value,
|
||||
onChanged: onRatioChanged)),
|
||||
GestureDetector(
|
||||
child: Text(translate('use-the-selected-printer-tip')),
|
||||
onTap: () =>
|
||||
onRatioChanged(kValuePrinterIncomingJobSelected)),
|
||||
]),
|
||||
SizedBox(
|
||||
height: selectionAreaHeight,
|
||||
width: 500,
|
||||
child: ListView.builder(
|
||||
itemBuilder: (context, index) {
|
||||
return Obx(() => GestureDetector(
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
color: selectedPrinterName.value ==
|
||||
printerNames[index]
|
||||
? (defaultOrSelectedGroupValue.value ==
|
||||
kValuePrinterIncomingJobSelected
|
||||
? MyTheme.button
|
||||
: MyTheme.button.withOpacity(0.5))
|
||||
: Theme.of(context).cardColor,
|
||||
borderRadius: BorderRadius.all(
|
||||
Radius.circular(5.0),
|
||||
),
|
||||
),
|
||||
key: ValueKey(printerNames[index]),
|
||||
height: printerItemHeight,
|
||||
child: Align(
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.only(left: 10.0),
|
||||
child: Text(
|
||||
printerNames[index],
|
||||
style: TextStyle(fontSize: 14),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
onTap: defaultOrSelectedGroupValue.value ==
|
||||
kValuePrinterIncomingJobSelected
|
||||
? () {
|
||||
selectedPrinterName.value =
|
||||
printerNames[index];
|
||||
}
|
||||
: null,
|
||||
));
|
||||
},
|
||||
itemCount: printerNames.length),
|
||||
),
|
||||
],
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
Obx(() => Checkbox(
|
||||
value: saveSettings.value,
|
||||
onChanged: (value) {
|
||||
if (value != null) {
|
||||
saveSettings.value = value;
|
||||
mainSetLocalBoolOption(kKeyPrinterSave, value);
|
||||
}
|
||||
})),
|
||||
GestureDetector(
|
||||
child: Text(translate('save-settings-tip')),
|
||||
onTap: () {
|
||||
saveSettings.value = !saveSettings.value;
|
||||
mainSetLocalBoolOption(kKeyPrinterSave, saveSettings.value);
|
||||
}),
|
||||
],
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
Obx(() => Checkbox(
|
||||
value: dontShowAgain.value,
|
||||
onChanged: (value) {
|
||||
if (value != null) {
|
||||
dontShowAgain.value = value;
|
||||
}
|
||||
})),
|
||||
GestureDetector(
|
||||
child: Text(translate('dont-show-again-tip')),
|
||||
onTap: () {
|
||||
dontShowAgain.value = !dontShowAgain.value;
|
||||
}),
|
||||
],
|
||||
),
|
||||
],
|
||||
);
|
||||
return CustomAlertDialog(
|
||||
title: Text(translate('Incoming Print Job')),
|
||||
content: content,
|
||||
actions: [
|
||||
dialogButton('OK', onPressed: onSubmit),
|
||||
dialogButton('Cancel', onPressed: onCancel),
|
||||
],
|
||||
onSubmit: onSubmit,
|
||||
onCancel: onCancel,
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
_handleUseTextureRender(
|
||||
Map<String, dynamic> evt, SessionID sessionId, String peerId) {
|
||||
parent.target?.imageModel.setUseTextureRender(evt['v'] == 'Y');
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue