Skip to content

Commit d1e8dcc

Browse files
committed
Made the disclaimer page show inside the main dialog
1 parent 52f2bdf commit d1e8dcc

1 file changed

Lines changed: 34 additions & 21 deletions

File tree

USBFunctionModeSwitcher/Program.cs

Lines changed: 34 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -113,30 +113,11 @@ private static void ShowTaskDialog()
113113
if (role.IsHost && role.HostRole.EnableVbus)
114114
{
115115
args.CancelClose = true;
116-
117-
var newPage = new TaskDialogPage()
118-
{
119-
Title = "USB Function Mode Switcher",
120-
Text = "Switching to this mode will enable power output from the USB Type C port. This may harm your device if you plug in a charging cable or a continuum dock. In this mode NEVER plug in any charging cable, wall charger, PC USB Cable (connected to a PC) or any externally powered USB hub! We cannot be taken responsible for any damage caused by this, you have been warned!",
121-
Instruction = "Do you really want to do this?",
122-
Icon = TaskDialogStandardIcon.Warning,
123-
CustomButtonStyle = TaskDialogCustomButtonStyle.CommandLinks,
124-
AllowCancel = true,
125-
SizeToContent = true
126-
};
127-
128-
TaskDialogCustomButton nobutton = newPage.CustomButtons.Add("No");
129-
TaskDialogCustomButton yesbutton = newPage.CustomButtons.Add("Yes I understand all the risks");
130-
131-
yesbutton.Click += (object sender2, TaskDialogButtonClickedEventArgs args2) =>
116+
ShowDisclaimerDialog(dialog, () =>
132117
{
133118
handler.CurrentUSBRole = role;
134-
dialog.Close();
135119
RebootDevice();
136-
};
137-
138-
var innerDialog = new TaskDialog(newPage);
139-
TaskDialogButton innerResult = innerDialog.Show();
120+
});
140121
}
141122
else
142123
{
@@ -177,6 +158,38 @@ private static void RebootDevice()
177158
Process.Start("shutdown", "/r /t 10 /f");
178159
}
179160

161+
private static void ShowDisclaimerDialog(TaskDialog dialog, Action action)
162+
{
163+
var newPage = new TaskDialogPage()
164+
{
165+
Title = "USB Function Mode Switcher",
166+
Text = "Switching to this mode will enable power output from the USB Type C port. This may harm your device if you plug in a charging cable or a continuum dock. In this mode NEVER plug in any charging cable, wall charger, PC USB Cable (connected to a PC) or any externally powered USB hub! We cannot be taken responsible for any damage caused by this, you have been warned!",
167+
Instruction = "Do you really want to do this?",
168+
Icon = TaskDialogStandardIcon.Warning,
169+
CustomButtonStyle = TaskDialogCustomButtonStyle.CommandLinks,
170+
AllowCancel = true,
171+
SizeToContent = true
172+
};
173+
174+
TaskDialogCustomButton nobutton = newPage.CustomButtons.Add("No");
175+
TaskDialogCustomButton yesbutton = newPage.CustomButtons.Add("Yes I understand all the risks");
176+
177+
yesbutton.Click += (object sender2, TaskDialogButtonClickedEventArgs args2) =>
178+
{
179+
action();
180+
};
181+
182+
var origpage = dialog.Page;
183+
184+
nobutton.Click += (object sender2, TaskDialogButtonClickedEventArgs args2) =>
185+
{
186+
args2.CancelClose = true;
187+
dialog.Page = origpage;
188+
};
189+
190+
dialog.Page = newPage;
191+
}
192+
180193
private static void ShowAboutDialog(TaskDialog dialog)
181194
{
182195
var newPage = new TaskDialogPage()

0 commit comments

Comments
 (0)