public inbox for cygwin-apps@cygwin.com
 help / color / mirror / Atom feed
* [PATCH setup] Enhance quiet mode to allow window to be input-disabled or hidden
@ 2023-04-20 13:57 Jon Turney
  0 siblings, 0 replies; only message in thread
From: Jon Turney @ 2023-04-20 13:57 UTC (permalink / raw)
  To: cygwin-apps; +Cc: Jon Turney

'-q'/'--quiet-mode' now accepts an optional parameter specifying how the
setup wizard behaves: 'unattended' is the existing behaviour (basically,
the wizard automatically advances rather than requiring 'next' to be
pressed, and MessageBox()es automatically performn some default action),
'noinput' also disables mouse and keyboard interaction with the wizard,
and 'hidden' hides the the wizard.

No exhaustive audit has taken place that there aren't places in setup
where we don't loop forever, or get stuck waiting for user input to
resolve some unexpected condition.

(In particular, I suspect that dialogs which may occur if some
authorization credentials need to be provided for the network connection
to the package repository (HTTP auth, or proxy auth, or FTP password)
don't handle unattended mode correctly, and there's currently no
non-interactive way to provide these credentials)
---

Notes:
    The names of the quite modes probably could use a bit more thought.
    
    The ideal approach to this problem is probably to decouple the GUI and
    install logic, so we can build a CLI installer, but things are
    sufficently entangled that that's would be a substantial amount of work
    to do.

 main.cc       | 18 +++++++++++++++---
 propsheet.cc  | 17 +++++++++++++++--
 quiet.h       | 26 ++++++++++++++++++++++++++
 res/en/res.rc |  2 +-
 4 files changed, 57 insertions(+), 6 deletions(-)
 create mode 100644 quiet.h

diff --git a/main.cc b/main.cc
index 1d65d53..01c90b9 100644
--- a/main.cc
+++ b/main.cc
@@ -36,6 +36,7 @@
 #include "resource.h"
 #include "dialog.h"
 #include "state.h"
+#include "quiet.h"
 #include "msg.h"
 #include "find.h"
 #include "mount.h"
@@ -95,8 +96,14 @@ static StringChoiceOption::StringChoices symlink_types({
     {"wsl", SymlinkTypeWsl},
   });
 
+static StringChoiceOption::StringChoices quiet_types({
+    {"unattended", QuietUnattended},
+    {"noinput", QuietNoInput},
+    {"hidden", QuietHidden},
+  });
+
 static StringOption Arch ("", 'a', "arch", IDS_HELPTEXT_ARCH, false);
-static BoolOption UnattendedOption (false, 'q', "quiet-mode", IDS_HELPTEXT_QUIET_MODE);
+StringChoiceOption UnattendedOption (quiet_types, 'q', "quiet-mode", IDS_HELPTEXT_QUIET_MODE, true, -1, QuietUnattended);
 static BoolOption PackageManagerOption (false, 'M', "package-manager", IDS_HELPTEXT_PACKAGE_MANAGER);
 static BoolOption NoAdminOption (false, 'B', "no-admin", IDS_HELPTEXT_NO_ADMIN);
 static BoolOption WaitOption (false, 'W', "wait", IDS_HELPTEXT_WAIT);
@@ -275,8 +282,13 @@ WinMain (HINSTANCE h,
           SetThreadUILanguage(langid);
       }
 
-    unattended_mode = PackageManagerOption ? chooseronly
-			: (UnattendedOption ? unattended : attended);
+    if (PackageManagerOption)
+      unattended_mode = chooseronly;
+    else
+      if (UnattendedOption < 0)
+        unattended_mode = attended;
+      else
+        unattended_mode = unattended;
 
     bool output_only = help_option || VersionOption;
 
diff --git a/propsheet.cc b/propsheet.cc
index a2dca45..092293f 100644
--- a/propsheet.cc
+++ b/propsheet.cc
@@ -25,6 +25,7 @@
 #include "ControlAdjuster.h"
 #include "choose.h"
 #include "msg.h"
+#include "quiet.h"
 
 // Sort of a "hidden" Windows structure.  Used in the PropSheetCallback.
 #include <pshpack1.h>
@@ -243,16 +244,28 @@ PropSheetProc (HWND hwndDlg, UINT uMsg, LPARAM lParam)
     {
     case PSCB_PRECREATE:
       {
-	LONG additionalStyle =
-	  (WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_THICKFRAME);
+        LONG additionalStyle = (WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_THICKFRAME);
+
+        // 'noinput' quiet mode adds WS_DISABLE to prevent user interaction
+        // with the propsheet
+        if (UnattendedOption == QuietNoInput)
+          additionalStyle |= WS_DISABLED;
+
+        // 'hidden' quiet mode totally hides the propsheet window
+        LONG forbiddenStyle = 0;
+        if (UnattendedOption == QuietHidden)
+          forbiddenStyle |= WS_VISIBLE;
+
 	// Add a minimize box to the sheet/wizard.
 	if (((LPDLGTEMPLATEEX) lParam)->signature == 0xFFFF)
 	  {
 	    ((LPDLGTEMPLATEEX) lParam)->style |= additionalStyle;
+            ((LPDLGTEMPLATEEX) lParam)->style &= ~forbiddenStyle;
 	  }
 	else
 	  {
 	    ((LPDLGTEMPLATE) lParam)->style |= additionalStyle;
+            ((LPDLGTEMPLATE) lParam)->style &= ~forbiddenStyle;
 	  }
       }
       return TRUE;
diff --git a/quiet.h b/quiet.h
new file mode 100644
index 0000000..9f2b6d8
--- /dev/null
+++ b/quiet.h
@@ -0,0 +1,26 @@
+/*
+ *     This program is free software; you can redistribute it and/or modify
+ *     it under the terms of the GNU General Public License as published by
+ *     the Free Software Foundation; either version 2 of the License, or
+ *     (at your option) any later version.
+ *
+ *     A copy of the GNU General Public License can be found at
+ *     http://www.gnu.org/
+ *
+ */
+
+#ifndef SETUP_QUIET_H
+#define SETUP_QUIET_H
+
+#include "getopt++/StringChoiceOption.h"
+
+typedef enum
+{
+  QuietUnattended,
+  QuietNoInput,
+  QuietHidden,
+} QuietEnum;
+
+extern StringChoiceOption UnattendedOption;
+
+#endif /* SETUP_QUIET_H */
diff --git a/res/en/res.rc b/res/en/res.rc
index e2f04fd..68869af 100644
--- a/res/en/res.rc
+++ b/res/en/res.rc
@@ -693,7 +693,7 @@ BEGIN
     IDS_HELPTEXT_PROXY "HTTP/FTP proxy (host:port)"
     IDS_HELPTEXT_PRUNE_INSTALL "Prune the installation to only the requested packages"
     IDS_HELPTEXT_PUBKEY "URL or absolute path of extra public key file (RFC4880 format)"
-    IDS_HELPTEXT_QUIET_MODE "Unattended setup mode"
+    IDS_HELPTEXT_QUIET_MODE "Unattended setup mode (unattended, noinput, hidden)"
     IDS_HELPTEXT_REMOVE_CATEGORIES "Specify categories to uninstall"
     IDS_HELPTEXT_REMOVE_PACKAGES "Specify packages to uninstall"
     IDS_HELPTEXT_ROOT "Root installation directory"
-- 
2.39.0


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-04-20 13:58 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-20 13:57 [PATCH setup] Enhance quiet mode to allow window to be input-disabled or hidden Jon Turney

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).