File tree Expand file tree Collapse file tree 2 files changed +49
-3
lines changed
Assets/PatchKit Patcher/Scripts Expand file tree Collapse file tree 2 files changed +49
-3
lines changed Original file line number Diff line number Diff line change 22using UnityEngine . UI ;
33using UniRx ;
44using PatchKit . Unity . Patcher . Debug ;
5+ using PatchKit . Unity . Patcher . AppData . Local ;
56
67namespace 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}
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments