Skip to content

Commit

Permalink
refactored core.
Browse files Browse the repository at this point in the history
  • Loading branch information
rocksdanister committed Sep 4, 2020
1 parent 9fb61ed commit 3f7d83b
Show file tree
Hide file tree
Showing 17 changed files with 1,727 additions and 1,720 deletions.
1,635 changes: 0 additions & 1,635 deletions src/livelywpf/livelywpf/Core/Class/Wallpaper.cs

This file was deleted.

39 changes: 39 additions & 0 deletions src/livelywpf/livelywpf/Core/Interface/Wallpaper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Text;
using System.Windows;
using livelywpf.Model;

namespace livelywpf.Core
{
public interface IWallpaper
{
WallpaperType GetWallpaperType();
LibraryModel GetWallpaperData();
IntPtr GetHWND();
void SetHWND(IntPtr hwnd);
Process GetProcess();
void Show();
void Pause();
void Resume();
void Play();
void Stop();
void Close();
void Terminate();
LivelyScreen GetScreen();
void SetScreen(LivelyScreen display);
void SendMessage(string msg);
string GetLivelyPropertyCopyPath();
void SetVolume(int volume);
event EventHandler<WindowInitializedArgs> WindowInitialized;
}

public class WindowInitializedArgs
{
public bool Success { get; set; }
public Exception Error { get; set; }
public string Msg { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@

namespace livelywpf.Core
{
/// <summary>
/// System monitor logic to pause/unpause wallpaper playback.
/// </summary>
public class Playback
{
private static readonly NLog.Logger Logger = NLog.LogManager.GetCurrentClassLogger();
Expand Down
136 changes: 52 additions & 84 deletions src/livelywpf/livelywpf/Core/SetupDesktop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ public static class SetupDesktop
private static readonly List<IWallpaper> wallpapersPending = new List<IWallpaper>();
public static event EventHandler WallpaperChanged;

#endregion //init

#region core

static SetupDesktop()
{
SystemEvents.DisplaySettingsChanged += SystemEvents_DisplaySettingsChanged;
}

#endregion //init

#region core

public static void SetWallpaper(LibraryModel wp, LivelyScreen targetDisplay)
{
if (SystemParameters.HighContrast)
Expand Down Expand Up @@ -236,13 +236,13 @@ private static async void SetupDesktop_WallpaperInitialized(object sender, Windo
switch (Program.SettingsVM.Settings.WallpaperArrangement)
{
case WallpaperArrangement.per:
CloseWallpaperWithoutEvent(wallpaper.GetScreen());
CloseWallpaper(wallpaper.GetScreen(), false);
break;
case WallpaperArrangement.span:
CloseAllWallpapersWithoutEvent();
CloseAllWallpapers(false);
break;
case WallpaperArrangement.duplicate:
CloseAllWallpapersWithoutEvent();
CloseAllWallpapers(false);
break;
}
}
Expand Down Expand Up @@ -273,16 +273,16 @@ private static async void SetupDesktop_WallpaperInitialized(object sender, Windo
switch (Program.SettingsVM.Settings.WallpaperArrangement)
{
case WallpaperArrangement.per:
CloseWallpaperWithoutEvent(wallpaper.GetScreen());
CloseWallpaper(wallpaper.GetScreen(), false);
//CloseaWallpaperAfterDelay(wallpaper.GetScreen(), 500);
SetWallpaperPerScreen(wallpaper.GetHWND(), wallpaper.GetScreen());
break;
case WallpaperArrangement.span:
CloseAllWallpapersWithoutEvent();
CloseAllWallpapers(false);
SetWallpaperSpanScreen(wallpaper.GetHWND());
break;
case WallpaperArrangement.duplicate:
CloseAllWallpapersWithoutEvent();
CloseAllWallpapers(false);
SetWallpaperDuplicateScreen(wallpaper.GetHWND());
break;
}
Expand Down Expand Up @@ -449,7 +449,7 @@ public static void ShutDown()
WallpaperChanged -= SetupDesktop_WallpaperChanged;
processMonitor.Stop();
//CloseAllWallpapersWithoutEvent();
TerminateAllWallpapersWithoutEvent();
TerminateAllWallpapers(false);
RefreshDesktop();
}
}
Expand Down Expand Up @@ -625,14 +625,22 @@ public static Task ShowVLCScreenCaptureDialogSTAThread(IWallpaper wp)

#endregion threads

#region wallpaper close
#region wallpaper operations

public static void CloseAllWallpapers()
private static void CloseAllWallpapers(bool fireEvent)
{
Wallpapers.ForEach(x => x.Close());
Wallpapers.Clear();
WallpaperChanged?.Invoke(null, null);
SendMsgLivelySubProcess("lively:clear");
if (fireEvent)
{
WallpaperChanged?.Invoke(null, null);
}
}

public static void CloseAllWallpapers()
{
CloseAllWallpapers(true);
}

public static void CloseWallpaper(WallpaperType type)
Expand All @@ -652,24 +660,32 @@ public static void CloseWallpaper(WallpaperType type)
WallpaperChanged?.Invoke(null, null);
}

public static void CloseWallpaper(LivelyScreen display)
private static void CloseWallpaper(LivelyScreen display, bool fireEvent)
{
Wallpapers.ForEach(x =>
{
if (ScreenHelper.ScreenCompare(x.GetScreen(), display, DisplayIdentificationMode.screenLayout))
{
if(x.GetProcess() != null)
if (x.GetProcess() != null)
{
SendMsgLivelySubProcess("lively:rmv-pgm " + x.GetProcess().Id);
}
x.Close();
}
});
Wallpapers.RemoveAll(x => ScreenHelper.ScreenCompare(x.GetScreen(), display, DisplayIdentificationMode.screenLayout));
WallpaperChanged?.Invoke(null, null);
if(fireEvent)
{
WallpaperChanged?.Invoke(null, null);
}
}

public static void CloseWallpaper(LibraryModel wp)
public static void CloseWallpaper(LivelyScreen display)
{
CloseWallpaper(display, true);
}

public static void TerminateWallpaper(LibraryModel wp)
{
Wallpapers.ForEach(x =>
{
Expand All @@ -679,13 +695,29 @@ public static void CloseWallpaper(LibraryModel wp)
{
SendMsgLivelySubProcess("lively:rmv-pgm " + x.GetProcess().Id);
}
x.Close();
x.Terminate();
}
});
Wallpapers.RemoveAll(x => x.GetWallpaperData() == wp);
WallpaperChanged?.Invoke(null, null);
}

private static void TerminateAllWallpapers(bool fireEvent)
{
Wallpapers.ForEach(x => x.Terminate());
Wallpapers.Clear();
SendMsgLivelySubProcess("lively:clear");
if (fireEvent)
{
WallpaperChanged?.Invoke(null, null);
}
}

public static void TerminateAllWallpapers()
{
TerminateAllWallpapers(true);
}

/// <summary>
/// Note: If more than one instance of same wallpaper running, will send message to both.
/// </summary>
Expand All @@ -711,71 +743,7 @@ public static void SendMessageWallpaper(LivelyScreen display, string msg)
});
}

private static void CloseWallpaperWithoutEvent(LivelyScreen display)
{
Wallpapers.ForEach(x =>
{
if (ScreenHelper.ScreenCompare(x.GetScreen(), display, DisplayIdentificationMode.screenLayout))
{
if (x.GetProcess() != null)
{
SendMsgLivelySubProcess("lively:rmv-pgm " + x.GetProcess().Id);
}
x.Close();
}
});
Wallpapers.RemoveAll(x => ScreenHelper.ScreenCompare(x.GetScreen(), display, DisplayIdentificationMode.screenLayout));
}

private static void CloseAllWallpapersWithoutEvent()
{
Wallpapers.ForEach(x => x.Close());
Wallpapers.Clear();
SendMsgLivelySubProcess("lively:clear");
}

private async static void CloseaWallpaperAfterDelay(LivelyScreen display, int delay)
{
List<IWallpaper> tmp = new List<IWallpaper>();
Wallpapers.ForEach(x =>
{
if (ScreenHelper.ScreenCompare(x.GetScreen(), display, DisplayIdentificationMode.screenLayout))
{
if (x.GetProcess() != null)
{
SendMsgLivelySubProcess("lively:rmv-pgm " + x.GetProcess().Id);
}
tmp.Add(x);
}
});
Wallpapers.RemoveAll(x => ScreenHelper.ScreenCompare(x.GetScreen(), display, DisplayIdentificationMode.screenLayout));

await Task.Delay(delay);
tmp.ForEach (x =>
{
if (ScreenHelper.ScreenCompare(x.GetScreen(), display, DisplayIdentificationMode.screenLayout))
{
x.Close();
}
});
}

public static void TerminateAllWallpapers()
{
Wallpapers.ForEach(x => x.Terminate());
Wallpapers.Clear();
SendMsgLivelySubProcess("lively:clear");
WallpaperChanged?.Invoke(null, null);
}

private static void TerminateAllWallpapersWithoutEvent()
{
Wallpapers.ForEach(x => x.Terminate());
Wallpapers.Clear();
SendMsgLivelySubProcess("lively:clear");
}

#endregion //wallpaper close
#endregion //wallpaper operations

#region helper functons

Expand Down
Loading

0 comments on commit 3f7d83b

Please sign in to comment.