Skip to content

Commit 115cdd4

Browse files
committed
Small changes
* Added CustomTooltip, letting us enable/disable them with the new disable tooltip setting * Added more styling * Fixed crash if theme dir doesn't exist * Fixed crash on accessing theme with disposed archive * Fixed DiscordCheckOverlay being stuck on Linux * Temp disable other json context * Package bumps
1 parent e9e0773 commit 115cdd4

20 files changed

+180
-59
lines changed

MultiRPC/Assets/Language/en-gb.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,5 +243,6 @@
243243
"ToAdd": "To Add",
244244
"SomethingHappenedWhileGettingThemeColours": "Something happened while getting theme colours in {themepath}",
245245
"SomethingHappenedWhileGettingThemeMetadata": "Something happened while getting theme metadata in {themepath}",
246-
"WewCheckBox": "Wew this is a checkbox header"
246+
"WewCheckBox": "Wew this is a checkbox header",
247+
"ShowAllTooltips": "Disable all tooltips (Helps with Tile Window Managers)"
247248
}

MultiRPC/MultiRPC.csproj

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@
1111
<BuiltInComInteropSupport>true</BuiltInComInteropSupport>
1212
</PropertyGroup>
1313
<ItemGroup Label="Packages">
14-
<PackageReference Include="Avalonia.Desktop" Version="0.10.10" />
15-
<PackageReference Include="Avalonia.Svg" Version="0.10.10" />
14+
<PackageReference Include="Avalonia.Desktop" Version="0.10.11" />
15+
<PackageReference Include="Avalonia.Svg" Version="0.10.11" />
1616
<PackageReference Include="DiscordRichPresence" Version="1.0.175" />
17-
<PackageReference Include="Splat" Version="14.1.1" />
18-
<PackageReference Include="System.IO.Pipelines" Version="6.0.0" />
19-
<PackageReference Include="System.Text.Json" Version="6.0.0" />
17+
<PackageReference Include="Splat" Version="14.1.17" />
18+
<PackageReference Include="System.IO.Pipelines" Version="6.0.1" />
19+
<PackageReference Include="System.Text.Json" Version="6.0.1" />
2020
<PackageReference Include="TinyUpdate.Binary" Version="0.0.0.10-alpha" />
2121
<PackageReference Include="TinyUpdate.Github" Version="0.0.0.10-alpha" />
2222
<PackageReference Include="XamlNameReferenceGenerator" Version="1.3.4" />
@@ -27,7 +27,7 @@
2727
</ItemGroup>
2828

2929
<ItemGroup Condition=" '$(Configuration)' == 'Debug' " Label="Debug Packages">
30-
<PackageReference Include="Avalonia.Diagnostics" Version="0.10.10" />
30+
<PackageReference Include="Avalonia.Diagnostics" Version="0.10.11" />
3131
</ItemGroup>
3232

3333
<ItemGroup Label="Resources">

MultiRPC/Setting/Settings/DisableSettings.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ public partial class DisableSettings : BaseSetting
99
[JsonIgnore]
1010
public override string Name => "Disable";
1111

12-
public override JsonSerializerContext? SerializerContext { get; } = DisableSettingsContext.Default;
12+
[JsonIgnore]
13+
public override JsonSerializerContext? SerializerContext { get; }
1314

1415
[GeneratedProperty, SettingName("DiscordCheck")]
1516
private bool _discordCheck;
@@ -29,9 +30,12 @@ public partial class DisableSettings : BaseSetting
2930
[GeneratedProperty, SettingName("ShowPageTooltips")]
3031
private bool _showPageTooltips;
3132

33+
[GeneratedProperty, SettingName("ShowAllTooltips")]
34+
private bool _allTooltips;
35+
3236
[GeneratedProperty]
3337
private bool _inviteWarn;
3438
}
3539

36-
[JsonSerializable(typeof(DisableSettings))]
37-
public partial class DisableSettingsContext : JsonSerializerContext { }
40+
/*[JsonSerializable(typeof(DisableSettings))]
41+
public partial class DisableSettingsContext : JsonSerializerContext { }*/

MultiRPC/Setting/Settings/GeneralSettings.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public partial class GeneralSettings : BaseSetting
1616
[JsonIgnore]
1717
public override string Name => "General";
1818

19-
public override JsonSerializerContext? SerializerContext { get; } = GeneralSettingsContext.Default;
19+
public override JsonSerializerContext? SerializerContext { get; }
2020

2121
[GeneratedProperty]
2222
private string? _lastUser = "NA#0000";
@@ -76,5 +76,5 @@ private string[] GetAutoStarts()
7676
}
7777
}
7878

79-
[JsonSerializable(typeof(GeneralSettings))]
80-
public partial class GeneralSettingsContext : JsonSerializerContext { }
79+
/*[JsonSerializable(typeof(GeneralSettings))]
80+
public partial class GeneralSettingsContext : JsonSerializerContext { }*/

MultiRPC/Theming/Theme.cs

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,17 @@ static Theme()
6767

6868
public bool HaveAsset(string key)
6969
{
70+
if (Mode == ThemeMode.Modern)
71+
{
72+
if (!_archiveLoaded)
73+
{
74+
ReloadAssets();
75+
}
76+
return _archive?.Entries.Any(x => x.FullName == "Assets/" + key) ?? false;
77+
}
78+
7079
//We can't load in assets from the older theming
71-
return Mode == ThemeMode.Modern
72-
&& (_archive?.Entries.Any(x => x.FullName == "Assets/" + key) ?? false);
80+
return false;
7381
}
7482

7583
public Stream GetAssetStream(string key)
@@ -78,12 +86,17 @@ public Stream GetAssetStream(string key)
7886
{
7987
return Stream.Null;
8088
}
81-
89+
if (!_archiveLoaded)
90+
{
91+
ReloadAssets();
92+
}
93+
8294
return _archive?.Entries
8395
.FirstOrDefault(x => x.FullName == "Assets/" + key)?
8496
.Open() ?? Stream.Null;
8597
}
86-
98+
99+
private string _filepath = null!;
87100
private ZipArchive? _archive;
88101
/// <summary>
89102
/// Load's in the theme for being used
@@ -114,10 +127,12 @@ public Stream GetAssetStream(string key)
114127
return null;
115128
}
116129

117-
var theme = new Theme()
130+
var theme = new Theme
118131
{
119132
Location = filepath,
120-
_archive = archive
133+
_archive = archive,
134+
_filepath = filepath,
135+
_archiveLoaded = true
121136
};
122137
try
123138
{
@@ -154,10 +169,27 @@ public Stream GetAssetStream(string key)
154169
if (theme.Mode == ThemeMode.Legacy)
155170
{
156171
archive.Dispose();
172+
theme._archiveLoaded = false;
157173
}
158174
return theme;
159175
}
160176

177+
private bool _archiveLoaded = false;
178+
public void ReloadAssets()
179+
{
180+
UnloadAssets();
181+
182+
var fileStream = StreamUtil.SafeOpenRead(_filepath);
183+
_archive = new ZipArchive(fileStream, ZipArchiveMode.Read);
184+
_archiveLoaded = true;
185+
}
186+
187+
public void UnloadAssets()
188+
{
189+
_archive?.Dispose();
190+
_archiveLoaded = false;
191+
}
192+
161193
/// <summary>
162194
/// Applies the theming to a IResourceDictionary (or App.Current.Resources if nothing is applied)
163195
/// </summary>
@@ -167,7 +199,7 @@ public void Apply(IResourceDictionary? resourceDictionary = null)
167199
if (resourceDictionary == null)
168200
{
169201
resourceDictionary = Application.Current.Resources;
170-
ActiveTheme?.Dispose();
202+
ActiveTheme?.UnloadAssets();
171203
ActiveTheme = this;
172204
}
173205
resourceDictionary["ThemeAccentColor"] = Colours.ThemeAccentColor;
@@ -188,7 +220,6 @@ public void Apply(IResourceDictionary? resourceDictionary = null)
188220

189221
public void Dispose()
190222
{
191-
_archive?.Dispose();
192223
GC.SuppressFinalize(this);
193224
}
194225
}

MultiRPC/UI/App.axaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
<SolidColorBrush x:Key="RedBrush" Color="{DynamicResource Red}" />
2727
<SolidColorBrush x:Key="PurpleBrush" Color="{DynamicResource Purple}" />
2828

29+
<SolidColorBrush x:Key="ThemeForegroundBrush" Color="White" />
30+
<SolidColorBrush x:Key="ComboBoxDropDownBackground" Color="{DynamicResource ThemeAccentColor2}" />
2931
<SolidColorBrush x:Key="ThemeAccentBrush" Color="{DynamicResource ThemeAccentColor}"/>
3032
<SolidColorBrush x:Key="ThemeAccentBrush2" Color="{DynamicResource ThemeAccentColor2}"/>
3133
<SolidColorBrush x:Key="ThemeAccentBrush2Hover" Color="{DynamicResource ThemeAccentColor2Hover}"/>

MultiRPC/UI/Controls/TabsPage.axaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ private Control MakeTab(ITabPage page)
4040
var rec = new Rectangle
4141
{
4242
Height = 0,
43-
Fill = Brushes.White
43+
[!Shape.FillProperty] = Application.Current.GetResourceObservable("ThemeForegroundBrush").ToBinding()
4444
};
4545

4646
var stc = new StackPanel

MultiRPC/UI/CustomTooltip.cs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
using System.Collections.Generic;
2+
using System.ComponentModel;
3+
using Avalonia.Controls;
4+
using MultiRPC.Setting;
5+
using MultiRPC.Setting.Settings;
6+
7+
namespace MultiRPC.UI;
8+
9+
/// <summary>
10+
/// This helps us use our system for disabling tooltips when they are not wanted
11+
/// </summary>
12+
public static class CustomToolTip
13+
{
14+
static CustomToolTip()
15+
{
16+
DisableSettings.PropertyChanged += DisableSettingsOnPropertyChanged;
17+
}
18+
19+
private static void DisableSettingsOnPropertyChanged(object? sender, PropertyChangedEventArgs e)
20+
{
21+
if (e.PropertyName == nameof(Setting.Settings.DisableSettings.AllTooltips))
22+
{
23+
foreach (var (key, value) in StoredTooltips)
24+
{
25+
SetTooltip(key, value);
26+
}
27+
}
28+
}
29+
30+
private static readonly Dictionary<Control, object?> StoredTooltips = new Dictionary<Control, object?>();
31+
private static readonly DisableSettings DisableSettings = SettingManager<DisableSettings>.Setting;
32+
public static void SetTip(Control element, object? value)
33+
{
34+
if (!StoredTooltips.ContainsKey(element))
35+
{
36+
StoredTooltips.Add(element, value);
37+
}
38+
StoredTooltips[element] = value;
39+
SetTooltip(element, value);
40+
}
41+
42+
private static void SetTooltip(Control element, object? value)
43+
{
44+
if (!DisableSettings.AllTooltips)
45+
{
46+
ToolTip.SetTip(element, value);
47+
return;
48+
}
49+
50+
ToolTip.SetTip(element, null);
51+
}
52+
}

MultiRPC/UI/MainPage.axaml.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,12 +127,12 @@ private Button AddSidePage(ISidePage page)
127127
});
128128

129129
var lang = Language.GetLanguage(page.LocalizableName);
130-
lang.TextObservable.Subscribe(s => ToolTip.SetTip(btn, _disableSetting.ShowPageTooltips ? null : s));
130+
lang.TextObservable.Subscribe(s => CustomToolTip.SetTip(btn, _disableSetting.ShowPageTooltips ? null : s));
131131
_disableSetting.PropertyChanged += (sender, args) =>
132132
{
133133
if (args.PropertyName == nameof(DisableSettings.ShowPageTooltips))
134134
{
135-
ToolTip.SetTip(btn, _disableSetting.ShowPageTooltips ? null : lang.Text);
135+
CustomToolTip.SetTip(btn, _disableSetting.ShowPageTooltips ? null : lang.Text);
136136
}
137137
};
138138

MultiRPC/UI/MainWindow.axaml.cs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.IO;
33
using System.Linq;
4+
using System.Runtime.InteropServices;
45
using System.Windows.Input;
56
using Avalonia;
67
using Avalonia.Controls;
@@ -42,6 +43,21 @@ public partial class MainWindow : FluentWindow
4243
{
4344
public MainWindow() : this(new MainPage())
4445
{
46+
DragDrop.SetAllowDrop(this, true);
47+
AddHandler(DragDrop.DropEvent, DragOver);
48+
AddHandler(DragDrop.DragEnterEvent, DragEnter);
49+
50+
/*Tray Icon seems to be a bit broken on anything other then windows
51+
after running for a while, skip if we aren't on windows but we also
52+
crash on shutdown which is an issue for passing Microsoft store validation
53+
so skip if deploying to it*/
54+
#if !WINSTORE
55+
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
56+
#endif
57+
{
58+
return;
59+
}
60+
4561
var disableSettings = SettingManager<DisableSettings>.Setting;
4662
var trayIcon = new TrayIcon
4763
{
@@ -57,10 +73,6 @@ public MainWindow() : this(new MainPage())
5773
ChangeTrayIconText(trayIcon);
5874
ShowInTaskbar = !(!disableSettings.HideTaskbarIcon && x == WindowState.Minimized);
5975
});
60-
61-
DragDrop.SetAllowDrop(this, true);
62-
AddHandler(DragDrop.DropEvent, DragOver);
63-
AddHandler(DragDrop.DragEnterEvent, DragEnter);
6476
}
6577

6678
private void DragEnter(object? sender, DragEventArgs e)

MultiRPC/UI/Overlays/DiscordCheckOverlay.axaml.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
using System.Diagnostics;
2+
using System.Runtime.InteropServices;
23
using System.Threading.Tasks;
34
using Avalonia.Controls;
45
using Avalonia.Interactivity;
56
using MultiRPC.Extensions;
67
using MultiRPC.Setting;
78
using MultiRPC.Setting.Settings;
9+
using TinyUpdate.Core.Helper;
810
using TinyUpdate.Core.Logging;
911

1012
namespace MultiRPC.UI.Overlays;
@@ -83,11 +85,13 @@ private async Task WaitForDiscord()
8385
tblMultiRPC.Text = "MultiRPC - " + Language.GetText(discordClient);
8486
}
8587

88+
var processExpectedCount = OSHelper.ActiveOS == OSPlatform.Windows ? 4 : 2;
89+
8690
while (!_ranFadeOut)
8791
{
8892
//If we have less then 4 processes from discord then discord itself is still loading
8993
var processCount = Process.GetProcessesByName(discordClient).Length;
90-
if (processCount < 4)
94+
if (processCount < processExpectedCount)
9195
{
9296
tblDiscordClientMessage.Text =
9397
$"{Language.GetText(discordClient)} {Language.GetText(LanguageText.IsLoading)}....";

MultiRPC/UI/Pages/Rpc/BaseRpcControl.axaml.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ private async Task CheckID(string s)
192192
txtClientID.Classes.Remove("checking");
193193
if (successful)
194194
{
195-
ToolTip.SetTip(txtClientID, null);
195+
CustomToolTip.SetTip(txtClientID, null);
196196
RichPresence.ID = id;
197197
if (RichPresence.Name.StartsWith("Profile"))
198198
{
@@ -205,7 +205,7 @@ private async Task CheckID(string s)
205205
}
206206
txtClientID.Classes.Add("error");
207207
error ??= Language.GetText(LanguageText.ClientIDIsNotValid);
208-
ToolTip.SetTip(txtClientID, error);
208+
CustomToolTip.SetTip(txtClientID, error);
209209
ProfileChanged?.Invoke(this, EventArgs.Empty);
210210
}
211211

MultiRPC/UI/Pages/Rpc/Custom/CustomPage.axaml.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,10 @@ public override void Initialize(bool loadXaml)
9393
tabPage.Initialize();
9494

9595
//Setup tooltips
96-
_editLang.TextObservable.Subscribe(x => ToolTip.SetTip(imgProfileEdit, x));
97-
_shareLang.TextObservable.Subscribe(x => ToolTip.SetTip(imgProfileShare, x));
98-
_addLang.TextObservable.Subscribe(x => ToolTip.SetTip(imgProfileAdd, x));
99-
_deleteLang.TextObservable.Subscribe(x => ToolTip.SetTip(imgProfileDelete, x));
96+
_editLang.TextObservable.Subscribe(x => CustomToolTip.SetTip(imgProfileEdit, x));
97+
_shareLang.TextObservable.Subscribe(x => CustomToolTip.SetTip(imgProfileShare, x));
98+
_addLang.TextObservable.Subscribe(x => CustomToolTip.SetTip(imgProfileAdd, x));
99+
_deleteLang.TextObservable.Subscribe(x => CustomToolTip.SetTip(imgProfileDelete, x));
100100

101101
//Make help controls
102102
var helpGrid = new Grid

MultiRPC/UI/Pages/Settings/AboutSettingsTab.axaml.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,13 @@ public void Initialize(bool loadXaml)
4545
_ = CheckDiscordStatus();
4646

4747
var githubTooltipLang = Language.GetLanguage(LanguageText.GithubTooltip);
48-
githubTooltipLang.TextObservable.Subscribe(x => ToolTip.SetTip(imgGithub, x));
48+
githubTooltipLang.TextObservable.Subscribe(x => CustomToolTip.SetTip(imgGithub, x));
4949

5050
var fluxpointTooltipLang = Language.GetLanguage(LanguageText.FluxpointTooltip);
51-
fluxpointTooltipLang.TextObservable.Subscribe(x => ToolTip.SetTip(imgFluxpoint, x));
51+
fluxpointTooltipLang.TextObservable.Subscribe(x => CustomToolTip.SetTip(imgFluxpoint, x));
5252

5353
var discordTooltipLang = Language.GetLanguage(LanguageText.JoinForFunBotsAndSupport);
54-
discordTooltipLang.TextObservable.Subscribe(x => ToolTip.SetTip(brdDiscord, x));
54+
discordTooltipLang.TextObservable.Subscribe(x => CustomToolTip.SetTip(brdDiscord, x));
5555

5656
imgIcon.AddSvgAsset("Logo.svg");
5757
imgGithub.AddSvgAsset("Icons/Github.svg");

0 commit comments

Comments
 (0)