diff --git a/Core/FormBrowser.cs b/Core/FormBrowser.cs index b61f9351..8c1240b8 100644 --- a/Core/FormBrowser.cs +++ b/Core/FormBrowser.cs @@ -87,9 +87,7 @@ private void Browser_LoadingStateChanged(object sender, LoadingStateChangedEvent private void Browser_FrameLoadEnd(object sender, FrameLoadEndEventArgs e){ if (e.Frame.IsMain){ - string js = ScriptLoader.LoadResource("code.js"); - - if (js != null){ + foreach(string js in ScriptLoader.LoadResources("code.js","update.js").Where(js => js != null)){ browser.ExecuteScriptAsync(js); } } diff --git a/Resources/code.js b/Resources/code.js index cf37be53..1abbf860 100644 --- a/Resources/code.js +++ b/Resources/code.js @@ -14,11 +14,6 @@ // var prevFontSizeClass; - // - // Variable: Current timeout ID for update checking. - // - var updateCheckTimeoutID; - // // Function: Initializes TweetD*ck events. Called after the website app is loaded. // @@ -71,9 +66,6 @@ return true; }; - // Run update check - runUpdateCheck(); - // Finish init isInitialized = true; }; @@ -169,114 +161,6 @@ return tags.join(""); }; - // - // Function: Creates the update notification element. Removes the old one if already exists. - // - var createUpdateNotificationElement = function(version, download){ - var ele = $("#tweetdck-update"); - var existed = ele.length > 0; - - if (existed > 0){ - ele.remove(); - } - - var html = [ - "<div id='tweetdck-update'>", - "<p class='tdu-title'>"+$TD.brandName+" Update</p>", - "<p class='tdu-info'>Version "+version+" is now available.</p>", - "<div class='tdu-buttons'>", - "<button class='btn btn-positive tdu-btn-download'><span class='label'>Download</button>", - "<button class='btn btn-negative tdu-btn-dismiss'><span class='label'>Dismiss</button>", - "</div>", - "</div>" - ]; - - $("h1.app-title").after(html.join("")); - - ele = $("#tweetdck-update"); - - var buttonDiv = ele.children("div.tdu-buttons").first(); - - ele.css({ - color: "#fff", - backgroundColor: "rgb(32,94,138)", - position: "absolute", - left: "4px", - bottom: "4px", - width: "192px", - height: "86px", - display: existed ? "block" : "none", - borderRadius: "2px" - }); - - ele.children("p.tdu-title").first().css({ - fontSize: "17px", - fontWeight: "bold", - textAlign: "center", - letterSpacing: "0.2px", - margin: "4px auto 2px" - }); - - ele.children("p.tdu-info").first().css({ - fontSize: "12px", - textAlign: "center", - margin: "2px auto 6px" - }); - - buttonDiv.css({ - textAlign: "center" - }); - - buttonDiv.children().css({ - margin: "0 4px", - minHeight: "25px", - boxShadow: "1px 1px 1px rgba(17,17,17,0.5)" - }); - - buttonDiv.find("span").css({ - verticalAlign: "baseline" - }); - - ele.find("span.tdu-data-tag").first().css({ - cursor: "pointer", - textDecoration: "underline" - }); - - buttonDiv.children(".tdu-btn-download").click(function(){ - ele.remove(); - $TD.onUpdateAccepted(version,download); - }); - - buttonDiv.children(".tdu-btn-dismiss").click(function(){ - $TD.onUpdateDismissed(version); - ele.slideUp(function(){ ele.remove(); }); - }); - - if (!existed){ - ele.slideDown(); - } - - return ele; - }; - - // - // Function: Runs an update check and updates all DOM elements appropriately - // - var runUpdateCheck = function(){ - clearTimeout(updateCheckTimeoutID); - updateCheckTimeoutID = setTimeout(runUpdateCheck,1000*60*60); // 1 hour - - if (!$TD.updateCheckEnabled)return; - - $.getJSON("https://api.github.com/repos/chylex/"+$TD.brandName+"/releases/latest",function(response){ - var tagName = response.tag_name; - - if (tagName != $TD.versionTag && tagName != $TD.dismissedVersionTag && response.assets.length > 0){ - createUpdateNotificationElement(tagName,response.assets[0].browser_download_url); - } - }); - }; - // // Block: Observe the app <div> element and initialize TweetD*ck whenever possible. // @@ -365,9 +249,4 @@ e.preventDefault(); } }); - - // - // Block: Setup global functions. - // - window.TDGF_runUpdateCheck = runUpdateCheck; })($,$TD); diff --git a/Resources/update.js b/Resources/update.js new file mode 100644 index 00000000..5751f15c --- /dev/null +++ b/Resources/update.js @@ -0,0 +1,121 @@ +(function($,$TD){ + // + // Variable: Current timeout ID for update checking. + // + var updateCheckTimeoutID; + + // + // Function: Creates the update notification element. Removes the old one if already exists. + // + var createUpdateNotificationElement = function(version, download){ + var ele = $("#tweetdck-update"); + var existed = ele.length > 0; + + if (existed > 0){ + ele.remove(); + } + + var html = [ + "<div id='tweetdck-update'>", + "<p class='tdu-title'>"+$TD.brandName+" Update</p>", + "<p class='tdu-info'>Version "+version+" is now available.</p>", + "<div class='tdu-buttons'>", + "<button class='btn btn-positive tdu-btn-download'><span class='label'>Download</button>", + "<button class='btn btn-negative tdu-btn-dismiss'><span class='label'>Dismiss</button>", + "</div>", + "</div>" + ]; + + $(document.body).append(html.join("")); + + ele = $("#tweetdck-update"); + + var buttonDiv = ele.children("div.tdu-buttons").first(); + + ele.css({ + color: "#fff", + backgroundColor: "rgb(32,94,138)", + position: "absolute", + left: "4px", + bottom: "4px", + width: "192px", + height: "86px", + display: existed ? "block" : "none", + borderRadius: "2px", + zIndex: 9999 + }); + + ele.children("p.tdu-title").first().css({ + fontSize: "17px", + fontWeight: "bold", + textAlign: "center", + letterSpacing: "0.2px", + margin: "4px auto 2px" + }); + + ele.children("p.tdu-info").first().css({ + fontSize: "12px", + textAlign: "center", + margin: "2px auto 6px" + }); + + buttonDiv.css({ + textAlign: "center" + }); + + buttonDiv.children().css({ + margin: "0 4px", + minHeight: "25px", + boxShadow: "1px 1px 1px rgba(17,17,17,0.5)" + }); + + buttonDiv.find("span").css({ + verticalAlign: "baseline" + }); + + ele.find("span.tdu-data-tag").first().css({ + cursor: "pointer", + textDecoration: "underline" + }); + + buttonDiv.children(".tdu-btn-download").click(function(){ + ele.remove(); + $TD.onUpdateAccepted(version,download); + }); + + buttonDiv.children(".tdu-btn-dismiss").click(function(){ + $TD.onUpdateDismissed(version); + ele.slideUp(function(){ ele.remove(); }); + }); + + if (!existed){ + ele.slideDown(); + } + + return ele; + }; + + // + // Function: Runs an update check and updates all DOM elements appropriately + // + var runUpdateCheck = function(){ + clearTimeout(updateCheckTimeoutID); + updateCheckTimeoutID = setTimeout(runUpdateCheck,1000*60*60); // 1 hour + + if (!$TD.updateCheckEnabled)return; + + $.getJSON("https://api.github.com/repos/chylex/"+$TD.brandName+"/releases/latest",function(response){ + var tagName = response.tag_name; + + if (tagName != $TD.versionTag && tagName != $TD.dismissedVersionTag && response.assets.length > 0){ + createUpdateNotificationElement(tagName,response.assets[0].browser_download_url); + } + }); + }; + + // + // Block: Setup global functions. + // + window.TDGF_runUpdateCheck = runUpdateCheck; + runUpdateCheck(); +})($,$TD); diff --git a/TweetDck.csproj b/TweetDck.csproj index 9a4221b7..6b190091 100644 --- a/TweetDck.csproj +++ b/TweetDck.csproj @@ -212,6 +212,12 @@ <TargetPath>notification.js</TargetPath> </ContentWithTargetPath> </ItemGroup> + <ItemGroup> + <ContentWithTargetPath Include="Resources\update.js"> + <CopyToOutputDirectory>Always</CopyToOutputDirectory> + <TargetPath>update.js</TargetPath> + </ContentWithTargetPath> + </ItemGroup> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild"> <PropertyGroup>