From a0517a83d2b559de45bb6fbe75a2e185b9c4646f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Alm=C3=A9n?= <78877636+almenscorner@users.noreply.github.com> Date: Fri, 24 May 2024 13:29:33 +0200 Subject: [PATCH 1/4] Set initial color to #FFFFFF --- Models/DeviceInfoModel.cs | 2 +- Models/StorageModel.cs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Models/DeviceInfoModel.cs b/Models/DeviceInfoModel.cs index 009eaf8..a600d44 100644 --- a/Models/DeviceInfoModel.cs +++ b/Models/DeviceInfoModel.cs @@ -7,7 +7,7 @@ public partial class DeviceInfoModel : ObservableObject [ObservableProperty] private string _hostName = string.Empty; [ObservableProperty] private string _ipAddress = string.Empty; [ObservableProperty] private int _lastBootTime; - [ObservableProperty] private string _lastBootTimeColor = string.Empty; + [ObservableProperty] private string _lastBootTimeColor = "#FFFFFF"; [ObservableProperty] private long _memSize; [ObservableProperty] private string _model = string.Empty; [ObservableProperty] private string _osBuild = string.Empty; diff --git a/Models/StorageModel.cs b/Models/StorageModel.cs index 5a83fb0..f345257 100644 --- a/Models/StorageModel.cs +++ b/Models/StorageModel.cs @@ -6,12 +6,12 @@ public partial class StorageModel : ObservableObject { [ObservableProperty] private bool _fileVaultEnabled; [ObservableProperty] private bool _isEncrypted; - [ObservableProperty] private string _isEncryptedColor = string.Empty; + [ObservableProperty] private string _isEncryptedColor = "#FFFFFF"; [ObservableProperty] private double _volumeFree; [ObservableProperty] private string _volumeName = string.Empty; [ObservableProperty] private double _volumeSize; [ObservableProperty] private string _volumeType = string.Empty; [ObservableProperty] private double _volumeUsed; [ObservableProperty] private double _volumeUsedPercentage; - [ObservableProperty] private string _volumeUsedPercentageColor = string.Empty; + [ObservableProperty] private string _volumeUsedPercentageColor = "#FFFFFF"; } \ No newline at end of file From a1481d1a16c87a0a915136dea53d79caabc46a04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Alm=C3=A9n?= <78877636+almenscorner@users.noreply.github.com> Date: Fri, 24 May 2024 13:35:28 +0200 Subject: [PATCH 2/4] Refresh data on show window --- Models/EvergreenInfoModel.cs | 3 ++- ViewModels/DeviceWidgetViewModel.cs | 10 ++++++++- ViewModels/EvergreenWidgetViewModel.cs | 28 +++++++++++++++++++------- ViewModels/MacPasswordViewModel.cs | 17 ++++++++++++++-- ViewModels/MdmStatusViewModel.cs | 9 ++++++++- ViewModels/StorageViewModel.cs | 10 ++++++++- ViewModels/UserViewModel.cs | 9 ++++++++- 7 files changed, 72 insertions(+), 14 deletions(-) diff --git a/Models/EvergreenInfoModel.cs b/Models/EvergreenInfoModel.cs index 3bf5ce0..b1b1b57 100644 --- a/Models/EvergreenInfoModel.cs +++ b/Models/EvergreenInfoModel.cs @@ -1,8 +1,9 @@ +using System.Collections.ObjectModel; using CommunityToolkit.Mvvm.ComponentModel; namespace SupportCompanion.Models; public partial class EvergreenInfoModel : ObservableObject { - [ObservableProperty] private List? _catalogs = new(); + [ObservableProperty] private ObservableCollection _catalogs = new(); } \ No newline at end of file diff --git a/ViewModels/DeviceWidgetViewModel.cs b/ViewModels/DeviceWidgetViewModel.cs index b58a4c4..3956c57 100644 --- a/ViewModels/DeviceWidgetViewModel.cs +++ b/ViewModels/DeviceWidgetViewModel.cs @@ -1,4 +1,5 @@ using Avalonia.Threading; +using ReactiveUI; using SukiUI.Controls; using SupportCompanion.Helpers; using SupportCompanion.Interfaces; @@ -13,6 +14,8 @@ public class DeviceWidgetViewModel : ViewModelBase, IWindowStateAware private readonly IOKitService _iioKit; private readonly SystemInfoService _systemInfo; + private DeviceInfoModel? _deviceInfo; + public DeviceWidgetViewModel(SystemInfoService systemInfo, ClipboardService clipboard, IOKitService iioKit) { @@ -23,7 +26,12 @@ public DeviceWidgetViewModel(SystemInfoService systemInfo, Dispatcher.UIThread.Post(InitializeAsync); } - public DeviceInfoModel? DeviceInfo { get; private set; } + public DeviceInfoModel? DeviceInfo + { + get => _deviceInfo; + private set => this.RaiseAndSetIfChanged(ref _deviceInfo, value); + } + private string ModelValue { get; set; } = string.Empty; public string RebootToolTip => diff --git a/ViewModels/EvergreenWidgetViewModel.cs b/ViewModels/EvergreenWidgetViewModel.cs index c9b69e6..598c279 100644 --- a/ViewModels/EvergreenWidgetViewModel.cs +++ b/ViewModels/EvergreenWidgetViewModel.cs @@ -1,4 +1,6 @@ +using System.Collections.ObjectModel; using Avalonia.Threading; +using ReactiveUI; using SupportCompanion.Interfaces; using SupportCompanion.Models; using SupportCompanion.Services; @@ -8,19 +10,28 @@ namespace SupportCompanion.ViewModels; public class EvergreenWidgetViewModel : ViewModelBase, IWindowStateAware { private readonly CatalogsService _catalogsService; - private List _catalogs = new(); + private readonly ObservableCollection _catalogs = new(); + + private EvergreenInfoModel? _evergreenInfo; public EvergreenWidgetViewModel(CatalogsService catalogs) { _catalogsService = catalogs; if (App.Config.MunkiMode) { - EvergreenInfo = new EvergreenInfoModel(); + EvergreenInfo = new EvergreenInfoModel + { + Catalogs = _catalogs + }; Dispatcher.UIThread.Post(InitializeAsync); } } - public EvergreenInfoModel? EvergreenInfo { get; private set; } + public EvergreenInfoModel? EvergreenInfo + { + get => _evergreenInfo; + private set => this.RaiseAndSetIfChanged(ref _evergreenInfo, value); + } public void OnWindowHidden() { @@ -31,7 +42,10 @@ public void OnWindowShown() { if (App.Config.MunkiMode) { - EvergreenInfo = new EvergreenInfoModel(); + EvergreenInfo = new EvergreenInfoModel + { + Catalogs = _catalogs + }; Dispatcher.UIThread.Post(InitializeAsync); } } @@ -43,9 +57,9 @@ private async void InitializeAsync() private async Task DeviceCatalogs() { - EvergreenInfo?.Catalogs?.Clear(); - _catalogs = await _catalogsService.GetCatalogs(); - EvergreenInfo.Catalogs = _catalogs; + _catalogs.Clear(); // Clear the collection before fetching new catalogs + var newCatalogs = await _catalogsService.GetCatalogs(); + foreach (var catalog in newCatalogs) _catalogs.Add(catalog); // Add new catalogs to the ObservableCollection } private void CleanUp() diff --git a/ViewModels/MacPasswordViewModel.cs b/ViewModels/MacPasswordViewModel.cs index 3187a3f..12f5687 100644 --- a/ViewModels/MacPasswordViewModel.cs +++ b/ViewModels/MacPasswordViewModel.cs @@ -1,5 +1,6 @@ using System.Text.Json; using Avalonia.Threading; +using ReactiveUI; using SupportCompanion.Interfaces; using SupportCompanion.Models; using SupportCompanion.Services; @@ -12,6 +13,9 @@ public class MacPasswordViewModel : ViewModelBase, IWindowStateAware private readonly LoggerService _logger; private readonly MacPasswordService _macPasswordService; + private KerberosSSOModel? _kerberosSSO; + private PlatformSSOModel? _platformSSO; + public MacPasswordViewModel(ActionsService actionsService, MacPasswordService macPasswordService, LoggerService loggerService) { @@ -23,8 +27,17 @@ public MacPasswordViewModel(ActionsService actionsService, MacPasswordService ma Dispatcher.UIThread.Post(InitializeAsync); } - public KerberosSSOModel? KerberosSSO { get; private set; } - public PlatformSSOModel? PlatformSSO { get; private set; } + public KerberosSSOModel? KerberosSSO + { + get => _kerberosSSO; + private set => this.RaiseAndSetIfChanged(ref _kerberosSSO, value); + } + + public PlatformSSOModel? PlatformSSO + { + get => _platformSSO; + private set => this.RaiseAndSetIfChanged(ref _platformSSO, value); + } public void OnWindowHidden() { diff --git a/ViewModels/MdmStatusViewModel.cs b/ViewModels/MdmStatusViewModel.cs index 28bc93d..ccd1511 100644 --- a/ViewModels/MdmStatusViewModel.cs +++ b/ViewModels/MdmStatusViewModel.cs @@ -1,4 +1,5 @@ using Avalonia.Threading; +using ReactiveUI; using SupportCompanion.Interfaces; using SupportCompanion.Models; using SupportCompanion.Services; @@ -11,6 +12,8 @@ public class MdmStatusViewModel : ViewModelBase, IWindowStateAware private bool _disposed; private Dictionary _mdmStatus = new(); + private MdmStatusModel? _mdmStatusInfo; + public MdmStatusViewModel(MdmStatusService mdmStatus) { _mdmStatusService = mdmStatus; @@ -18,7 +21,11 @@ public MdmStatusViewModel(MdmStatusService mdmStatus) Dispatcher.UIThread.Post(InitializeAsync); } - public MdmStatusModel? MdmStatusInfo { get; private set; } + public MdmStatusModel? MdmStatusInfo + { + get => _mdmStatusInfo; + private set => this.RaiseAndSetIfChanged(ref _mdmStatusInfo, value); + } public void OnWindowHidden() { diff --git a/ViewModels/StorageViewModel.cs b/ViewModels/StorageViewModel.cs index 47bcdac..6dbe86d 100644 --- a/ViewModels/StorageViewModel.cs +++ b/ViewModels/StorageViewModel.cs @@ -1,4 +1,5 @@ using Avalonia.Threading; +using ReactiveUI; using SupportCompanion.Interfaces; using SupportCompanion.Models; using SupportCompanion.Services; @@ -9,6 +10,8 @@ public class StorageViewModel : ViewModelBase, IWindowStateAware { private readonly LoggerService _logger; private readonly StorageService _storage; + + private StorageModel? _storageInfo; private Timer? _timer; public StorageViewModel(StorageService storage, LoggerService loggerService) @@ -21,7 +24,12 @@ public StorageViewModel(StorageService storage, LoggerService loggerService) Dispatcher.UIThread.Post(InitializeAsync); } - public StorageModel? StorageInfo { get; private set; } + public StorageModel? StorageInfo + { + get => _storageInfo; + private set => this.RaiseAndSetIfChanged(ref _storageInfo, value); + } + public bool ShowManageStorageButton { get; private set; } public void OnWindowHidden() diff --git a/ViewModels/UserViewModel.cs b/ViewModels/UserViewModel.cs index 277e5b7..3e8fbe7 100644 --- a/ViewModels/UserViewModel.cs +++ b/ViewModels/UserViewModel.cs @@ -1,5 +1,6 @@ using System.Text.RegularExpressions; using Avalonia.Threading; +using ReactiveUI; using SupportCompanion.Interfaces; using SupportCompanion.Models; using SupportCompanion.Services; @@ -14,6 +15,8 @@ public class UserViewModel : ViewModelBase, IWindowStateAware private const string ShellPattern = @"Shell:\s+(\S+)"; private readonly ActionsService _actionsService; + private UserModel _user; + public UserViewModel(ActionsService actionsService) { User = new UserModel(); @@ -21,7 +24,11 @@ public UserViewModel(ActionsService actionsService) Dispatcher.UIThread.Post(InitializeAsync); } - public UserModel? User { get; private set; } + public UserModel? User + { + get => _user; + private set => this.RaiseAndSetIfChanged(ref _user, value); + } public void OnWindowHidden() { From 529774775e03c4727c3ab303071687bacdeebfe5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Alm=C3=A9n?= <78877636+almenscorner@users.noreply.github.com> Date: Fri, 24 May 2024 14:17:38 +0200 Subject: [PATCH 3/4] Set CFBundleVersion and CFBundleShortVersionString to automated build --- build.sh | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/build.sh b/build.sh index 2d23d5e..f236bfe 100755 --- a/build.sh +++ b/build.sh @@ -26,7 +26,7 @@ sudo xcode-select -s "$XCODE_PATH" # automate the build version bump AUTOMATED_SC_BUILD="$CURRENT_SC_MAIN_BUILD_VERSION.$NEWSUBBUILD" -echo "$VERSION" > "./build_info.txt" +echo "$AUTOMATED_SC_BUILD" > "./build_info.txt" echo "$CURRENT_SC_MAIN_BUILD_VERSION" > "./build_info_main.txt" # is dotnet installed? @@ -65,6 +65,11 @@ then rm -rf "$PUBLISH_OUTPUT_DIRECTORY" fi +if [ -d "$APP_SUPPORT_PATH/scripts" ] +then + rm -rf "$APP_SUPPORT_PATH/scripts" +fi + if [ -d "$BUILD_PATH/payload/Applications/Utilities/SupportCompanion.app/" ] then rm -rf "$BUILD_PATH/payload/Applications/Utilities/SupportCompanion.app/" @@ -82,6 +87,10 @@ cp "$SUKIUI_LICENSE_FILE" "$PUBLISH_OUTPUT_DIRECTORY/Contents/Resources/" chmod +x "$PUBLISH_OUTPUT_DIRECTORY/Contents/Resources/Uninstall.sh" cp -a "${PROJECT_PATH}/Assets/scripts" "${BUILD_PATH}/payload/Library/Application Support/SupportCompanion/" +# set the plist version to AUTOMATED_SC_BUILD +/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $AUTOMATED_SC_BUILD" "${PUBLISH_OUTPUT_APP}/Contents/Info.plist" +/usr/libexec/PlistBuddy -c "Set :CFBundleShortVersionString $AUTOMATED_SC_BUILD" "${PUBLISH_OUTPUT_APP}/Contents/Info.plist" + # mv each script file to remove the extension SCRIPT_FILES="$(ls "${APP_SUPPORT_PATH}/scripts/")" for SCRIPT_FILE in $SCRIPT_FILES @@ -113,7 +122,7 @@ find "${BUILD_PATH}/payload/Applications/Utilities/SupportCompanion.app/Contents "distribution_style": true, "version": "$AUTOMATED_SC_BUILD", "name": "SupportCompanion-$AUTOMATED_SC_BUILD.pkg", - "install_location": "/Applications/Utilities", + "install_location": "/", "signing_info": { "identity": "$INSTALLER_SIGNING_IDENTITY", "timestamp": true From 38bbfba2f3b0c331e24c441542a50df6032dfbd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Alm=C3=A9n?= <78877636+almenscorner@users.noreply.github.com> Date: Fri, 24 May 2024 14:17:56 +0200 Subject: [PATCH 4/4] Create build_dev.zsh --- build_dev.zsh | 86 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100755 build_dev.zsh diff --git a/build_dev.zsh b/build_dev.zsh new file mode 100755 index 0000000..3126b67 --- /dev/null +++ b/build_dev.zsh @@ -0,0 +1,86 @@ +#!/bin/zsh +PROJECT_PATH="." +BUILD_PATH="./Build" +APP_SUPPORT_PATH="${BUILD_PATH}/payload/Library/Application Support/SupportCompanion" +PUBLISH_OUTPUT_DIRECTORY="${PROJECT_PATH}/bin/Release/net8.0-macos/SupportCompanion.app" +PUBLISH_OUTPUT_APP="${PROJECT_PATH}/bin/Release/net8.0-macos/SupportCompanion.app" +ICON_FILE="${PROJECT_PATH}/Assets/appicon.icns" +SUKIUI_LICENSE_FILE="${PROJECT_PATH}/SUKIUI_LICENSE" +UNINSTALL_SCRIPT="${PROJECT_PATH}/Assets/Uninstall.sh" +VERSION=$(/usr/libexec/PlistBuddy -c "Print :CFBundleVersion" "${PROJECT_PATH}/Info.plist") +CURRENT_SC_MAIN_BUILD_VERSION=$VERSION +NEWSUBBUILD=$((80620 + $(git rev-parse HEAD~0 | xargs -I{} git rev-list --count {}))) + +# automate the build version bump +AUTOMATED_SC_BUILD="$CURRENT_SC_MAIN_BUILD_VERSION.$NEWSUBBUILD" + +echo "$AUTOMATED_SC_BUILD" > "./build_info.txt" +echo "$CURRENT_SC_MAIN_BUILD_VERSION" > "./build_info_main.txt" + +# is dotnet installed? +dotnet="$(dotnet --version)" + +if [ -z "$dotnet" ] +then + echo "dotnet is not installed" + exit 1 +fi + +if [ -d "$PUBLISH_OUTPUT_DIRECTORY" ] +then + rm -rf "$PUBLISH_OUTPUT_DIRECTORY" +fi + +if [ -d "$APP_SUPPORT_PATH/scripts" ] +then + rm -rf "$APP_SUPPORT_PATH/scripts" +fi + +if [ -d "$BUILD_PATH/payload/Applications/Utilities/SupportCompanion.app/" ] +then + rm -rf "$BUILD_PATH/payload/Applications/Utilities/SupportCompanion.app/" +fi + +dotnet publish --configuration Release -p:UseAppHost=true + +# Create the Applications directory and utilities directory +mkdir -p "${BUILD_PATH}/payload/Applications/Utilities" + +rm -f "$PUBLISH_OUTPUT_DIRECTORY/Contents/Resources/suki_photo.ico" +cp "$ICON_FILE" "$PUBLISH_OUTPUT_DIRECTORY/Contents/Resources/" +cp "$UNINSTALL_SCRIPT" "$PUBLISH_OUTPUT_DIRECTORY/Contents/Resources/" +cp "$SUKIUI_LICENSE_FILE" "$PUBLISH_OUTPUT_DIRECTORY/Contents/Resources/" +chmod +x "$PUBLISH_OUTPUT_DIRECTORY/Contents/Resources/Uninstall.sh" +cp -a "${PROJECT_PATH}/Assets/scripts" "${BUILD_PATH}/payload/Library/Application Support/SupportCompanion/" + +# set the plist version to AUTOMATED_SC_BUILD +/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $AUTOMATED_SC_BUILD" "${PUBLISH_OUTPUT_APP}/Contents/Info.plist" +/usr/libexec/PlistBuddy -c "Set :CFBundleShortVersionString $AUTOMATED_SC_BUILD" "${PUBLISH_OUTPUT_APP}/Contents/Info.plist" + +# mv each script file to remove the extension +SCRIPT_FILES="$(ls "${APP_SUPPORT_PATH}/scripts/")" +for SCRIPT_FILE in $SCRIPT_FILES +do + FILE_WITHOUT_EXT=$(basename "$SCRIPT_FILE" .py) + mv "$APP_SUPPORT_PATH/scripts/$SCRIPT_FILE" "$APP_SUPPORT_PATH/scripts/$FILE_WITHOUT_EXT" + chmod +x "$APP_SUPPORT_PATH/scripts/$FILE_WITHOUT_EXT" +done + +cp -a "$PUBLISH_OUTPUT_APP" "${BUILD_PATH}/payload/Applications/Utilities/" + +# Create the json file for munkipkg Support Companion pkg +/bin/cat << SIGNED_JSONFILE > "$BUILD_PATH/build-info.json" +{ + "ownership": "recommended", + "suppress_bundle_relocation": true, + "identifier": "com.almenscorner.supportcompanion", + "postinstall_action": "none", + "distribution_style": true, + "version": "$AUTOMATED_SC_BUILD", + "name": "SupportCompanion-$AUTOMATED_SC_BUILD.pkg", + "install_location": "/" +} +SIGNED_JSONFILE + +# Create the signed pkg +munkipkg "$BUILD_PATH" \ No newline at end of file