Skip to content

Commit

Permalink
Merge pull request #10 from gandarez/master
Browse files Browse the repository at this point in the history
Initialize WakaTime async
  • Loading branch information
alanhamlett committed Aug 28, 2015
2 parents 620c917 + 0b1c0a2 commit 085ccb3
Showing 1 changed file with 28 additions and 24 deletions.
52 changes: 28 additions & 24 deletions WakaTime/WakaTime.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
using System;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using WakaTime.Forms;
Expand Down Expand Up @@ -33,9 +31,10 @@ class WakaTime
private static readonly object ThreadLock = new object();
#endregion

#region StartUp/CleanUp
#region StartUp/CleanUp

internal static void CommandMenuInit()
{
{
_version = string.Format("{0}.{1}.{2}", CoreAssembly.Version.Major, CoreAssembly.Version.Minor, CoreAssembly.Version.Build);

try
Expand All @@ -51,23 +50,7 @@ internal static void CommandMenuInit()
_iniFilePath = sbIniFilePath.ToString();
if (!Directory.Exists(_iniFilePath)) Directory.CreateDirectory(_iniFilePath);

// Make sure python is installed
if (!PythonManager.IsPythonInstalled())
{
var url = PythonManager.PythonDownloadUrl;
Downloader.DownloadPython(url, WakaTimeConstants.UserConfigDir);
}

if (!DoesCliExist() || !IsCliLatestVersion())
{
try
{
Directory.Delete(string.Format("{0}\\wakatime-master", WakaTimeConstants.UserConfigDir), true);
}
catch { /* ignored */ }

Downloader.DownloadCli(WakaTimeConstants.CliUrl, WakaTimeConstants.UserConfigDir);
}
Task.Run(() => { InitializeWakaTimeAsync(); });

GetSettings();

Expand All @@ -85,6 +68,27 @@ internal static void CommandMenuInit()
Logger.Error("Error initializing Wakatime", ex);
}
}

private static void InitializeWakaTimeAsync()
{
// Make sure python is installed
if (!PythonManager.IsPythonInstalled())
{
var url = PythonManager.PythonDownloadUrl;
Downloader.DownloadPython(url, WakaTimeConstants.UserConfigDir);
}

if (DoesCliExist() && IsCliLatestVersion()) return;

try
{
Directory.Delete(string.Format("{0}\\wakatime-master", WakaTimeConstants.UserConfigDir), true);
}
catch { /* ignored */ }

Downloader.DownloadCli(WakaTimeConstants.CliUrl, WakaTimeConstants.UserConfigDir);
}

internal static void SetToolBarIcon()
{
var tbIcons = new toolbarIcons { hToolbarBmp = TbBmp.GetHbitmap() };
Expand Down Expand Up @@ -139,7 +143,7 @@ public static void HandleActivity(bool isWrite)
var currentFile = GetCurrentFile();
if (currentFile == null) return;

Task.Factory.StartNew(() =>
Task.Run(() =>
{
lock (ThreadLock)
{
Expand All @@ -156,7 +160,7 @@ public static void HandleActivity(bool isWrite)
public static bool EnoughTimePassed()
{
return _lastHeartbeat < DateTime.UtcNow.AddMinutes(-1);
}
}

public static void SendHeartbeat(string fileName, bool isWrite)
{
Expand All @@ -181,7 +185,7 @@ public static void SendHeartbeat(string fileName, bool isWrite)
}
else
Logger.Error("Could not send heartbeat because python is not installed");
}
}

private static bool DoesCliExist()
{
Expand Down

0 comments on commit 085ccb3

Please sign in to comment.