-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moving config setup and fixing build
- Loading branch information
Showing
23 changed files
with
259 additions
and
138 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
31 changes: 27 additions & 4 deletions
31
src/Shiny.Mediator.Blazor/Infrastructure/InternetService.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 |
---|---|---|
@@ -1,12 +1,35 @@ | ||
using Microsoft.JSInterop; | ||
using Shiny.Mediator.Infrastructure; | ||
|
||
namespace Shiny.Mediator.Blazor.Infrastructure; | ||
|
||
public class InternetService : IInternetService | ||
|
||
public class InternetService(IJSRuntime jsruntime) : IInternetService, IDisposable | ||
{ | ||
public bool IsAvailable { get; } | ||
public Task WaitForAvailable(CancellationToken cancelToken = default) | ||
public bool IsAvailable => ((IJSInProcessRuntime)jsruntime).Invoke<bool>("navigator.onLine"); | ||
|
||
|
||
[JSInvokable("InternetService.OnStatusChanged")] | ||
public void OnStatusChanged(bool isOnline) | ||
{ | ||
throw new NotImplementedException(); | ||
if (isOnline) | ||
this.waitSource?.TrySetResult(); | ||
} | ||
|
||
|
||
TaskCompletionSource? waitSource; | ||
public async Task WaitForAvailable(CancellationToken cancelToken = default) | ||
{ | ||
if (this.IsAvailable) | ||
return; | ||
|
||
var objRef = DotNetObjectReference.Create(this); | ||
((IJSInProcessRuntime)jsruntime).InvokeVoid("InternetService.subscribe", objRef); | ||
|
||
this.waitSource = new(); | ||
await this.waitSource.Task.ConfigureAwait(false); | ||
this.waitSource = null; | ||
} | ||
|
||
public void Dispose() => ((IJSInProcessRuntime)jsruntime).InvokeVoid("InternetService.unsubscribe"); | ||
} |
59 changes: 55 additions & 4 deletions
59
src/Shiny.Mediator.Blazor/Infrastructure/StorageService.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 |
---|---|---|
@@ -1,22 +1,73 @@ | ||
using System.Text.Json; | ||
using Microsoft.JSInterop; | ||
using Shiny.Mediator.Infrastructure; | ||
|
||
namespace Shiny.Mediator.Blazor.Infrastructure; | ||
|
||
|
||
public class StorageService : IStorageService | ||
public class StorageService(IJSRuntime jsruntime) : IStorageService | ||
{ | ||
public Task Store(object request, object result, bool isPeristent) | ||
{ | ||
throw new NotImplementedException(); | ||
var key = this.GetStoreKeyFromRequest(request); | ||
var store = isPeristent ? "localStorage" : "sessionStorage"; | ||
|
||
var json = JsonSerializer.Serialize(result); | ||
((IJSInProcessRuntime)jsruntime).Invoke<string?>(store + ".setItem", key, json); | ||
|
||
return Task.CompletedTask; | ||
} | ||
|
||
public Task<TResult?> Get<TResult>(object request, bool isPeristent) | ||
{ | ||
throw new NotImplementedException(); | ||
var key = this.GetStoreKeyFromRequest(request); | ||
var store = isPeristent ? "localStorage" : "sessionStorage"; | ||
var stringValue = ((IJSInProcessRuntime)jsruntime).Invoke<string?>(store + ".getItem", key); | ||
if (String.IsNullOrWhiteSpace(stringValue)) | ||
return null!; | ||
|
||
var final = JsonSerializer.Deserialize<TResult>(stringValue); | ||
return Task.FromResult(final); | ||
} | ||
|
||
public Task Clear() | ||
{ | ||
throw new NotImplementedException(); | ||
var inproc = (IJSInProcessRuntime)jsruntime; | ||
inproc.InvokeVoid("localStorage.clear"); | ||
inproc.InvokeVoid("sessionStorage.clear"); | ||
return Task.CompletedTask; | ||
} | ||
|
||
|
||
protected virtual string GetStoreKeyFromRequest(object request) | ||
{ | ||
if (request is IRequestKey keyProvider) | ||
return keyProvider.GetKey(); | ||
|
||
var t = request.GetType(); | ||
var key = $"{t.Namespace}_{t.Name}"; | ||
|
||
return key; | ||
} | ||
|
||
|
||
// protected virtual string GetPersistentStoreKey(object request, bool createIfNotExists) | ||
// { | ||
// var key = this.GetStoreKeyFromRequest(request); | ||
// this.EnsureKeyLoad(); | ||
// if (this.keys.ContainsKey(key)) | ||
// { | ||
// key = this.keys[key]; | ||
// } | ||
// else if (createIfNotExists) | ||
// { | ||
// var newKey = Guid.NewGuid().ToString(); | ||
// this.keys.Add(key, newKey); | ||
// key = newKey; | ||
// | ||
// this.PersistKeyStore(); | ||
// } | ||
// | ||
// return key; | ||
// } | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
let handler; | ||
|
||
window.InternetService = { | ||
subscribe: function(interop) { | ||
|
||
handler = function() { | ||
interop.invokeMethodAsync("InternetService.OnStatusChanged", navigator.onLine); | ||
} | ||
|
||
window.addEventListener("online", handler); | ||
window.addEventListener("offline", handler); | ||
}, | ||
|
||
unsubscribe: function() { | ||
if (handler == null) | ||
return; | ||
|
||
window.removeEventListener("online", handler); | ||
window.removeEventListener("offline", handler); | ||
} | ||
}; |
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
10 changes: 7 additions & 3 deletions
10
src/Shiny.Mediator.Maui/Middleware/MainTheadEventMiddleware.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
2 changes: 2 additions & 0 deletions
2
src/Shiny.Mediator.Maui/Middleware/MainThreadRequestHandler.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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
using Shiny.Mediator.Infrastructure; | ||
|
||
namespace Shiny.Mediator.Middleware; | ||
|
||
|
||
|
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 was deleted.
Oops, something went wrong.
Oops, something went wrong.