From 9384ef9ed3218987c6a879b475262eb75e47a54a Mon Sep 17 00:00:00 2001 From: Ben Olden-Cooligan Date: Sun, 3 Dec 2023 17:52:26 -0800 Subject: [PATCH] Escl: Add NoScannerSharing option to appsettings.xml --- CHANGELOG.md | 1 + NAPS2.Lib/Config/CommonConfig.cs | 3 +++ NAPS2.Lib/Config/ConfigSerializer.cs | 4 ++++ NAPS2.Lib/Config/ObsoleteTypes/AppConfigV0.cs | 2 ++ NAPS2.Lib/EtoForms/MenuProvider.cs | 8 ++++++-- NAPS2.Lib/EtoForms/Ui/DesktopForm.cs | 2 +- NAPS2.Lib/EtoForms/Ui/ProfilesForm.cs | 4 +++- NAPS2.Lib/Remoting/Server/SharedDeviceManager.cs | 8 ++++++++ NAPS2.Setup/appsettings.xml | 1 + 9 files changed, 29 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 086a82ed98..de630ef4ae 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ Changes in 7.2.0: - "Apple Driver" on Mac and "Sane Driver" on Linux should also work - NAPS2 currently must be kept open on the host for sharing to work - Shared scanners can be used from any ESCL-capable client, not just NAPS2 + - Use NoScannerSharing in appsettings.xml to disable - Slightly updated icons in Profiles window - Bug fixes diff --git a/NAPS2.Lib/Config/CommonConfig.cs b/NAPS2.Lib/Config/CommonConfig.cs index 967aba9baf..38bbaec20c 100644 --- a/NAPS2.Lib/Config/CommonConfig.cs +++ b/NAPS2.Lib/Config/CommonConfig.cs @@ -174,4 +174,7 @@ public class CommonConfig [User] public bool ShowPageNumbers { get; set; } + [Common] + public bool DisableScannerSharing { get; set; } + } \ No newline at end of file diff --git a/NAPS2.Lib/Config/ConfigSerializer.cs b/NAPS2.Lib/Config/ConfigSerializer.cs index 7c73fd11a9..365d2553db 100644 --- a/NAPS2.Lib/Config/ConfigSerializer.cs +++ b/NAPS2.Lib/Config/ConfigSerializer.cs @@ -135,6 +135,10 @@ private ConfigStorage AppConfigV0ToCommonConfigLocked(AppConfigV0 { storage.Set(x => x.EnableDebugLogging, false); } + if (c.NoScannerSharing) + { + storage.Set(x => x.DisableScannerSharing, true); + } return storage; } diff --git a/NAPS2.Lib/Config/ObsoleteTypes/AppConfigV0.cs b/NAPS2.Lib/Config/ObsoleteTypes/AppConfigV0.cs index 562d7a65ce..5243688ad0 100644 --- a/NAPS2.Lib/Config/ObsoleteTypes/AppConfigV0.cs +++ b/NAPS2.Lib/Config/ObsoleteTypes/AppConfigV0.cs @@ -50,6 +50,8 @@ public class AppConfigV0 public bool NoDebugLogging { get; set; } + public bool NoScannerSharing { get; set; } + public bool DeleteAfterSaving { get; set; } public bool DisableSaveNotifications { get; set; } diff --git a/NAPS2.Lib/EtoForms/MenuProvider.cs b/NAPS2.Lib/EtoForms/MenuProvider.cs index 5ff167b76a..ea55a8c114 100644 --- a/NAPS2.Lib/EtoForms/MenuProvider.cs +++ b/NAPS2.Lib/EtoForms/MenuProvider.cs @@ -16,11 +16,15 @@ public MenuProvider Dynamic(ListProvider commandListProvider) return this; } - public MenuProvider Append(Command command) + public MenuProvider Append(Command? command) { + if (command == null) + { + return this; + } _items.Add(new CommandItem { - Command = command ?? throw new ArgumentNullException(nameof(command)) + Command = command }); return this; } diff --git a/NAPS2.Lib/EtoForms/Ui/DesktopForm.cs b/NAPS2.Lib/EtoForms/Ui/DesktopForm.cs index 45fbc2fbb1..33e37321f6 100644 --- a/NAPS2.Lib/EtoForms/Ui/DesktopForm.cs +++ b/NAPS2.Lib/EtoForms/Ui/DesktopForm.cs @@ -251,7 +251,7 @@ protected virtual void CreateToolbarsAndMenus() .Separator() .Append(Commands.NewProfile) .Append(Commands.BatchScan) - .Append(Commands.ScannerSharing)); + .Append(Config.Get(c => c.DisableScannerSharing) ? null : Commands.ScannerSharing)); if (!hiddenButtons.HasFlag(ToolbarButtons.Profiles)) CreateToolbarButton(Commands.Profiles); if (!hiddenButtons.HasFlag(ToolbarButtons.Ocr)) diff --git a/NAPS2.Lib/EtoForms/Ui/ProfilesForm.cs b/NAPS2.Lib/EtoForms/Ui/ProfilesForm.cs index 20b0abbdf2..cfeedb29fa 100644 --- a/NAPS2.Lib/EtoForms/Ui/ProfilesForm.cs +++ b/NAPS2.Lib/EtoForms/Ui/ProfilesForm.cs @@ -145,7 +145,9 @@ protected override void BuildLayout() C.Button(_editCommand, ButtonImagePosition.Left), C.Button(_deleteCommand, ButtonImagePosition.Left), C.Filler(), - C.Button(_scannerSharingCommand, ButtonImagePosition.Left) + Config.Get(c => c.DisableScannerSharing) + ? C.None() + : C.Button(_scannerSharingCommand, ButtonImagePosition.Left) ) ), C.CancelButton(this, UiStrings.Done) diff --git a/NAPS2.Lib/Remoting/Server/SharedDeviceManager.cs b/NAPS2.Lib/Remoting/Server/SharedDeviceManager.cs index 93b5c5d0c6..882db12aed 100644 --- a/NAPS2.Lib/Remoting/Server/SharedDeviceManager.cs +++ b/NAPS2.Lib/Remoting/Server/SharedDeviceManager.cs @@ -18,11 +18,19 @@ public SharedDeviceManager(ScanningContext scanningContext, Naps2Config config) public void StartSharing() { + if (_config.Get(c => c.DisableScannerSharing)) + { + return; + } _server.Start(); } public void StopSharing() { + if (_config.Get(c => c.DisableScannerSharing)) + { + return; + } _server.Stop(); } diff --git a/NAPS2.Setup/appsettings.xml b/NAPS2.Setup/appsettings.xml index 848f9891ba..5eda9a925f 100644 --- a/NAPS2.Setup/appsettings.xml +++ b/NAPS2.Setup/appsettings.xml @@ -20,6 +20,7 @@ false false false + false false false false