Skip to content

Commit 354c2c3

Browse files
committed
Adding dynamic wallpaper on and off
Adding dynamic wallpaper on and off
1 parent ecc480f commit 354c2c3

File tree

4 files changed

+91
-26
lines changed

4 files changed

+91
-26
lines changed

Nimble/Helpers/ConfigHelper.cs

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
using System;
22
using System.Configuration;
3+
using System.IO.Ports;
4+
using System.Windows.Media;
35

46
namespace Nimble.Helpers
57
{
@@ -10,8 +12,9 @@ public partial class ConfigHelper
1012
{
1113
public static bool EdgeHide { get; set; }
1214
public static double Opacity { get; set; }
13-
public static bool CustomJson { get;private set; }
15+
public static bool CustomJson { get; private set; }
1416
public static bool Startup { get; set; }
17+
public static bool OpenWallpaper { get; set; }
1518
public static string WallpaperPath { get; set; }
1619
public static void GetConfigHelper()
1720
{
@@ -33,9 +36,15 @@ public static void GetConfigHelper()
3336

3437
bool startup;
3538
if (!bool.TryParse(string.IsNullOrWhiteSpace(ConfigurationManager.AppSettings["Startup"]) ? "false" : ConfigurationManager.AppSettings["Startup"], out startup))
36-
startup = false;
39+
Startup = false;
3740
else
38-
startup = Convert.ToBoolean(string.IsNullOrWhiteSpace(ConfigurationManager.AppSettings["Startup"]) ? "false" : ConfigurationManager.AppSettings["Startup"]);
41+
Startup = Convert.ToBoolean(string.IsNullOrWhiteSpace(ConfigurationManager.AppSettings["Startup"]) ? "false" : ConfigurationManager.AppSettings["Startup"]);
42+
43+
bool openWallpaper;
44+
if (!bool.TryParse(string.IsNullOrWhiteSpace(ConfigurationManager.AppSettings["OpenWallpaper"]) ? "false" : ConfigurationManager.AppSettings["OpenWallpaper"], out openWallpaper))
45+
OpenWallpaper = false;
46+
else
47+
OpenWallpaper = Convert.ToBoolean(string.IsNullOrWhiteSpace(ConfigurationManager.AppSettings["OpenWallpaper"]) ? "false" : ConfigurationManager.AppSettings["OpenWallpaper"]);
3948

4049
WallpaperPath = string.IsNullOrWhiteSpace(ConfigurationManager.AppSettings["WallpaperPath"]) ? string.Empty : ConfigurationManager.AppSettings["WallpaperPath"];
4150
}
@@ -50,6 +59,7 @@ double GetOpacity()
5059
}
5160
public static void SaveOpacity(double opacity)
5261
{
62+
Opacity = opacity;
5363
SaveConfig("Opacity", opacity.ToString());
5464
}
5565

@@ -64,18 +74,27 @@ bool GetEdgeHide()
6474
}
6575
public static void SaveEdgeHide(bool edgeHide)
6676
{
77+
EdgeHide = edgeHide;
6778
SaveConfig("EdgeHide", edgeHide.ToString());
6879
}
6980

7081
public static void SaveStartup(bool startUp)
7182
{
83+
Startup = startUp;
7284
SaveConfig("Startup", startUp.ToString());
7385
}
86+
87+
public static void SaveOpenWallpaper(bool openWallpaper)
88+
{
89+
OpenWallpaper = openWallpaper;
90+
SaveConfig("OpenWallpaper", openWallpaper.ToString());
91+
}
7492
public static void SaveWallpaperPath(string path)
7593
{
94+
WallpaperPath = path;
7695
SaveConfig("WallpaperPath", path);
7796
}
78-
static void SaveConfig(string key,string value)
97+
static void SaveConfig(string key, string value)
7998
{
8099
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
81100
config.AppSettings.Settings.Remove(key);

Nimble/Models/WallpaperItem.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,16 @@
22
{
33
public class WallpaperItem : ItemBase
44
{
5-
public string ItemName { get; set; }
5+
private string _itemName;
6+
public string ItemName
7+
{
8+
get => _itemName;
9+
set
10+
{
11+
_itemName = value;
12+
NotifyPropertyChange("ItemName");
13+
}
14+
}
615
public string VideoPath { get; set; }
716
}
817
}

Nimble/ViewModels/MainVM.cs

Lines changed: 57 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ public MainVM()
4848
private IntPtr desktopHandle;
4949
private Process ffplayProcess;
5050
private IntPtr ffplayWindowHandle;
51+
private readonly string _exitWallpaper = "ExitWallpaper";
5152

5253
#endregion
5354

@@ -237,23 +238,7 @@ public List<WallpaperItem> WallpaperArray
237238

238239
#endregion
239240

240-
#region Wallpaper
241-
var wallpaersPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Video");
242-
if (Directory.Exists(wallpaersPath))
243-
{
244-
var names = new List<WallpaperItem>();
245-
var files = Directory.GetFiles(wallpaersPath);
246-
foreach (var filePath in files)
247-
{
248-
var fileName = Path.GetFileNameWithoutExtension(filePath);
249-
names.Add(new WallpaperItem { ItemName = fileName, VideoPath = filePath, IsSelected = ConfigHelper.WallpaperPath == filePath ? true : false });
250-
}
251-
names.Add(new WallpaperItem { ItemName = "更多壁纸请加QQ群:929469013" });
252-
WallpaperArray = names;
253-
if (WallpaperArray.Count > 0)
254-
ShowWallpaper(ConfigHelper.WallpaperPath);
255-
}
256-
#endregion
241+
WallpaersFilePlay();
257242

258243
if (Common.ApplicationListCache == null)
259244
{
@@ -430,8 +415,30 @@ private void ScreenCapturer_SnapCompleted(CroppedBitmap bitmap)
430415
{
431416
if (obj is WallpaperItem wallpaper)
432417
{
433-
if (string.IsNullOrWhiteSpace(wallpaper.VideoPath)) return;
434-
ShowWallpaper(wallpaper.VideoPath);
418+
if (wallpaper.VideoPath == _exitWallpaper)
419+
{
420+
if (!wallpaper.IsSelected)
421+
{
422+
StopFFplayProcess();
423+
wallpaper.ItemName = "壁纸已关闭";
424+
wallpaper.IsSelected = false;
425+
}
426+
else
427+
{
428+
WallpaersFilePlay();
429+
wallpaper.ItemName = "壁纸已开启";
430+
wallpaper.IsSelected = true;
431+
}
432+
}
433+
else
434+
{
435+
if (string.IsNullOrWhiteSpace(wallpaper.VideoPath)) return;
436+
if (File.Exists(wallpaper.VideoPath))
437+
{
438+
ShowWallpaper(wallpaper.VideoPath);
439+
}
440+
441+
}
435442
}
436443

437444
});
@@ -444,10 +451,16 @@ void ShowWallpaper(string wallpaperPath)
444451
{
445452
if (string.IsNullOrWhiteSpace(wallpaperPath) || !File.Exists(wallpaperPath)) return;
446453
StopFFplayProcess();
447-
WallpaperArray.Where(x => x.VideoPath != wallpaperPath).ToList().ForEach(x =>
454+
WallpaperArray.Where(x => x.VideoPath != wallpaperPath && x.VideoPath != _exitWallpaper).ToList().ForEach(x =>
448455
{
449456
x.IsSelected = false;
450457
});
458+
var wallpaper = WallpaperArray.FirstOrDefault(x => x.VideoPath == _exitWallpaper);
459+
if (wallpaper != null)
460+
{
461+
wallpaper.ItemName = "壁纸已开启";
462+
wallpaper.IsSelected = true;
463+
}
451464
StartFFplayProcess(wallpaperPath);
452465
if (ffplayWindowHandle != IntPtr.Zero)
453466
{
@@ -509,7 +522,7 @@ private void MouseHook_MouseDown(object sender, MouseEventArgs e)
509522
{
510523
_timer.Stop();
511524
mouseHook.Stop();
512-
if (colorView != null)
525+
if (colorView != null)
513526
colorView.Close();
514527
}
515528
}
@@ -587,6 +600,29 @@ void StopFFplayProcess()
587600
Log.Error($"Error: StopFFplayProcess {ex.Message}");
588601
}
589602
}
603+
void WallpaersFilePlay()
604+
{
605+
WallpaperArray = null;
606+
#region Wallpaper
607+
var wallpaersPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Video");
608+
if (Directory.Exists(wallpaersPath))
609+
{
610+
var names = new List<WallpaperItem>();
611+
var files = Directory.GetFiles(wallpaersPath);
612+
foreach (var filePath in files)
613+
{
614+
var fileName = Path.GetFileNameWithoutExtension(filePath);
615+
names.Add(new WallpaperItem { ItemName = fileName, VideoPath = filePath, IsSelected = ConfigHelper.WallpaperPath == filePath ? true : false });
616+
}
617+
if (names.Count > 0)
618+
names.Add(new WallpaperItem { ItemName = ConfigHelper.OpenWallpaper == true ? "壁纸已开启" : "壁纸已关闭", VideoPath = _exitWallpaper, IsSelected = ConfigHelper.OpenWallpaper });
619+
names.Add(new WallpaperItem { ItemName = "更多壁纸请加QQ群:929469013" });
620+
WallpaperArray = names;
621+
if (WallpaperArray.Count > 0)
622+
ShowWallpaper(ConfigHelper.WallpaperPath);
623+
}
624+
#endregion
625+
}
590626
#endregion
591627
}
592628
}

Nimble/app.config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
-->
2626
<add key="CustomJson" value="false"/>
2727
<add key="Startup" value="false"/>
28+
<add key="OpenWallpaper" value="true"/>
2829
<add key="WallpaperPath" value=""/>
2930
</appSettings>
3031
</configuration>

0 commit comments

Comments
 (0)