Skip to content

Commit

Permalink
fixy fixy
Browse files Browse the repository at this point in the history
  • Loading branch information
noblereign authored and foxt committed Nov 25, 2020
1 parent bd0b2be commit 024d671
Showing 1 changed file with 133 additions and 106 deletions.
239 changes: 133 additions & 106 deletions SMTCRP/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public static void HideConsoleWindow()
public static ContextMenuStrip context = new ContextMenuStrip();
public static GlobalSystemMediaTransportControlsSessionManager gsmtcsm = GlobalSystemMediaTransportControlsSessionManager.RequestAsync().GetAwaiter().GetResult();
public static bool isDisplaying = false;
public static bool settingsUpdated = false;
public static string lastData = "";
public static System.Timers.Timer updTimer = new System.Timers.Timer(1000);
public static System.Timers.Timer deferTimer = new System.Timers.Timer(14000);
Expand Down Expand Up @@ -145,6 +146,7 @@ static void Main(string[] args)
{
Console.WriteLine("Settings updated, Presence will update as soon as it's allowed");
isDisplaying = false;
settingsUpdated = true;
};

context.Items.Add(showalbumtitle);
Expand Down Expand Up @@ -260,6 +262,8 @@ public static void update(object sender, ElapsedEventArgs arg)
}
}

//var browser_blocked = false;

if (session == null)
{
trayIcon.Icon = trey;
Expand All @@ -269,6 +273,7 @@ public static void update(object sender, ElapsedEventArgs arg)
isDisplaying = false;
client.ClearPresence();
Console.WriteLine("No media app open, Defering update cycle for 14 seconds...");
settingsUpdated = false;
updTimer.Stop();
deferTimer.Start();

Expand All @@ -287,142 +292,164 @@ public static void update(object sender, ElapsedEventArgs arg)
session.SourceAppUserModelId.ToLower().StartsWith("msedge") ||
session.SourceAppUserModelId.ToLower().StartsWith("spotify"))
{
Console.WriteLine("browser_blocker {0}", session.SourceAppUserModelId);
//Console.WriteLine("browser_blocker {0}", session.SourceAppUserModelId);
if (session == null || i >= ses.Count)
{
session = null;
break;
}
session = ses[i];
//browser_blocked = true;
i += 1;
}
}
}

var mediaProperties = session.TryGetMediaPropertiesAsync().GetAwaiter().GetResult();
string appName = session.SourceAppUserModelId.Replace(".exe", "");
string appLogo = "generic";
if (icons.Contains(appName.ToLower()))
{
appLogo = appName.ToLower();
}
if (appName.ToLower().StartsWith("winamp") || appName.ToLower().StartsWith("wacup"))
{
appLogo = "winamp";
appName = "Winamp";
}
if (appName.EndsWith("ZuneMusic"))
{
appLogo = "zunemusic";
appName = "Groove Music";
}
if (appLogo == "generic")
{
Console.WriteLine("Using generic app icon! Contact theLMGN#4444 to get an app icon for {0}", appName);
}
if (appName.Contains("!")) // attempt to clean UWP app names
{
appName = appName.Split(".").Last();
}
var data = mediaProperties.Title + " by " + mediaProperties.Artist + " via " + appName;
if (blockapp.GetCurrentParent().InvokeRequired)
if (session != null)
{
blockapp.GetCurrentParent().Invoke(new Action(() =>
var mediaProperties = session.TryGetMediaPropertiesAsync().GetAwaiter().GetResult();
string appName = session.SourceAppUserModelId.Replace(".exe", "");
string appLogo = "generic";
if (icons.Contains(appName.ToLower()))
{
appLogo = appName.ToLower();
}
if (appName.ToLower().StartsWith("winamp") || appName.ToLower().StartsWith("wacup"))
{
appLogo = "winamp";
appName = "Winamp";
}
if (appName.EndsWith("ZuneMusic"))
{
appLogo = "zunemusic";
appName = "Groove Music";
}
if (appName.Contains("!")) // attempt to clean UWP app names
{
appName = appName.Split(".").Last();
}
var data = mediaProperties.Title + " by " + mediaProperties.Artist + " via " + appName;
if (blockapp.GetCurrentParent().InvokeRequired)
{
blockapp.GetCurrentParent().Invoke(new Action(() =>
{
blockapp.Text = "Block " + appName;
}));
}
else
{
blockapp.Text = "Block " + appName;
}));
}
else
{
blockapp.Text = "Block " + appName;
}

var pbi = session.GetPlaybackInfo();
if (pbi.PlaybackStatus != GlobalSystemMediaTransportControlsSessionPlaybackStatus.Playing && !isDisplaying)
{
return;
}
if (pbi.PlaybackStatus != GlobalSystemMediaTransportControlsSessionPlaybackStatus.Playing)
{
trayIcon.Icon = trey;
trayIcon.Text = "SMTCRP - Nothing playing";
client.ClearPresence();
isDisplaying = false;
Console.WriteLine("Playback is {0}, Defering update cycle for 14 seconds...", pbi.PlaybackStatus);
updTimer.Stop();
deferTimer.Start();
return;
}
var tlp = session.GetTimelineProperties();

if (data == lastData && isDisplaying) { return; }
Console.WriteLine(data);
}

var count = mediaProperties.AlbumTrackCount;
var num = mediaProperties.TrackNumber;
var pbi = session.GetPlaybackInfo();
if (pbi.PlaybackStatus != GlobalSystemMediaTransportControlsSessionPlaybackStatus.Playing && !isDisplaying)
{
return;
}
if (pbi.PlaybackStatus != GlobalSystemMediaTransportControlsSessionPlaybackStatus.Playing)
{
trayIcon.Icon = trey;
trayIcon.Text = "SMTCRP - Nothing playing";
client.ClearPresence();
isDisplaying = false;
Console.WriteLine("Playback is {0}, Defering update cycle for 14 seconds...", pbi.PlaybackStatus);
settingsUpdated = false;
updTimer.Stop();
deferTimer.Start();
return;
}
var tlp = session.GetTimelineProperties();

if (count < num)
{
count = num;
}
if (data == lastData && isDisplaying) { return; }
Console.WriteLine(data);

if (Properties.Settings.Default.blockedApps.Contains(session.SourceAppUserModelId.ToLower()))
{
Console.WriteLine("user_blocker {0}", session.SourceAppUserModelId);
trayIcon.Icon = troy;
trayIcon.Text = "SMTCRP - " + appName + " is blocked";
client.ClearPresence();
isDisplaying = false;
Console.WriteLine("Playback is {0}, Defering update cycle for 14 seconds...", pbi.PlaybackStatus);
updTimer.Stop();
deferTimer.Start();
}
else
{
var generated_party = new Party()
{
ID = Guid.NewGuid().ToString(),
Size = num,
Max = count
};
var count = mediaProperties.AlbumTrackCount;
var num = mediaProperties.TrackNumber;

if (!Properties.Settings.Default.useTrackNumbers)
if (count < num)
{
generated_party = null;
count = num;
}

var generated_details = "🎵 " + mediaProperties.Title;
if (Properties.Settings.Default.useAlbumTitle)
if (Properties.Settings.Default.blockedApps.Contains(session.SourceAppUserModelId.ToLower()))
{
generated_details = "🎵 " + mediaProperties.AlbumTitle + " - " + mediaProperties.Title;
//Console.WriteLine("user_blocker {0}", session.SourceAppUserModelId);
trayIcon.Icon = troy;
trayIcon.Text = "SMTCRP - " + appName + " is blocked";
client.ClearPresence();
isDisplaying = false;
//Console.WriteLine("Playback is {0}, Defering update cycle for 14 seconds...", pbi.PlaybackStatus);
//updTimer.Stop();
//deferTimer.Start();
}

client.SetPresence(new RichPresence()
else
{
Details = generated_details,
State = "👥 " + mediaProperties.Artist,
Party = generated_party,
Assets = new Assets()
var generated_party = new Party()
{
LargeImageKey = appLogo,
LargeImageText = "via " + appName,
SmallImageKey = "logo",
SmallImageText = "https://github.com/thelmgn/smtcrp"
},
});
isDisplaying = true;
lastData = data;
trayIcon.Icon = tray;
if (data.Length > 54)
{
trayIcon.Text = "SMTCRP - " + data.Substring(0, 53) + "…";
ID = Guid.NewGuid().ToString(),
Size = num,
Max = count
};

if (!Properties.Settings.Default.useTrackNumbers)
{
generated_party = null;
}

var generated_details = "🎵 " + mediaProperties.Title;
if (Properties.Settings.Default.useAlbumTitle)
{
generated_details = "🎵 " + mediaProperties.AlbumTitle + " - " + mediaProperties.Title;
}

if (appLogo == "generic")
{
Console.WriteLine("Using generic app icon! Contact theLMGN#4444 to get an app icon for {0}", appName);
}

client.SetPresence(new RichPresence()
{
Details = generated_details,
State = "👥 " + mediaProperties.Artist,
Party = generated_party,
Assets = new Assets()
{
LargeImageKey = appLogo,
LargeImageText = "via " + appName,
SmallImageKey = "logo",
SmallImageText = "https://github.com/thelmgn/smtcrp"
},
});
isDisplaying = true;
lastData = data;
trayIcon.Icon = tray;
if (data.Length > 54)
{
trayIcon.Text = "SMTCRP - " + data.Substring(0, 53) + "…";
}
else
{
trayIcon.Text = "SMTCRP - " + data;
}
}
else
}
else
{
trayIcon.Icon = trey;
trayIcon.Text = "SMTCRP - Ignoring a browser";
if (isDisplaying || settingsUpdated)
{
trayIcon.Text = "SMTCRP - " + data;
isDisplaying = false;
client.ClearPresence();
Console.WriteLine("Browser ignored, Defering update cycle for 14 seconds...");
settingsUpdated = false;
updTimer.Stop();
deferTimer.Start();
}
return;
}
Console.WriteLine("Defering update cycle for 14 seconds...");
settingsUpdated = false;
updTimer.Stop();
deferTimer.Start();
}
Expand Down

0 comments on commit 024d671

Please sign in to comment.