Skip to content

Commit db508a0

Browse files
committed
🐛 GetActiveUserRecord
1 parent eb065d7 commit db508a0

File tree

3 files changed

+38
-26
lines changed

3 files changed

+38
-26
lines changed

src/BD.WTTS.Client.Avalonia.App/Startup.cs

Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -295,33 +295,42 @@ public override void InitSettingSubscribe()
295295

296296
protected override ActiveUserRecordDTO GetActiveUserRecord()
297297
{
298-
#if !__MOBILE__ && !MAUI
299-
var app = UI.App.Instance;
300-
var window = app.GetFirstOrDefaultWindow();
301-
var screens = window?.Screens;
302-
#else
303-
var mainDisplayInfo = DeviceDisplay.MainDisplayInfo;
304-
var mainDisplayInfoH = mainDisplayInfo.Height.ToInt32(NumberToInt32Format.Ceiling);
305-
var mainDisplayInfoW = mainDisplayInfo.Width.ToInt32(NumberToInt32Format.Ceiling);
306-
#endif
307298
var result = new ActiveUserRecordDTO
308299
{
309-
#if __MOBILE__ || MAUI
310-
ScreenCount = 1,
311-
PrimaryScreenPixelDensity = mainDisplayInfo.Density,
312-
PrimaryScreenWidth = mainDisplayInfoW,
313-
PrimaryScreenHeight = mainDisplayInfoH,
314-
SumScreenWidth = mainDisplayInfoW,
315-
SumScreenHeight = mainDisplayInfoH,
300+
};
301+
SetScreen(result);
302+
static void SetScreen(ActiveUserRecordDTO m)
303+
{
304+
try
305+
{
306+
#if !__MOBILE__ && !MAUI
307+
var app = UI.App.Instance;
308+
var window = app.GetFirstOrDefaultWindow();
309+
var screens = window?.Screens;
310+
311+
m.ScreenCount = screens?.ScreenCount ?? default;
312+
m.PrimaryScreenPixelDensity = screens?.Primary?.Scaling ?? default;
313+
m.PrimaryScreenWidth = screens?.Primary?.Bounds.Width ?? default;
314+
m.PrimaryScreenHeight = screens?.Primary?.Bounds.Height ?? default;
315+
m.SumScreenWidth = screens?.All?.Sum(x => x.Bounds.Width) ?? default;
316+
m.SumScreenHeight = screens?.All?.Sum(x => x.Bounds.Height) ?? default;
316317
#else
317-
ScreenCount = screens?.ScreenCount ?? default,
318-
PrimaryScreenPixelDensity = screens?.Primary?.Scaling ?? default,
319-
PrimaryScreenWidth = screens?.Primary?.Bounds.Width ?? default,
320-
PrimaryScreenHeight = screens?.Primary?.Bounds.Height ?? default,
321-
SumScreenWidth = screens?.All.Sum(x => x.Bounds.Width) ?? default,
322-
SumScreenHeight = screens?.All.Sum(x => x.Bounds.Height) ?? default,
318+
var mainDisplayInfo = DeviceDisplay.MainDisplayInfo;
319+
var mainDisplayInfoH = mainDisplayInfo.Height.ToInt32(NumberToInt32Format.Ceiling);
320+
var mainDisplayInfoW = mainDisplayInfo.Width.ToInt32(NumberToInt32Format.Ceiling);
321+
322+
m.ScreenCount = 1;
323+
m.PrimaryScreenPixelDensity = mainDisplayInfo.Density;
324+
m.PrimaryScreenWidth = mainDisplayInfoW;
325+
m.PrimaryScreenHeight = mainDisplayInfoH;
326+
m.SumScreenWidth = mainDisplayInfoW;
327+
m.SumScreenHeight = mainDisplayInfoH;
323328
#endif
324-
};
329+
}
330+
catch
331+
{
332+
}
333+
}
325334
return result;
326335
}
327336
}

src/BD.WTTS.Client.Avalonia/UI/App.axaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public App()
4545
{
4646
if (ApplicationLifetime is ClassicDesktopStyleApplicationLifetime classicDesktopStyleApplicationLifetime)
4747
{
48-
window = classicDesktopStyleApplicationLifetime.Windows.FirstOrDefault(x => x != null);
48+
window = classicDesktopStyleApplicationLifetime.Windows?.FirstOrDefault(x => x != null);
4949
}
5050
}
5151
return window;

src/BD.WTTS.Client/Startup/Startup.GlobalExceptionHandler.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,12 +137,15 @@ public static void Handler(Exception ex, string name, bool? isTerminating = null
137137
#endif
138138

139139
#if WINDOWS
140-
var mbText =
140+
if (isTerminating == true)
141+
{
142+
var mbText =
141143
$"""
142144
{string.Format(message, args)}
143145
{ex}
144146
""";
145-
ShowApplicationCrash(mbText);
147+
ShowApplicationCrash(mbText);
148+
}
146149
#endif
147150
}
148151

0 commit comments

Comments
 (0)