forked from nemec/earthporn_desktop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
70 lines (55 loc) · 2.29 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
using System;
using System.Runtime.InteropServices;
using EpApp.Classes;
namespace EpApp
{
public class Program
{
public static void Main(string[] args)
{
Console.WriteLine("App Started");
Console.WriteLine("Talking to Reddit...");
Reddit reddit = new Reddit();
RedditReponse response = reddit.GetPostsAsync().Result;
string topImage = response.data.children[0].data.url;
Console.WriteLine("Reddit data retrieved: " + topImage);
Console.WriteLine("Downloading file...");
IFileSaver saver = new FileDownloader();
string path = saver.Save(topImage);
Console.WriteLine("File downloaded to: " + path);
Console.WriteLine("Setting desktop wallpaper...");
IWallpaperSetter setter = CreateWallpaperSetter();
if(setter == null)
{
Console.Error.WriteLine("Platform not detected.");
return;
}
setter.SetWallpaper(path);
Console.WriteLine("Done!");
}
private static IWallpaperSetter CreateWallpaperSetter()
{
IWallpaperSetter setter = null;
//If Windows
if (System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
setter = new WindowsWallpaperImageSetter();
//If OSX
if (System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
setter = new MacOSWallpaperImageSetter();
//If Linux
if (System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
var desktopEnvironment = Environment.GetEnvironmentVariable("DESKTOP_SESSION") ??
Environment.GetEnvironmentVariable("XDG_CURRENT_DESKTOP") ??
Environment.GetEnvironmentVariable("XDG_SESSION_DESKTOP");
switch(desktopEnvironment.ToLower())
{
case "gnome":
setter = new LinuxGnomeWallpaperImageSetter();
break;
}
}
return setter;
}
}
}