-
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.
Made extension contributions load in order, added spinner, updated Pa…
…ratextData to 9.5.0.6, misc bug fixes and improvements (#1066)
- Loading branch information
Showing
51 changed files
with
2,377 additions
and
1,752 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
using System.Diagnostics; | ||
using System.Text.Json; | ||
using Paranext.DataProvider.MessageTransports; | ||
|
||
namespace Paranext.DataProvider.Services; | ||
|
||
internal static class LocalizationService | ||
{ | ||
public const string SETTINGS_SERVICE_NAME = "platform.localizationDataServiceDataProvider"; | ||
private const string SETTINGS_SERVICE_REQUEST = $"object:{SETTINGS_SERVICE_NAME}-data.function"; | ||
|
||
/// <summary> | ||
/// Get a localized string value | ||
/// </summary> | ||
/// <param name="papiClient"></param> | ||
/// <param name="key">localized string key `%something%`</param> | ||
/// <param name="defaultValue">Default value if the key comes back as the value or the request fails</param> | ||
/// <param name="shouldThrowErrors">if set to `true`, will throw errors instead of ignoring and returning default value. Defaults to `false`</param> | ||
/// <returns></returns> | ||
public static string GetLocalizedString(PapiClient papiClient, string key, string? defaultValue = null, bool shouldThrowErrors = false) | ||
{ | ||
string value = defaultValue ?? key; | ||
TaskCompletionSource taskSource = new(); | ||
using var getSettingTask = taskSource.Task; | ||
|
||
papiClient.SendRequest( | ||
SETTINGS_SERVICE_REQUEST, | ||
new object[] { "getLocalizedString", new LocalizationSelector(key) }, | ||
(bool success, object? returnValue) => | ||
{ | ||
try | ||
{ | ||
if (success) | ||
{ | ||
var result = (JsonElement?)returnValue; | ||
if (result.HasValue) | ||
{ | ||
var resultString = result.Value.Deserialize<string>(); | ||
if (resultString != null && resultString != key) | ||
value = resultString; | ||
} | ||
} | ||
|
||
taskSource.TrySetResult(); | ||
} | ||
catch (Exception ex) | ||
{ | ||
if (shouldThrowErrors) | ||
taskSource.TrySetException(ex); | ||
else { | ||
Trace.TraceError(ex.Message); | ||
taskSource.TrySetResult(); | ||
} | ||
} | ||
} | ||
); | ||
|
||
using var cts = new CancellationTokenSource(); | ||
getSettingTask.Wait(cts.Token); | ||
return value; | ||
} | ||
} | ||
|
||
public class LocalizationSelector(string localizeKey) | ||
{ | ||
/// <summary> | ||
/// ID of the project (must be unique and case-insensitive) | ||
/// </summary> | ||
public string LocalizeKey { get; } = localizeKey; | ||
} |
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,22 @@ | ||
using Paranext.DataProvider.MessageTransports; | ||
using Paratext.Data; | ||
using PtxUtils; | ||
|
||
namespace Paranext.DataProvider.Services; | ||
|
||
internal class PersistedParatextDataSettings(PapiClient papiClient) : IParatextDataSettings | ||
{ | ||
public SerializableStringDictionary LastRegistryDataCachedTimes { get; set; } = SettingsService.GetSettingObject<SerializableStringDictionary>( | ||
papiClient, | ||
Settings.PARATEXT_DATA_LAST_REGISTRY_DATA_CACHED_TIMES | ||
) ?? []; | ||
|
||
public void SafeSave() | ||
{ | ||
SettingsService.SetSetting( | ||
papiClient, | ||
Settings.PARATEXT_DATA_LAST_REGISTRY_DATA_CACHED_TIMES, | ||
LastRegistryDataCachedTimes | ||
); | ||
} | ||
} |
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,29 @@ | ||
using Paranext.DataProvider.MessageTransports; | ||
using PtxUtils; | ||
|
||
namespace Paranext.DataProvider.Services; | ||
|
||
internal class PersistedPtxUtilsSettings(PapiClient papiClient) : IPtxUtilsSettings | ||
{ | ||
public SerializableStringDictionary MementoData { get; set;} = SettingsService.GetSettingObject<SerializableStringDictionary>( | ||
papiClient, | ||
Settings.PTX_UTILS_MEMENTO_DATA | ||
) ?? []; | ||
|
||
public bool UpgradeNeeded | ||
{ | ||
get => throw new NotImplementedException(); | ||
set => throw new NotImplementedException(); | ||
} | ||
|
||
public bool EnableFormSnapping | ||
{ | ||
get => throw new NotImplementedException(); | ||
set => throw new NotImplementedException(); | ||
} | ||
|
||
public void SafeSave() | ||
{ | ||
SettingsService.SetSetting(papiClient, Settings.PTX_UTILS_MEMENTO_DATA, MementoData); | ||
} | ||
} |
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
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Oops, something went wrong.