Skip to content

Commit f994779

Browse files
committed
Added graceful exit as settings option
1 parent 0b79811 commit f994779

File tree

3 files changed

+30
-19
lines changed

3 files changed

+30
-19
lines changed

src/ReolinkRestart/ReolinkClient/ReolinkClientService.cs

+14-4
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,21 @@ public void Terminate(bool waitForExit = false)
3030
{
3131
var process = GetClientProcess();
3232

33-
process?.CloseMainWindow();
34-
35-
if (waitForExit)
33+
if (process != null)
3634
{
37-
process?.WaitForExit();
35+
if (settingsService.Settings!.ReolinkClientGracefulExit)
36+
{
37+
process.CloseMainWindow();
38+
}
39+
else
40+
{
41+
process.Kill();
42+
}
43+
44+
if (waitForExit)
45+
{
46+
process.WaitForExit();
47+
}
3848
}
3949
}
4050

src/ReolinkRestart/Settings/Settings.cs

+8-6
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,18 @@
22
{
33
public class Settings
44
{
5-
public required string ReolinkExecutableFilePath { get; set; }
5+
public string ReolinkExecutableFilePath { get; set; } = @"%localAppData%\Programs\Reolink\Reolink.exe";
66

7-
public required int RestartIntervalMinutes { get; set; }
7+
public int RestartIntervalMinutes { get; set; } = 60;
88

9-
public required bool UseFullscreen { get; set; }
9+
public bool UseFullscreen { get; set; } = true;
1010

11-
public required int FullscreenDelaySeconds { get; set; }
11+
public int FullscreenDelaySeconds { get; set; } = 4;
1212

13-
public required int FullscreenXOffset { get; set; }
13+
public int FullscreenXOffset { get; set; } = 50;
1414

15-
public required int FullscreenYOffset { get; set; }
15+
public int FullscreenYOffset { get; set; } = 40;
16+
17+
public bool ReolinkClientGracefulExit { get; set; } = true;
1618
}
1719
}

src/ReolinkRestart/Settings/SettingsService.cs

+8-9
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,12 @@ public bool ValidateAndLoadSettings(out string? message)
2828

2929
private void CreateSettings()
3030
{
31-
var settings = new Settings
32-
{
33-
ReolinkExecutableFilePath = @"%localAppData%\Programs\Reolink\Reolink.exe",
34-
RestartIntervalMinutes = 60,
35-
UseFullscreen = true,
36-
FullscreenDelaySeconds = 4,
37-
FullscreenXOffset = 50,
38-
FullscreenYOffset = 40
39-
};
31+
var settings = new Settings();
32+
WriteSettings(settings);
33+
}
4034

35+
private void WriteSettings(Settings settings)
36+
{
4137
var json = JsonSerializer.Serialize(settings, new JsonSerializerOptions { WriteIndented = true });
4238
File.WriteAllText(SettingsFileName, json);
4339
}
@@ -47,6 +43,9 @@ private void LoadSettings()
4743
var json = File.ReadAllText(SettingsFileName);
4844
Settings = JsonSerializer.Deserialize<Settings>(json)!;
4945

46+
// Write the settings back in-case there are new options
47+
WriteSettings(Settings);
48+
5049
Settings!.ReolinkExecutableFilePath = Environment.ExpandEnvironmentVariables(Settings.ReolinkExecutableFilePath);
5150
}
5251

0 commit comments

Comments
 (0)