Skip to content
This repository has been archived by the owner on Jul 10, 2024. It is now read-only.

Commit

Permalink
improve autodownload
Browse files Browse the repository at this point in the history
  • Loading branch information
HendrikMennen committed Jul 2, 2024
1 parent bf428f5 commit c602ace
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ public abstract class LanguageServiceLsp(string name, string? workspace) : Langu

public override async Task ActivateAsync()
{
//return;
if (IsActivated) return;
IsActivated = true;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,18 @@ protected LanguageServiceLspAutoDownload(IObservable<string> executablePath, Pac
executablePath.Subscribe(x =>
{
ExecutablePath = x;
if(File.Exists(ExecutablePath))
{
_ = ActivateAsync();
}
});
}

public override async Task ActivateAsync()
{
if (_packageService.GetPackageModel(_package) is {Status: PackageStatus.Available or PackageStatus.UpdateAvailable or PackageStatus.Installing})
if (!File.Exists(ExecutablePath) && _enableAutoDownload)
{
if (!_enableAutoDownload) return;
if(!await _packageService.InstallAsync(_package)) return;
await Task.Delay(100);
await _packageService.InstallAsync(_package);
}
await base.ActivateAsync();
}
Expand Down
17 changes: 15 additions & 2 deletions src/OneWare.Essentials/Models/PackageModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ public float Progress

protected string PackageType { get; }

public event EventHandler<Task<bool>>? Installing;

public event EventHandler? Installed;

public event EventHandler? Removed;
Expand Down Expand Up @@ -93,7 +95,16 @@ public async Task<bool> UpdateAsync(PackageVersion version)
return target;
}

public async Task<bool> DownloadAsync(PackageVersion version)
public Task<bool> DownloadAsync(PackageVersion version)
{
var task = PerformDownloadAsync(version);

Installing?.Invoke(this, task);

return task;
}

private async Task<bool> PerformDownloadAsync(PackageVersion version)
{
try
{
Expand Down Expand Up @@ -130,6 +141,8 @@ public async Task<bool> DownloadAsync(PackageVersion version)
InstalledVersion = version;

Installed?.Invoke(this, EventArgs.Empty);

await Task.Delay(100);
}
else
{
Expand All @@ -144,7 +157,7 @@ public async Task<bool> DownloadAsync(PackageVersion version)
}
return true;
}

/// <summary>
/// Gets called after downloading and extracting
/// Make sure to set Status after completing
Expand Down

0 comments on commit c602ace

Please sign in to comment.