-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Introduce support for browser extensions * Setup ublock origin * Release 0.9.9.7 branch * Automatically backup settings Closes #539 * Compare settings with remote
- Loading branch information
1 parent
c534561
commit 5765c27
Showing
16 changed files
with
419 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
Daybreak/Services/BrowserExtensions/BrowserExtensionsManager.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
using Microsoft.Web.WebView2.Core; | ||
using Slim; | ||
using System.Core.Extensions; | ||
using System.Extensions; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace Daybreak.Services.BrowserExtensions; | ||
|
||
public sealed class BrowserExtensionsManager : IBrowserExtensionsManager, IBrowserExtensionsProducer | ||
{ | ||
private readonly IServiceManager serviceManager; | ||
|
||
public BrowserExtensionsManager( | ||
IServiceManager serviceManager) | ||
{ | ||
this.serviceManager = serviceManager.ThrowIfNull(); | ||
} | ||
|
||
public void RegisterExtension<T>() | ||
where T : class, IBrowserExtension | ||
{ | ||
this.serviceManager.RegisterScoped<T, T>(); | ||
} | ||
|
||
public async Task InitializeBrowserEnvironment(CoreWebView2Profile coreWebView2Profile, string browserVersion) | ||
{ | ||
var existingExtensions = await coreWebView2Profile.GetBrowserExtensionsAsync(); | ||
foreach (var extension in this.serviceManager.GetServicesOfType<IBrowserExtension>() | ||
.Where(e => existingExtensions.None(ee => ee.Id == e.ExtensionId))) | ||
{ | ||
await extension.CheckAndUpdate(browserVersion); | ||
var extensionPath = await extension.GetExtensionPath(); | ||
if (!Directory.Exists(extensionPath)) | ||
{ | ||
continue; | ||
} | ||
|
||
if (!File.Exists(Path.Combine(extensionPath, "manifest.json"))) | ||
{ | ||
continue; | ||
} | ||
|
||
await coreWebView2Profile.AddBrowserExtensionAsync(extensionPath); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using System.Threading.Tasks; | ||
|
||
namespace Daybreak.Services.BrowserExtensions; | ||
|
||
public interface IBrowserExtension | ||
{ | ||
string ExtensionId { get; } | ||
Task CheckAndUpdate(string browserVersion); | ||
Task<string> GetExtensionPath(); | ||
} |
9 changes: 9 additions & 0 deletions
9
Daybreak/Services/BrowserExtensions/IBrowserExtensionsManager.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using Microsoft.Web.WebView2.Core; | ||
using System.Threading.Tasks; | ||
|
||
namespace Daybreak.Services.BrowserExtensions; | ||
|
||
public interface IBrowserExtensionsManager | ||
{ | ||
Task InitializeBrowserEnvironment(CoreWebView2Profile coreWebView2Profile, string browserVersion); | ||
} |
6 changes: 6 additions & 0 deletions
6
Daybreak/Services/BrowserExtensions/IBrowserExtensionsProducer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace Daybreak.Services.BrowserExtensions; | ||
public interface IBrowserExtensionsProducer | ||
{ | ||
void RegisterExtension<T>() | ||
where T : class, IBrowserExtension; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.