Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 48 additions & 3 deletions Assets/PatchKit Patcher/Scripts/GameTitle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,71 @@
using UnityEngine.UI;
using UniRx;
using PatchKit.Unity.Patcher.Debug;
using PatchKit.Unity.Patcher.AppData.Local;

namespace PatchKit.Unity
{
public class GameTitle : MonoBehaviour
{
private const string TitleCacheKey = "app-display-name";

public Text Text;

private bool _hasBeenSet;

private void Start()
{
var patcher = Patcher.Patcher.Instance;

Assert.IsNotNull(patcher);
Assert.IsNotNull(Text);

patcher.Data
.ObserveOnMainThread()
.Select(x => x.AppSecret)
.SkipWhile(string.IsNullOrEmpty)
.First()
.Subscribe(UseCachedText)
.AddTo(this);

patcher.AppInfo
.ObserveOnMainThread()
.Select(app => app.DisplayName)
.Where(s => !string.IsNullOrEmpty(s))
.SubscribeToText(Text)
.Where(x => !string.IsNullOrEmpty(x.DisplayName))
.Subscribe(SetAndCacheText)
.AddTo(this);
}

private void UseCachedText(string appSecret)
{
if (_hasBeenSet)
{
return;
}

var cachedDisplayName = GetCache(appSecret)
.GetValue(TitleCacheKey, null);

if (string.IsNullOrEmpty(cachedDisplayName))
{
return;
}

Text.text = cachedDisplayName;
}

private void SetAndCacheText(PatchKit.Api.Models.Main.App app)
{
string displayName = app.DisplayName;

GetCache(app.Secret).SetValue(TitleCacheKey, displayName);
Text.text = displayName;

_hasBeenSet = true;
}

private ICache GetCache(string appSecret)
{
return new UnityCache(appSecret);
}
}
}
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

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

Expand Down