Skip to content

Commit 29a951a

Browse files
committed
Further improvements to error handling during theme load/import
1 parent 330612e commit 29a951a

12 files changed

+89
-71
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ This is a commonly requested feature to mimic the behavior of macOS and many Lin
3535

3636
You are not limited to the Mojave themes that come preinstalled with the app. Custom themes created by the community can be downloaded [here](https://github.com/t1m0thyj/WinDynamicDesktop/wiki/Community-created-themes). You can also create your own theme that uses whatever wallpaper images you want, by following the instructions in [this tutorial](https://github.com/t1m0thyj/WinDynamicDesktop/wiki/Creating-custom-themes).
3737

38+
### Can I translate the app into my language?
39+
40+
Yes, translations are welcome. For instructions on how to create them and where to submit them, see [here](https://github.com/t1m0thyj/WDD-locale).
41+
3842
### How can I hide the tray icon?
3943

4044
If you want to run the app silently with no icon in the system tray, you can do this by editing the `settings.conf` file which is in the same folder as the EXE. Change the setting `"hideTrayIcon":false` to `"hideTrayIcon":true` (or add it if it doesn't exist), then restart the app.

src/AboutDialog.Designer.cs

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

src/AboutDialog.cs

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,35 @@ public AboutDialog()
2626
this.Font = SystemFonts.MessageBoxFont;
2727
this.nameLabel.Font = new Font(this.Font.Name, this.Font.Size * 1.2F, FontStyle.Bold);
2828

29-
int minWidth = TextRenderer.MeasureText(this.descriptionLabel.Text, this.Font).Width;
30-
minWidth = minWidth + (this.descriptionLabel.Width - minWidth) / 2 +
31-
this.descriptionLabel.Location.X * 2;
29+
int minWidth = TextRenderer.MeasureText(descriptionLabel.Text, this.Font).Width;
30+
31+
if (this.descriptionLabel.Width < minWidth)
32+
{
33+
minWidth += descriptionLabel.Location.X * 2;
34+
nameLabel.Width = minWidth;
35+
copyrightLabel.Width = minWidth;
36+
descriptionLabel.Width = minWidth;
37+
websiteLabel.Width = minWidth;
38+
}
39+
40+
minWidth = minWidth + (descriptionLabel.Width - minWidth) / 2 +
41+
descriptionLabel.Location.X * 2;
3242

3343
if (this.Size.Width < minWidth)
3444
{
3545
this.Size = new Size(minWidth, this.Size.Height);
3646
this.CenterToScreen();
3747
}
48+
49+
minWidth = TextRenderer.MeasureText(creditsButton.Text, this.Font).Width + 10;
50+
51+
if (this.creditsButton.Width < minWidth)
52+
{
53+
int oldWidth = creditsButton.Width;
54+
creditsButton.Width = minWidth;
55+
donateButton.Location = new Point(donateButton.Location.X + minWidth - oldWidth,
56+
donateButton.Location.Y);
57+
}
3858
}
3959

4060
private void AboutDialog_Load(object sender, EventArgs e)

src/App.config

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<configuration>
3-
<startup>
4-
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2"/>
5-
</startup>
3+
<startup>
4+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1"/>
5+
</startup>
66
<runtime>
77
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
88
<dependentAssembly>
@@ -11,7 +11,4 @@
1111
</dependentAssembly>
1212
</assemblyBinding>
1313
</runtime>
14-
<System.Windows.Forms.ApplicationConfigurationSection>
15-
<add key="DpiAwareness" value="PerMonitorV2" />
16-
</System.Windows.Forms.ApplicationConfigurationSection>
1714
</configuration>

src/ProgressDialog.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,15 +124,16 @@ private void ImportNext()
124124
string themePath = importQueue.Peek();
125125
this.Invoke(new Action(() => UpdateImportStatus(themePath)));
126126
ThemeConfig theme = ThemeManager.ImportTheme(themePath);
127-
this.Invoke(new Action(() => ThemeLoader.HandleError(theme.themeId)));
127+
this.Invoke(new Action(() => ThemeLoader.HandleError(
128+
Path.GetFileNameWithoutExtension(themePath))));
128129

129130
if (theme != null)
130131
{
131132
if (Path.GetExtension(themePath) == ".json")
132133
{
133134
downloadQueue = new Queue<ThemeConfig>(
134135
new List<ThemeConfig>() { theme });
135-
DownloadNext(); // TODO Test if this works
136+
DownloadNext(); // TODO Test this
136137
}
137138

138139
ThemeManager.importedThemes.Add(theme);
@@ -172,7 +173,7 @@ private void OnDownloadProgressChanged(object sender, DownloadProgressChangedEve
172173
{
173174
UpdateTotalPercentage(e.ProgressPercentage);
174175

175-
fileTransferSpeedLabel.Text = string.Format(_("{0} MB/s"),
176+
fileTransferSpeedLabel.Text = string.Format(_("{0} MB/s"),
176177
(e.BytesReceived / 1024f / 1024f / stopwatch.Elapsed.TotalSeconds).ToString("0.#"));
177178

178179
fileSizeProgressLabel.Text = string.Format(_("{0} MB of {1} MB"),
@@ -211,7 +212,8 @@ await Task.Run(() => ThemeLoader.ExtractTheme(theme.themeId + "_images.zip",
211212
}
212213
else
213214
{
214-
ThemeManager.DisableTheme(theme.themeId); // TODO Handle error here for failed download
215+
ThemeLoader.HandleError(theme.themeId, string.Format(
216+
_("Failed to download images for the '{0}' theme"), theme.themeId));
215217
}
216218
}
217219

src/ThemeDialog.Designer.cs

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

src/ThemeDialog.cs

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public ThemeDialog()
4747

4848
public void ImportThemes(List<string> themePaths)
4949
{
50-
ProgressDialog importDialog = new ProgressDialog();
50+
ProgressDialog importDialog = new ProgressDialog() { Owner = this };
5151
importDialog.FormClosing += OnImportDialogClosing;
5252
importDialog.Show();
5353
importDialog.InitImport(themePaths);
@@ -164,14 +164,9 @@ private string GetCreditsText()
164164
private List<int> GetImageList(ThemeConfig theme)
165165
{
166166
List<int> imageList = new List<int>();
167-
168-
if (!darkModeCheckbox.Checked)
169-
{
170-
imageList.AddRange(theme.sunriseImageList);
171-
imageList.AddRange(theme.dayImageList);
172-
imageList.AddRange(theme.sunsetImageList);
173-
}
174-
167+
imageList.AddRange(theme.sunriseImageList);
168+
imageList.AddRange(theme.dayImageList);
169+
imageList.AddRange(theme.sunsetImageList);
175170
imageList.AddRange(theme.nightImageList);
176171
return imageList;
177172
}
@@ -274,8 +269,6 @@ private void ThemeDialog_Load(object sender, EventArgs e)
274269
imageListView1.ContextMenuStrip = contextMenuStrip1;
275270
imageListView1.SetRenderer(new ThemeListViewRenderer());
276271

277-
darkModeCheckbox.Checked = JsonConfig.settings.darkMode;
278-
279272
Size thumbnailSize = GetThumbnailSize();
280273
imageListView1.ThumbnailSize = thumbnailSize;
281274
imageListView1.Items.Add(_("None"), ShrinkImage(windowsWallpaper, thumbnailSize.Width,
@@ -337,8 +330,7 @@ private void imageListView1_SelectionChanged(object sender, EventArgs e)
337330
SolarData solarData = SunriseSunsetService.GetSolarData(DateTime.Today);
338331
ThemeConfig theme = ThemeManager.themeSettings[selectedIndex - 1];
339332
imageNumber = GetImageList(theme).IndexOf(
340-
AppContext.wpEngine.GetImageData(solarData, theme,
341-
darkModeCheckbox.Checked).Item1) + 1;
333+
AppContext.wpEngine.GetImageData(solarData, theme).Item1) + 1;
342334
}
343335

344336
creditsLabel.Text = GetCreditsText();
@@ -413,8 +405,6 @@ private void applyButton_Click(object sender, EventArgs e)
413405
}
414406

415407
JsonConfig.settings.themeName = ThemeManager.currentTheme?.themeId;
416-
JsonConfig.settings.darkMode = darkModeCheckbox.Checked;
417-
MainMenu.darkModeItem.Checked = JsonConfig.settings.darkMode;
418408

419409
if (selectedIndex == 0)
420410
{

src/ThemeLoader.cs

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,20 +72,32 @@ public static void HandleError(string themeId)
7272
TaskbarProgress.SetState(taskbarHandle, TaskbarProgress.TaskbarStates.Error);
7373
}
7474

75-
MessageBox.Show(string.Format(_("Failed to load '{0}' theme:\n{1}"), themeId,
76-
errorMsg), _("Error"), MessageBoxButtons.OK, MessageBoxIcon.Warning);
75+
if (!ThemeManager.importMode)
76+
{
77+
DialogResult result = MessageBox.Show(string.Format(_("Failed to load '{0}' " +
78+
"theme:\n{1}\n\nDo you want to disable this theme to prevent the error from " +
79+
"happening again?"), themeId, errorMsg), _("Error"), MessageBoxButtons.YesNo,
80+
MessageBoxIcon.Warning);
81+
ThemeManager.DisableTheme(themeId, result == DialogResult.Yes);
82+
}
83+
else
84+
{
85+
MessageBox.Show(string.Format(_("Failed to import '{0}' theme:\n{1}"), themeId,
86+
errorMsg), _("Error"), MessageBoxButtons.OK, MessageBoxIcon.Warning);
87+
}
7788

7889
if (taskbarHandle != IntPtr.Zero)
7990
{
8091
TaskbarProgress.SetState(taskbarHandle, TaskbarProgress.TaskbarStates.Normal);
8192
}
8293

8394
errorMsg = null;
95+
}
8496

85-
if (!ThemeManager.importMode)
86-
{
87-
ThemeManager.DisableTheme(themeId);
88-
}
97+
public static void HandleError(string themeId, string errorText)
98+
{
99+
errorMsg = errorText;
100+
HandleError(themeId);
89101
}
90102

91103
public static bool PromptDialog(string dialogText)

src/ThemeManager.cs

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -73,19 +73,16 @@ public static string GetThemeName(ThemeConfig theme)
7373
return theme.displayName ?? theme.themeId.Replace('_', ' ');
7474
}
7575

76-
public static void DisableTheme(string themeId)
76+
public static void DisableTheme(string themeId, bool permanent)
7777
{
7878
themeSettings.RemoveAll(t => t.themeId == themeId);
7979

80-
if (currentTheme.themeId == themeId)
80+
if (currentTheme != null && (currentTheme.themeId == themeId))
8181
{
8282
currentTheme = null;
8383
}
8484

85-
bool shouldDisable = ThemeLoader.PromptDialog(_("The '{0}' theme could not be " +
86-
"loaded. Do you want to disable it to prevent this error from happening again?"));
87-
88-
if (shouldDisable)
85+
if (permanent)
8986
{
9087
Directory.Move(Path.Combine("themes", themeId),
9188
Path.Combine("themes", "." + themeId));
@@ -109,17 +106,22 @@ public static ThemeConfig ImportTheme(string importPath)
109106
}
110107

111108
Directory.CreateDirectory(Path.Combine("themes", themeId));
109+
bool shouldContinue = true;
110+
ThemeConfig theme = null;
112111

113112
if (Path.GetExtension(importPath) != ".json")
114113
{
115-
ThemeLoader.ExtractTheme(importPath, themeId);
114+
shouldContinue = ThemeLoader.ExtractTheme(importPath, themeId);
116115
}
117116
else
118117
{
119118
File.Copy(importPath, Path.Combine("themes", themeId, "theme.json"), true);
120119
}
121120

122-
ThemeConfig theme = ThemeLoader.TryLoad(themeId);
121+
if (shouldContinue)
122+
{
123+
theme = ThemeLoader.TryLoad(themeId);
124+
}
123125

124126
if (theme == null)
125127
{
@@ -198,14 +200,21 @@ private static void DownloadMissingImages()
198200
LaunchSequence.NextStep();
199201
return;
200202
}
203+
204+
foreach (ThemeConfig theme in
205+
missingThemes.Where(theme => string.IsNullOrEmpty(theme.imagesZipUri)))
206+
{
207+
missingThemes.Remove(theme);
208+
ThemeLoader.HandleError(theme.themeId,
209+
string.Format(_("Failed to find images for the '{0}' theme"), theme.themeId));
210+
}
201211

202212
downloadDialog = new ProgressDialog();
203213
downloadDialog.FormClosed += OnDownloadDialogClosed;
204214
downloadDialog.Show();
205215

206216
MainMenu.themeItem.Enabled = false;
207-
downloadDialog.InitDownload(missingThemes.FindAll(
208-
theme => !string.IsNullOrEmpty(theme.imagesZipUri))); // TODO Handle error if null or empty and missing images
217+
downloadDialog.InitDownload(missingThemes);
209218
}
210219

211220
private static void OnDownloadDialogClosed(object sender, EventArgs e)

src/WallpaperChangeScheduler.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,7 @@ public void RunScheduler(bool forceImageUpdate = false)
5858
lastImagePath = null;
5959
}
6060

61-
Tuple<int, long> imageData = GetImageData(data, ThemeManager.currentTheme,
62-
JsonConfig.settings.darkMode);
61+
Tuple<int, long> imageData = GetImageData(data, ThemeManager.currentTheme);
6362
SetWallpaper(imageData.Item1);
6463
nextImageUpdateTime = new DateTime(imageData.Item2);
6564
}
@@ -109,13 +108,13 @@ private DaySegment GetCurrentDaySegment(SolarData data)
109108
}
110109
}
111110

112-
public Tuple<int, long> GetImageData(SolarData data, ThemeConfig theme, bool darkMode)
111+
public Tuple<int, long> GetImageData(SolarData data, ThemeConfig theme)
113112
{
114113
int[] imageList;
115114
DateTime segmentStart;
116115
DateTime segmentEnd;
117116

118-
if (!darkMode)
117+
if (!JsonConfig.settings.darkMode)
119118
{
120119
switch (GetCurrentDaySegment(data))
121120
{

src/WinDynamicDesktop.csproj

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,11 @@
1010
<OutputType>WinExe</OutputType>
1111
<RootNamespace>WinDynamicDesktop</RootNamespace>
1212
<AssemblyName>WinDynamicDesktop</AssemblyName>
13-
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
13+
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
1414
<FileAlignment>512</FileAlignment>
1515
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
1616
<NuGetPackageImportStamp>
1717
</NuGetPackageImportStamp>
18-
<TargetFrameworkProfile />
1918
</PropertyGroup>
2019
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
2120
<PlatformTarget>AnyCPU</PlatformTarget>

0 commit comments

Comments
 (0)