Skip to content

Commit

Permalink
Escl: Add NoScannerSharing option to appsettings.xml
Browse files Browse the repository at this point in the history
  • Loading branch information
cyanfish committed Dec 4, 2023
1 parent 6e923a4 commit 9384ef9
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 3 additions & 0 deletions NAPS2.Lib/Config/CommonConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -174,4 +174,7 @@ public class CommonConfig
[User]
public bool ShowPageNumbers { get; set; }

[Common]
public bool DisableScannerSharing { get; set; }

}
4 changes: 4 additions & 0 deletions NAPS2.Lib/Config/ConfigSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@ private ConfigStorage<CommonConfig> AppConfigV0ToCommonConfigLocked(AppConfigV0
{
storage.Set(x => x.EnableDebugLogging, false);
}
if (c.NoScannerSharing)
{
storage.Set(x => x.DisableScannerSharing, true);
}
return storage;
}

Expand Down
2 changes: 2 additions & 0 deletions NAPS2.Lib/Config/ObsoleteTypes/AppConfigV0.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
8 changes: 6 additions & 2 deletions NAPS2.Lib/EtoForms/MenuProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,15 @@ public MenuProvider Dynamic(ListProvider<Command> 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;
}
Expand Down
2 changes: 1 addition & 1 deletion NAPS2.Lib/EtoForms/Ui/DesktopForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
4 changes: 3 additions & 1 deletion NAPS2.Lib/EtoForms/Ui/ProfilesForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 8 additions & 0 deletions NAPS2.Lib/Remoting/Server/SharedDeviceManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
1 change: 1 addition & 0 deletions NAPS2.Setup/appsettings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<AlwaysRememberDevice>false</AlwaysRememberDevice>
<NoUpdatePrompt>false</NoUpdatePrompt>
<NoDebugLogging>false</NoDebugLogging>
<NoScannerSharing>false</NoScannerSharing>
<DeleteAfterSaving>false</DeleteAfterSaving>
<DisableSaveNotifications>false</DisableSaveNotifications>
<SingleInstance>false</SingleInstance>
Expand Down

0 comments on commit 9384ef9

Please sign in to comment.