diff --git a/Core/Other/Settings/TabSettingsGeneral.cs b/Core/Other/Settings/TabSettingsGeneral.cs index 2201751d..eb21d58c 100644 --- a/Core/Other/Settings/TabSettingsGeneral.cs +++ b/Core/Other/Settings/TabSettingsGeneral.cs @@ -163,6 +163,11 @@ private void btnCheckUpdates_Click(object sender, EventArgs e){ btnCheckUpdates.Enabled = false; updateCheckEventId = updates.Check(true); + + if (updateCheckEventId == UpdateHandler.CheckCodeNotOnTweetDeck){ + FormMessage.Error("Update Check", "Updates can only be checked once TweetDeck is fully loaded.", FormMessage.OK); + btnCheckUpdates.Enabled = true; + } } private void updates_CheckFinished(object sender, UpdateEventArgs e){ diff --git a/Resources/Scripts/update.js b/Resources/Scripts/update.js index 3a96187b..6d3ffa98 100644 --- a/Resources/Scripts/update.js +++ b/Resources/Scripts/update.js @@ -300,6 +300,13 @@ }); }; + // + // Block: Check updates on startup. + // + $(document).one("TD.ready", function(){ + $TDU.triggerUpdateCheck(); + }); + // // Block: Setup global functions. // diff --git a/Updates/UpdateHandler.cs b/Updates/UpdateHandler.cs index 604cc60f..de677c12 100644 --- a/Updates/UpdateHandler.cs +++ b/Updates/UpdateHandler.cs @@ -8,6 +8,9 @@ namespace TweetDuck.Updates{ sealed class UpdateHandler{ + public const int CheckCodeUpdatesDisabled = -1; + public const int CheckCodeNotOnTweetDeck = -2; + private readonly ITweetDeckBrowser browser; private readonly UpdaterSettings settings; @@ -15,7 +18,7 @@ sealed class UpdateHandler{ public event EventHandler<UpdateEventArgs> UpdateDismissed; public event EventHandler<UpdateEventArgs> CheckFinished; - private int lastEventId; + private ushort lastEventId; private UpdateInfo lastUpdateInfo; public UpdateHandler(ITweetDeckBrowser browser, UpdaterSettings settings){ @@ -28,7 +31,6 @@ public UpdateHandler(ITweetDeckBrowser browser, UpdaterSettings settings){ private void OnFrameLoaded(IFrame frame){ ScriptLoader.ExecuteFile(frame, "update.js"); - Check(false); } public int Check(bool force){ @@ -36,12 +38,16 @@ public int Check(bool force){ if (force){ settings.DismissedUpdate = null; } + + if (!browser.IsTweetDeckWebsite){ + return CheckCodeNotOnTweetDeck; + } - browser.ExecuteFunction("TDUF_runUpdateCheck", ++lastEventId, Program.VersionTag, settings.DismissedUpdate ?? string.Empty, settings.AllowPreReleases); + browser.ExecuteFunction("TDUF_runUpdateCheck", (int)unchecked(++lastEventId), Program.VersionTag, settings.DismissedUpdate ?? string.Empty, settings.AllowPreReleases); return lastEventId; } - return 0; + return CheckCodeUpdatesDisabled; } public void BeginUpdateDownload(Form ownerForm, UpdateInfo updateInfo, Action<UpdateInfo> onSuccess){