Skip to content

Commit

Permalink
Merge pull request #110 from ChrisFeline/dev
Browse files Browse the repository at this point in the history
Fix 'Auto Copy on Join'
  • Loading branch information
ChrisFeline authored Dec 30, 2024
2 parents 240a961 + 8818313 commit 52a237a
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 52 deletions.
6 changes: 2 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# Latest Changelog

- Fixed terror names on Webhook embed not showing the correct variant name.
- Fixed new line handling on custom Chatbox messages with JS tags.
- Fixed Auto Copy on Open copying while this feature was disabled.
- Removed YoBro, for real this time.
- Fixed 'Auto Copy on Join' feature not working properly.
- Removed YoBro, he's part of a tree now.
20 changes: 20 additions & 0 deletions Models/SaveData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,26 @@ public void SetParsedPos(string name, long pos, bool save)
if (save) SetDirty();
}

public Entry? FindRecentEntry() {
if (Collection.Count == 0) return null;

History? latest = null;
foreach (History h in Collection) {
if (!h.IsCustom && (latest == null || h.UniversalTime > latest.UniversalTime))
latest = h;
}

if (latest == null || latest.Database.Count == 0) return null;

Entry? recent = null;
foreach (Entry e in latest.Database) {
if (recent == null || e.Timestamp > recent.Timestamp)
recent = e;
}

return recent;
}

public static void OpenDataLocation()
{
MainWindow.OpenExternalLink(Path.GetDirectoryName(Destination) ?? string.Empty);
Expand Down
66 changes: 33 additions & 33 deletions Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,52 +49,52 @@ internal static bool ContainsArg(string arg) {
[STAThread]
static void Main(string[] args)
{
Logger.Log("Initializing logging.");

try {
Logger.Log("Initializing logging.");

Directory.SetCurrentDirectory(ProgramDirectory);
Logger.Log("Program Directory: " + ProgramDirectory);
} catch (Exception e) {
Logger.Error("Failed to set Program Directory to: " + ProgramDirectory);
Logger.Error(e.ToString());
}

Arguments = args;
CultureInfo.DefaultThreadCurrentCulture = CultureInfo.InvariantCulture;
CultureInfo.DefaultThreadCurrentUICulture = CultureInfo.InvariantCulture;
Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
Thread.CurrentThread.CurrentUICulture = CultureInfo.InvariantCulture;
Arguments = args;
CultureInfo.DefaultThreadCurrentCulture = CultureInfo.InvariantCulture;
CultureInfo.DefaultThreadCurrentUICulture = CultureInfo.InvariantCulture;
Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
Thread.CurrentThread.CurrentUICulture = CultureInfo.InvariantCulture;

if (CheckMutex()) {
// Don't run program if it's already running, instead we focus the already existing window
NativeMethods.PostMessage((IntPtr)NativeMethods.HWND_BROADCAST, NativeMethods.WM_FOCUSINST, IntPtr.Zero, IntPtr.Zero);
return;
}
if (CheckMutex()) {
// Don't run program if it's already running, instead we focus the already existing window
NativeMethods.PostMessage((IntPtr)NativeMethods.HWND_BROADCAST, NativeMethods.WM_FOCUSINST, IntPtr.Zero, IntPtr.Zero);
return;
}

if (!Directory.Exists(DataLocation)) Directory.CreateDirectory(DataLocation);
if (!Directory.Exists(DataLocation)) Directory.CreateDirectory(DataLocation);

LANG.Initialize();
Updater.CheckPostUpdate(args);
LANG.Initialize();
Updater.CheckPostUpdate(args);

Logger.Log("Initializing application rendering.");
ApplicationConfiguration.Initialize();
Application.SetCompatibleTextRenderingDefault(true);
Logger.Log("Initializing application rendering.");
ApplicationConfiguration.Initialize();
Application.SetCompatibleTextRenderingDefault(true);

Logger.Log("Initializing font.");
InitializeFont();
Logger.Log("Initializing font.");
InitializeFont();

MainWindow.Started = false;
MainWindow.Started = false;

if (!StartCheckForUpdate()) {
Application.ApplicationExit += OnApplicationExit;
if (!StartCheckForUpdate()) {
Application.ApplicationExit += OnApplicationExit;

Logger.Log("Running 'MainWindow'");
Application.Run(new MainWindow());
}
Logger.Log("Running 'MainWindow'");
Application.Run(new MainWindow());
}

// Check when all forms close
Logger.Log("All windows are closed...");
GitHubUpdate.Start();
// Check when all forms close
Logger.Log("All windows are closed...");
GitHubUpdate.Start();
} catch (Exception e) {
// What the heck happened?
File.WriteAllText(Path.Combine(DataLocation, "output.error"), e.ToString());
}
}

private static void OnApplicationExit(object? sender, EventArgs e) {
Expand Down
6 changes: 2 additions & 4 deletions Utils/LogParser/ToNLogContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,8 @@ public override void Enter(string instanceID, bool isHomeWorld) {
WebSocketAPI.SendValue("INSTANCE", instanceID);
DSRichPresence.SetInstanceID(instanceID, isHomeWorld);

if (isHomeWorld && Settings.Get.AutoCopy && Settings.Get.CopyOnJoin && MainWindow.Started) {
MainWindow.Instance?.CopyRecent(true);
NotificationManager.PlayCopy();
}
if (isHomeWorld && Settings.Get.AutoCopy && Settings.Get.CopyOnJoin && MainWindow.Started)
MainWindow.CopyRecentData();
}
}

Expand Down
22 changes: 11 additions & 11 deletions Windows/MainWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ private void mainWindow_Shown(object sender, EventArgs e) {
Started = true;
SetTitle(null);

if (Settings.Get.CopyOnOpen)
CopyRecent(true);
if (Settings.Get.AutoCopy && Settings.Get.CopyOnOpen)
CopyRecentData();

LilOSC.Initialize();
WebSocketAPI.Initialize();
Expand Down Expand Up @@ -643,7 +643,7 @@ private void LogWatcher_OnLine(object? sender, OnLineArgs e) {
}

private void LogWatcher_OnTick(object? sender, EventArgs e) {
if ((Settings.Get.CopyOnSave && Started))
if (Settings.Get.CopyOnSave && Started)
CopyRecent(false);

Export();
Expand Down Expand Up @@ -955,14 +955,6 @@ private void FirstImport() {

if (temp == null || temp.UniversalTime < h.UniversalTime) temp = h;
}

if (Settings.Get.AutoCopy && Settings.Get.CopyOnOpen) {
Entry? first = temp?.Database.FirstOrDefault();
if (first != null) {
SetRecent(first);
NotificationManager.PlayCopy();
}
}
}

private void AddCustomEntry(Entry entry, History? collection) {
Expand Down Expand Up @@ -1060,6 +1052,14 @@ internal void CopyRecent(bool force) {
RecentData.Fresh = false;
}

internal static void CopyRecentData() {
Entry? entry = SaveData.FindRecentEntry();

if (entry != null) {
entry.CopyToClipboard();
NotificationManager.PlayCopy();
}
}
#endregion

}
Expand Down

0 comments on commit 52a237a

Please sign in to comment.