Skip to content

Commit

Permalink
Merge pull request #17 from macadmins/dev
Browse files Browse the repository at this point in the history
Fix data refresh on show window
  • Loading branch information
almenscorner authored May 24, 2024
2 parents ccc68ba + 38bbfba commit a8ecb3f
Show file tree
Hide file tree
Showing 11 changed files with 172 additions and 19 deletions.
2 changes: 1 addition & 1 deletion Models/DeviceInfoModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion Models/EvergreenInfoModel.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
using System.Collections.ObjectModel;
using CommunityToolkit.Mvvm.ComponentModel;

namespace SupportCompanion.Models;

public partial class EvergreenInfoModel : ObservableObject
{
[ObservableProperty] private List<string>? _catalogs = new();
[ObservableProperty] private ObservableCollection<string> _catalogs = new();
}
4 changes: 2 additions & 2 deletions Models/StorageModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
10 changes: 9 additions & 1 deletion ViewModels/DeviceWidgetViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Avalonia.Threading;
using ReactiveUI;
using SukiUI.Controls;
using SupportCompanion.Helpers;
using SupportCompanion.Interfaces;
Expand All @@ -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)
{
Expand All @@ -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 =>
Expand Down
28 changes: 21 additions & 7 deletions ViewModels/EvergreenWidgetViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System.Collections.ObjectModel;
using Avalonia.Threading;
using ReactiveUI;
using SupportCompanion.Interfaces;
using SupportCompanion.Models;
using SupportCompanion.Services;
Expand All @@ -8,19 +10,28 @@ namespace SupportCompanion.ViewModels;
public class EvergreenWidgetViewModel : ViewModelBase, IWindowStateAware
{
private readonly CatalogsService _catalogsService;
private List<string> _catalogs = new();
private readonly ObservableCollection<string> _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()
{
Expand All @@ -31,7 +42,10 @@ public void OnWindowShown()
{
if (App.Config.MunkiMode)
{
EvergreenInfo = new EvergreenInfoModel();
EvergreenInfo = new EvergreenInfoModel
{
Catalogs = _catalogs
};
Dispatcher.UIThread.Post(InitializeAsync);
}
}
Expand All @@ -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()
Expand Down
17 changes: 15 additions & 2 deletions ViewModels/MacPasswordViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Text.Json;
using Avalonia.Threading;
using ReactiveUI;
using SupportCompanion.Interfaces;
using SupportCompanion.Models;
using SupportCompanion.Services;
Expand All @@ -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)
{
Expand All @@ -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()
{
Expand Down
9 changes: 8 additions & 1 deletion ViewModels/MdmStatusViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Avalonia.Threading;
using ReactiveUI;
using SupportCompanion.Interfaces;
using SupportCompanion.Models;
using SupportCompanion.Services;
Expand All @@ -11,14 +12,20 @@ public class MdmStatusViewModel : ViewModelBase, IWindowStateAware
private bool _disposed;
private Dictionary<string, string> _mdmStatus = new();

private MdmStatusModel? _mdmStatusInfo;

public MdmStatusViewModel(MdmStatusService mdmStatus)
{
_mdmStatusService = mdmStatus;
MdmStatusInfo = new MdmStatusModel();
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()
{
Expand Down
10 changes: 9 additions & 1 deletion ViewModels/StorageViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Avalonia.Threading;
using ReactiveUI;
using SupportCompanion.Interfaces;
using SupportCompanion.Models;
using SupportCompanion.Services;
Expand All @@ -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)
Expand All @@ -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()
Expand Down
9 changes: 8 additions & 1 deletion ViewModels/UserViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Text.RegularExpressions;
using Avalonia.Threading;
using ReactiveUI;
using SupportCompanion.Interfaces;
using SupportCompanion.Models;
using SupportCompanion.Services;
Expand All @@ -14,14 +15,20 @@ 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();
_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()
{
Expand Down
13 changes: 11 additions & 2 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down Expand Up @@ -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/"
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
86 changes: 86 additions & 0 deletions build_dev.zsh
Original file line number Diff line number Diff line change
@@ -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"

0 comments on commit a8ecb3f

Please sign in to comment.