Skip to content

Commit

Permalink
Initializing automatically in the background
Browse files Browse the repository at this point in the history
  • Loading branch information
madskristensen committed Oct 11, 2015
1 parent 232ecc5 commit a1b48a1
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 32 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
- [ ] Generate gulpfile.js from compilerconfig.json (#34)
- [ ] Preview window (#6)
- [ ] File globbing pattern support (#49)
- [ ] Show yellow InfoBar when initializing
- [x] MSBuild: Changed build ordering (#124)
- [x] Compile only when files have changed (#121)
- [x] Fixed loss of compile on save (#125)
- [x] LESS: Support for _less-plugin-csscomb_ (#126)
- [ ] Show yellow InfoBar when initializing
- [x] Initializing automatically in the background

Features that have a checkmark are complete and available for
download in the
Expand Down
62 changes: 31 additions & 31 deletions src/WebCompiler/Compile/CompilerService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,7 @@ internal static ICompiler GetCompiler(Config config)
string ext = Path.GetExtension(config.InputFile).ToUpperInvariant();
ICompiler compiler = null;

lock (_syncRoot)
{
Initialize();
}

switch (ext)
{
Expand Down Expand Up @@ -72,36 +69,39 @@ public static void Initialize()
var node_exe = Path.Combine(_path, "node.exe");
var log_file = Path.Combine(_path, "log.txt");

if (!Directory.Exists(node_modules) || !File.Exists(node_exe) || !File.Exists(log_file) || (Directory.Exists(node_modules) && Directory.GetDirectories(node_modules).Length < 300))
lock (_syncRoot)
{
OnInitializing();

if (Directory.Exists(_path))
Directory.Delete(_path, true);

Directory.CreateDirectory(_path);
SaveResourceFile(_path, "WebCompiler.Node.node.7z", "node.7z");
SaveResourceFile(_path, "WebCompiler.Node.node_modules.7z", "node_modules.7z");
SaveResourceFile(_path, "WebCompiler.Node.7z.exe", "7z.exe");
SaveResourceFile(_path, "WebCompiler.Node.7z.dll", "7z.dll");
SaveResourceFile(_path, "WebCompiler.Node.prepare.cmd", "prepare.cmd");

ProcessStartInfo start = new ProcessStartInfo
if (!Directory.Exists(node_modules) || !File.Exists(node_exe) || !File.Exists(log_file) || (Directory.Exists(node_modules) && Directory.GetDirectories(node_modules).Length < 300))
{
WorkingDirectory = _path,
CreateNoWindow = true,
WindowStyle = ProcessWindowStyle.Hidden,
FileName = "cmd.exe",
Arguments = "/c prepare.cmd"
};

Process p = Process.Start(start);
p.WaitForExit();

// If this file is written, then the initialization was successfull.
File.WriteAllText(log_file, DateTime.Now.ToLongDateString());

OnInitialized();
OnInitializing();

if (Directory.Exists(_path))
Directory.Delete(_path, true);

Directory.CreateDirectory(_path);
SaveResourceFile(_path, "WebCompiler.Node.node.7z", "node.7z");
SaveResourceFile(_path, "WebCompiler.Node.node_modules.7z", "node_modules.7z");
SaveResourceFile(_path, "WebCompiler.Node.7z.exe", "7z.exe");
SaveResourceFile(_path, "WebCompiler.Node.7z.dll", "7z.dll");
SaveResourceFile(_path, "WebCompiler.Node.prepare.cmd", "prepare.cmd");

ProcessStartInfo start = new ProcessStartInfo
{
WorkingDirectory = _path,
CreateNoWindow = true,
WindowStyle = ProcessWindowStyle.Hidden,
FileName = "cmd.exe",
Arguments = "/c prepare.cmd"
};

Process p = Process.Start(start);
p.WaitForExit();

// If this file is written, then the initialization was successful.
File.WriteAllText(log_file, DateTime.Now.ToLongDateString());

OnInitialized();
}
}
}

Expand Down
25 changes: 25 additions & 0 deletions src/WebCompilerVsix/WebCompilerPackage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,29 @@ public static bool IsDocumentDirty(string documentPath, out IVsPersistDocData pe
return false;
}
}

[ProvideAutoLoad(UIContextGuids80.SolutionExists)]
[ProvideAutoLoad(UIContextGuids80.NoSolution)]
public sealed class WebCompilerInitPackage : Package
{
protected override void Initialize()
{
// Delay execution until VS is idle.
Dispatcher.CurrentDispatcher.BeginInvoke(new Action(() =>
{
// Then execute in a background thread.
System.Threading.ThreadPool.QueueUserWorkItem((o) =>
{
try
{
WebCompiler.CompilerService.Initialize();
}
catch (Exception ex)
{
Logger.Log(ex);
}
});
}), DispatcherPriority.ApplicationIdle, null);
}
}
}

0 comments on commit a1b48a1

Please sign in to comment.