Skip to content

Commit 3854c40

Browse files
committed
Cache app display name
1 parent dd5cd91 commit 3854c40

File tree

2 files changed

+50
-3
lines changed

2 files changed

+50
-3
lines changed

Assets/PatchKit Patcher/Scripts/GameTitle.cs

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,69 @@
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
{
1011
public Text Text;
1112

13+
private bool _hasBeenSet;
14+
1215
private void Start()
1316
{
1417
var patcher = Patcher.Patcher.Instance;
1518

1619
Assert.IsNotNull(patcher);
1720
Assert.IsNotNull(Text);
1821

22+
patcher.Data
23+
.ObserveOnMainThread()
24+
.SkipWhile(data => string.IsNullOrEmpty(data.AppSecret))
25+
.Select(x => x.AppSecret)
26+
.First()
27+
.Subscribe(UseCachedText)
28+
.AddTo(this);
29+
1930
patcher.AppInfo
2031
.ObserveOnMainThread()
21-
.Select(app => app.DisplayName)
22-
.Where(s => !string.IsNullOrEmpty(s))
23-
.SubscribeToText(Text)
32+
.Where(x => !string.IsNullOrEmpty(x.DisplayName))
33+
.Subscribe(SetAndCacheText)
2434
.AddTo(this);
2535
}
36+
37+
private void UseCachedText(string appSecret)
38+
{
39+
if(_hasBeenSet)
40+
{
41+
return;
42+
}
43+
44+
var cachedDisplayName = GetCache(appSecret)
45+
.GetValue("app-display-name", null);
46+
47+
if (string.IsNullOrEmpty(cachedDisplayName))
48+
{
49+
return;
50+
}
51+
52+
Text.text = cachedDisplayName;
53+
}
54+
55+
private void SetAndCacheText(PatchKit.Api.Models.Main.App app)
56+
{
57+
string displayName = app.DisplayName;
58+
59+
GetCache(app.Secret).SetValue("app-display-name", displayName);
60+
Text.text = displayName;
61+
62+
_hasBeenSet = true;
63+
}
64+
65+
private ICache GetCache(string appSecret)
66+
{
67+
return new UnityCache(appSecret);
68+
}
2669
}
2770
}

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](http://keepachangelog.com/)
55
and this project adheres to [Semantic Versioning](http://semver.org/).
66

7+
## [3.x.x.x]
8+
### Added
9+
- Caching application display name so it can be displayed in offline mode (#1350)
10+
711
## [3.14.0.0]
812
### Added
913
- Automated scripting runtime changing to .NET 3.5 on Unity 2017 or newer (#1241)

0 commit comments

Comments
 (0)