Skip to content

Commit 7c66cc5

Browse files
authored
Merge pull request #136 from patchkit-net/feature/v3.x.x.x/1350-cache-app-display-name
Cache app display name (#1350)
2 parents cb02623 + 3377038 commit 7c66cc5

File tree

2 files changed

+49
-3
lines changed

2 files changed

+49
-3
lines changed

Assets/PatchKit Patcher/Scripts/GameTitle.cs

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,71 @@
22
using UnityEngine.UI;
33
using UniRx;
44
using PatchKit.Unity.Patcher.Debug;
5+
using PatchKit.Unity.Patcher.AppData.Local;
56

67
namespace PatchKit.Unity
78
{
89
public class GameTitle : MonoBehaviour
910
{
11+
private const string TitleCacheKey = "app-display-name";
12+
1013
public Text Text;
1114

15+
private bool _hasBeenSet;
16+
1217
private void Start()
1318
{
1419
var patcher = Patcher.Patcher.Instance;
1520

1621
Assert.IsNotNull(patcher);
1722
Assert.IsNotNull(Text);
1823

24+
patcher.Data
25+
.ObserveOnMainThread()
26+
.Select(x => x.AppSecret)
27+
.SkipWhile(string.IsNullOrEmpty)
28+
.First()
29+
.Subscribe(UseCachedText)
30+
.AddTo(this);
31+
1932
patcher.AppInfo
2033
.ObserveOnMainThread()
21-
.Select(app => app.DisplayName)
22-
.Where(s => !string.IsNullOrEmpty(s))
23-
.SubscribeToText(Text)
34+
.Where(x => !string.IsNullOrEmpty(x.DisplayName))
35+
.Subscribe(SetAndCacheText)
2436
.AddTo(this);
2537
}
38+
39+
private void UseCachedText(string appSecret)
40+
{
41+
if (_hasBeenSet)
42+
{
43+
return;
44+
}
45+
46+
var cachedDisplayName = GetCache(appSecret)
47+
.GetValue(TitleCacheKey, null);
48+
49+
if (string.IsNullOrEmpty(cachedDisplayName))
50+
{
51+
return;
52+
}
53+
54+
Text.text = cachedDisplayName;
55+
}
56+
57+
private void SetAndCacheText(PatchKit.Api.Models.Main.App app)
58+
{
59+
string displayName = app.DisplayName;
60+
61+
GetCache(app.Secret).SetValue(TitleCacheKey, displayName);
62+
Text.text = displayName;
63+
64+
_hasBeenSet = true;
65+
}
66+
67+
private ICache GetCache(string appSecret)
68+
{
69+
return new UnityCache(appSecret);
70+
}
2671
}
2772
}

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
66

77
## [3.x.x.x]
88
### Added
9+
- Caching application display name so it can be displayed in offline mode (#1350)
910
- Caching application changelog so it can be displayed in offline mode (#1361)
1011
- Skip unchanged files while patching (#994)
1112

0 commit comments

Comments
 (0)