Skip to content
This repository was archived by the owner on Sep 15, 2025. It is now read-only.

Commit 856d099

Browse files
committed
Start settings UI, tweak connection logic
Added a settings UI and settings button to the main menu. Added a connect button and changed the behavior of the initial scan. Rather than close when no devices are found, all buttons (aside from settings) are disabled until a device is connected.
1 parent 0ca8cec commit 856d099

9 files changed

Lines changed: 550 additions & 16 deletions

FlashForgeUI.csproj

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,12 @@
150150
<Compile Include="ui\window\SendCommandWindow.Designer.cs">
151151
<DependentUpon>SendCommandWindow.cs</DependentUpon>
152152
</Compile>
153+
<Compile Include="ui\window\SettingsWindow.cs">
154+
<SubType>Form</SubType>
155+
</Compile>
156+
<Compile Include="ui\window\SettingsWindow.Designer.cs">
157+
<DependentUpon>SettingsWindow.cs</DependentUpon>
158+
</Compile>
153159
<Compile Include="webui\PrinterWebServer.cs" />
154160
<Compile Include="webui\WebServerBridge.cs" />
155161
<EmbeddedResource Include="Properties\Resources.resx">
@@ -179,6 +185,9 @@
179185
<EmbeddedResource Include="ui\window\SendCommandWindow.resx">
180186
<DependentUpon>SendCommandWindow.cs</DependentUpon>
181187
</EmbeddedResource>
188+
<EmbeddedResource Include="ui\window\SettingsWindow.resx">
189+
<DependentUpon>SettingsWindow.cs</DependentUpon>
190+
</EmbeddedResource>
182191
<None Include="packages.config" />
183192
<None Include="Properties\Settings.settings">
184193
<Generator>SettingsSingleFileGenerator</Generator>

Folder.DotSettings.user

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
22
<s:Boolean x:Key="/Default/AddReferences/RecentPaths/=C_003A_005CUsers_005CCope_005CRiderProjects_005CSlicerMeta_005Cbin_005CDebug_005CSlicerMeta_002Edll/@EntryIndexedValue">True</s:Boolean>
3+
<s:Boolean x:Key="/Default/AddReferences/RecentPaths/=C_003A_005CUsers_005CCope_005CRiderProjects_005CSlicerMeta_005Cbin_005CDebug_005CSlicerMeta_002Epdb/@EntryIndexedValue">True</s:Boolean>
4+
<s:String x:Key="/Default/Environment/AssemblyExplorer/XmlDocument/@EntryValue">&lt;AssemblyExplorer /&gt;</s:String>
35
<s:Boolean x:Key="/Default/ResxEditorPersonal/CheckedGroups/=FlashForgeUI_002FForm1/@EntryIndexedValue">True</s:Boolean>
46
<s:Boolean x:Key="/Default/ResxEditorPersonal/Initialized/@EntryValue">True</s:Boolean></wpf:ResourceDictionary>

ui/main/MainMenu.Designer.cs

Lines changed: 51 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ui/main/MainMenu.cs

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public partial class MainMenu : Form
2828

2929
public FiveMClient printerClient;
3030

31-
private PrinterWebServer webServer;
31+
internal PrinterWebServer webServer;
3232

3333
internal WebhookHelper webhook;
3434

@@ -46,7 +46,8 @@ public MjpegStreamManager GetMjpegStreamManager()
4646
{ // for WebhookHelper (sending preview image to discord)
4747
return StreamManager;
4848
}
49-
49+
50+
internal bool isConnected = false;
5051
internal bool WebcamOn;
5152

5253
public MainMenu()
@@ -315,7 +316,7 @@ public dynamic GetPrinterStatus()
315316

316317

317318

318-
// Events (no idea if this will work)
319+
// Events
319320

320321
internal async void MainMenu_Shown(object sender, EventArgs e)
321322
{
@@ -329,7 +330,12 @@ internal async void MainMenu_Shown(object sender, EventArgs e)
329330

330331
// load config
331332
config = new Config().Load();
332-
333+
334+
isConnected = await Connect();
335+
}
336+
337+
internal async Task<bool> Connect()
338+
{
333339
var connected = await _connectionManager.FindPrinterAndConnect();
334340
if (connected)
335341
{
@@ -341,12 +347,11 @@ internal async void MainMenu_Shown(object sender, EventArgs e)
341347
if (config.DiscordSync) InitWebhook(); // only check/enable the webhook if the user actually enabled it.
342348
await StartTimers();
343349
if (config.WebUi) StartWebUi();
350+
351+
return true;
344352
}
345-
else
346-
{
347-
// If not connected, close the application
348-
Close();
349-
}
353+
354+
return false;
350355
}
351356

352357
internal void MainMenu_Closing(object sender, CancelEventArgs cancelEventArgs)
@@ -560,5 +565,15 @@ private async void clearPlatformButton_Click(object sender, EventArgs e)
560565
{
561566
await _buttonManager.ClearPlatform();
562567
}
568+
569+
private void settingsButton_Click(object sender, EventArgs e)
570+
{
571+
_buttonManager.OpenSettings();
572+
}
573+
574+
private async void connectButton_Click(object sender, EventArgs e)
575+
{
576+
isConnected = await Connect();
577+
}
563578
}
564579
}

ui/main/manager/ButtonManager.cs

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,38 @@ public ButtonManager(ui.main.MainMenu form1)
1616
_ui = form1;
1717
}
1818

19+
private bool Check()
20+
{
21+
if (!_ui.isConnected)
22+
{
23+
MessageBox.Show("Connect to a printer first!", "Not connected");
24+
return false;
25+
}
26+
27+
return true;
28+
}
29+
30+
31+
1932
// LEDs
2033
public async Task LedOn()
2134
{
35+
if (!Check()) return;
2236
await _ui.printerClient.Control.SetLedOn();
2337
_ui.AppendLog("LED turned on.");
2438
}
2539

2640
public async Task LedOff()
2741
{
42+
if (!Check()) return;
2843
await _ui.printerClient.Control.SetLedOff();
2944
_ui.AppendLog("LED turned off.");
3045
}
3146

3247

3348
public void TogglePreview()
3449
{
50+
if (!Check()) return;
3551
if (_ui.printerClient == null) return;
3652
if (!_ui.printerClient.IsPro && !_ui.config.CustomCamera) // check for webcam or custom setup
3753
{
@@ -56,6 +72,7 @@ public void TogglePreview()
5672
// Filtration
5773
public async Task FilteringOff()
5874
{
75+
if (!Check()) return;
5976
// todo this needs to be coded into the webUI, this is a lazy fix for now since it will invoke this (indirectly) anyways
6077
if (!_ui.printerClient.IsPro)
6178
{
@@ -68,6 +85,7 @@ public async Task FilteringOff()
6885

6986
public async Task ExternalFilterOn()
7087
{
88+
if (!Check()) return;
7189
// todo same for here
7290
if (!_ui.printerClient.IsPro)
7391
{
@@ -83,6 +101,7 @@ public async Task ExternalFilterOn()
83101

84102
public async Task InternalFilterOn()
85103
{
104+
if (!Check()) return;
86105
// todo also same for here
87106
if (!_ui.printerClient.IsPro)
88107
{
@@ -99,13 +118,15 @@ public async Task InternalFilterOn()
99118
// Fans
100119
public async Task SetCoolingFanSpeed()
101120
{
121+
if (!Check()) return;
102122
var input = Interaction.InputBox("Fan speed (0-100)", "Set Cooling Fan Speed", "0");
103123
if (int.TryParse(input, out var speed)) await _ui.printerClient.Control.SetCoolingFanSpeed(speed);
104124
else _ui.AppendLog("Setting cooling fan speed cancelled.");
105125
}
106126

107127
public async Task SetChamberFanSpeed()
108128
{
129+
if (!Check()) return;
109130
// todo this also needs to be coded into the web ui
110131
if (!_ui.printerClient.IsPro)
111132
{
@@ -121,6 +142,7 @@ public async Task SetChamberFanSpeed()
121142

122143
public async Task PauseJob()
123144
{
145+
if (!Check()) return;
124146
await _ui.CmdWait();
125147
if (!await _ui.printerClient.Info.IsPrinting()) _ui.AppendLog("No job to pause...");
126148
else if (!await _ui.printerClient.JobControl.PausePrintJob()) _ui.AppendLog("(Error) Unable to pause current job");
@@ -130,6 +152,7 @@ public async Task PauseJob()
130152

131153
public async Task ResumeJob()
132154
{
155+
if (!Check()) return;
133156
await _ui.CmdWait();
134157
// need to see what "state" is when paused, could be exactly that lol
135158
if (!await _ui.printerClient.JobControl.ResumePrintJob()) _ui.AppendLog("(Error) Unable to resume current job");
@@ -139,6 +162,7 @@ public async Task ResumeJob()
139162

140163
public async Task StopJob()
141164
{
165+
if (!Check()) return;
142166
await _ui.CmdWait();
143167
if (!await _ui.printerClient.Info.IsPrinting()) _ui.AppendLog("No job to stop...");
144168
else if (!await _ui.printerClient.JobControl.CancelPrintJob()) _ui.AppendLog("(Error) Unable to cancel current job");
@@ -148,6 +172,7 @@ public async Task StopJob()
148172

149173
public async Task ClearPlatform()
150174
{
175+
if (!Check()) return;
151176
if (!Compat.Is313OrAbove(_ui.printerClient.FirmVer)) return; // not supported below fw 3.13.3
152177
await _ui.CmdWait();
153178
var state = await _ui.printerClient.Info.GetState();
@@ -166,6 +191,7 @@ public async Task ClearPlatform()
166191
// Upload (and start) job/start local/recent (last 10) jobs
167192
public async Task<bool> SelectAndUploadGCodeFile()
168193
{
194+
if (!Check()) return false;
169195
using (var form = new GCodeFilePicker())
170196
{
171197
// todo this needs to be tested (the ReaLTaiizor refactor)
@@ -187,6 +213,7 @@ public async Task<bool> SelectAndUploadGCodeFile()
187213

188214
public async Task SelectRecentJob()
189215
{
216+
if (!Check()) return;
190217
var localFileList = new GCodeListWindow(_ui.printerClient); // get recent (last 10 files) list
191218
var result = localFileList.ShowDialog();
192219
localFileList.Dispose();
@@ -196,6 +223,7 @@ public async Task SelectRecentJob()
196223

197224
public async Task SelectLocalJob()
198225
{
226+
if (!Check()) return;
199227
var localFileList = new GCodeListWindow(_ui.printerClient, true); // get full list
200228
var result = localFileList.ShowDialog();
201229
localFileList.Dispose();
@@ -205,13 +233,22 @@ public async Task SelectLocalJob()
205233

206234
private async Task StartLocalJob(GCodeListWindow localFileListWindow)
207235
{ // get selected file from list and start the print
236+
if (!Check()) return;
208237
if (await _ui.printerClient.JobControl.PrintLocalFile(localFileListWindow.SelectedFileName,
209238
localFileListWindow.AutoLevel))
210239
{
211240
_ui.AppendLog($"Starting job {localFileListWindow.SelectedFileName}");
212241
}
213242
else _ui.AppendLog($"Error starting recent job {localFileListWindow.SelectedFileName}");
214243
}
215-
244+
245+
public void OpenSettings()
246+
{
247+
//if (!Check()) return;
248+
using (var form = new SettingsWindow(_ui))
249+
{
250+
form.ShowDialog();
251+
}
252+
}
216253
}
217254
}

0 commit comments

Comments
 (0)