-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAppShell.xaml.cs
More file actions
123 lines (110 loc) · 3.04 KB
/
AppShell.xaml.cs
File metadata and controls
123 lines (110 loc) · 3.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
using WorkshopUploader.Localization;
using WorkshopUploader.Services;
namespace WorkshopUploader;
public partial class AppShell : Shell
{
private readonly SteamWorkshopService _steam;
private bool _steamStatusTimerStarted;
public AppShell(ProjectsPage projects, NewProjectPage newProject, MyUploadsPage uploads, ModManagerPage modManager, SettingsPage settings, SteamWorkshopService steam)
{
_steam = steam;
// #region agent log
DebugSessionLog.Write("H2", "AppShell.ctor", "before_init", null);
// #endregion
InitializeComponent();
// #region agent log
DebugSessionLog.Write("H2", "AppShell.ctor", "after_init", null);
// #endregion
Loaded += OnShellLoaded;
var tabBar = new TabBar();
tabBar.Items.Add(new ShellContent
{
Title = S.Get("Tab_Projects"),
Content = projects,
Route = nameof(ProjectsPage),
});
tabBar.Items.Add(new ShellContent
{
Title = S.Get("Tab_New"),
Content = newProject,
Route = nameof(NewProjectPage),
});
tabBar.Items.Add(new ShellContent
{
Title = S.Get("Tab_MyUploads"),
Content = uploads,
Route = nameof(MyUploadsPage),
});
if (SettingsPage.IsModStoreEnabled())
{
tabBar.Items.Add(new ShellContent
{
Title = S.Get("Tab_ModStore"),
Content = modManager,
Route = nameof(ModManagerPage),
});
}
tabBar.Items.Add(new ShellContent
{
Title = S.Get("Tab_Settings"),
Content = settings,
Route = nameof(SettingsPage),
});
Items.Add(tabBar);
Routing.RegisterRoute(nameof(EditorPage), typeof(EditorPage));
Routing.RegisterRoute(nameof(NativeConfigEditorPage), typeof(NativeConfigEditorPage));
Routing.RegisterRoute(nameof(ItemDetailPage), typeof(ItemDetailPage));
}
private void OnShellLoaded(object? sender, EventArgs e)
{
if (_steamStatusTimerStarted)
{
return;
}
_steamStatusTimerStarted = true;
Loaded -= OnShellLoaded;
UpdateSteamConnectionUi();
var dispatcher = Application.Current?.Dispatcher;
if (dispatcher is null)
{
return;
}
dispatcher.StartTimer(TimeSpan.FromSeconds(2), () =>
{
MainThread.BeginInvokeOnMainThread(UpdateSteamConnectionUi);
return true;
});
}
private void UpdateSteamConnectionUi()
{
if (_steam.TryGetSteamReady(out var userName))
{
SteamStatusLed.Fill = new SolidColorBrush(Color.FromArgb("#61F4D8"));
SteamLogoTile.BackgroundColor = Color.FromArgb("#0D3835");
SteamStatusText.TextColor = Color.FromArgb("#C0FCF6");
SteamStatusText.Text = string.IsNullOrEmpty(userName)
? S.Get("Steam_Ok")
: S.Format("Steam_User", userName);
}
else
{
SteamStatusLed.Fill = new SolidColorBrush(Color.FromArgb("#D7383B"));
SteamLogoTile.BackgroundColor = Color.FromArgb("#1A2A1012");
SteamStatusText.TextColor = Color.FromArgb("#7FBFB8");
var hint = _steam.LastSteamConnectionHint;
if (string.IsNullOrWhiteSpace(hint))
{
SteamStatusText.Text = S.Get("Steam_Offline");
}
else
{
const int maxLen = 72;
if (hint.Length > maxLen)
{
hint = hint[..maxLen] + "…";
}
SteamStatusText.Text = S.Format("Steam_Hint", hint);
}
}
}
}