Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Final code drop from ADO #25

Merged
merged 1 commit into from
Mar 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 19 additions & 19 deletions DevHome.sln
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DevHome.SetupFlow.AppManage
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DevHome.SetupFlow.Common", "tools\SetupFlow\DevHome.SetupFlow.Common\DevHome.SetupFlow.Common.csproj", "{B7312416-3E61-440F-B17E-A9D10DA29E3F}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DevHome.SetupFlow.DevVolume", "tools\SetupFlow\DevHome.SetupFlow.DevVolume\DevHome.SetupFlow.DevVolume.csproj", "{CB65FC14-ACC3-49DD-B804-FA4C80BFF1B4}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DevHome.SetupFlow.Loading", "tools\SetupFlow\DevHome.SetupFlow.Loading\DevHome.SetupFlow.Loading.csproj", "{027F1F3B-A1F4-4508-BCA5-B222F12A2D42}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DevHome.SetupFlow.MainPage", "tools\SetupFlow\DevHome.SetupFlow.MainPage\DevHome.SetupFlow.MainPage.csproj", "{4B979440-E731-42B7-AA7C-A8BAF98789CF}"
Expand Down Expand Up @@ -71,6 +69,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DevHome.SetupFlow.UnitTest"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DevHome.SetupFlow.ConfigurationFile", "tools\SetupFlow\DevHome.SetupFlow.ConfigurationFlow\DevHome.SetupFlow.ConfigurationFile.csproj", "{AA13E2A1-7F04-419C-9E53-9E8CD45487A7}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DevHome.SetupFlow.DevDrive", "tools\SetupFlow\DevHome.SetupFlow.DevDrive\DevHome.SetupFlow.DevDrive.csproj", "{88E889AD-4F51-4312-8E16-5B81FA6BB1FD}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -267,22 +267,6 @@ Global
{B7312416-3E61-440F-B17E-A9D10DA29E3F}.Release|x64.Build.0 = Release|x64
{B7312416-3E61-440F-B17E-A9D10DA29E3F}.Release|x86.ActiveCfg = Release|x86
{B7312416-3E61-440F-B17E-A9D10DA29E3F}.Release|x86.Build.0 = Release|x86
{CB65FC14-ACC3-49DD-B804-FA4C80BFF1B4}.Debug|Any CPU.ActiveCfg = Debug|x64
{CB65FC14-ACC3-49DD-B804-FA4C80BFF1B4}.Debug|Any CPU.Build.0 = Debug|x64
{CB65FC14-ACC3-49DD-B804-FA4C80BFF1B4}.Debug|arm64.ActiveCfg = Debug|ARM64
{CB65FC14-ACC3-49DD-B804-FA4C80BFF1B4}.Debug|arm64.Build.0 = Debug|ARM64
{CB65FC14-ACC3-49DD-B804-FA4C80BFF1B4}.Debug|x64.ActiveCfg = Debug|x64
{CB65FC14-ACC3-49DD-B804-FA4C80BFF1B4}.Debug|x64.Build.0 = Debug|x64
{CB65FC14-ACC3-49DD-B804-FA4C80BFF1B4}.Debug|x86.ActiveCfg = Debug|x86
{CB65FC14-ACC3-49DD-B804-FA4C80BFF1B4}.Debug|x86.Build.0 = Debug|x86
{CB65FC14-ACC3-49DD-B804-FA4C80BFF1B4}.Release|Any CPU.ActiveCfg = Release|x64
{CB65FC14-ACC3-49DD-B804-FA4C80BFF1B4}.Release|Any CPU.Build.0 = Release|x64
{CB65FC14-ACC3-49DD-B804-FA4C80BFF1B4}.Release|arm64.ActiveCfg = Release|ARM64
{CB65FC14-ACC3-49DD-B804-FA4C80BFF1B4}.Release|arm64.Build.0 = Release|ARM64
{CB65FC14-ACC3-49DD-B804-FA4C80BFF1B4}.Release|x64.ActiveCfg = Release|x64
{CB65FC14-ACC3-49DD-B804-FA4C80BFF1B4}.Release|x64.Build.0 = Release|x64
{CB65FC14-ACC3-49DD-B804-FA4C80BFF1B4}.Release|x86.ActiveCfg = Release|x86
{CB65FC14-ACC3-49DD-B804-FA4C80BFF1B4}.Release|x86.Build.0 = Release|x86
{027F1F3B-A1F4-4508-BCA5-B222F12A2D42}.Debug|Any CPU.ActiveCfg = Debug|x64
{027F1F3B-A1F4-4508-BCA5-B222F12A2D42}.Debug|Any CPU.Build.0 = Debug|x64
{027F1F3B-A1F4-4508-BCA5-B222F12A2D42}.Debug|arm64.ActiveCfg = Debug|arm64
Expand Down Expand Up @@ -475,6 +459,22 @@ Global
{AA13E2A1-7F04-419C-9E53-9E8CD45487A7}.Release|x64.Build.0 = Release|x64
{AA13E2A1-7F04-419C-9E53-9E8CD45487A7}.Release|x86.ActiveCfg = Release|x86
{AA13E2A1-7F04-419C-9E53-9E8CD45487A7}.Release|x86.Build.0 = Release|x86
{88E889AD-4F51-4312-8E16-5B81FA6BB1FD}.Debug|Any CPU.ActiveCfg = Debug|x64
{88E889AD-4F51-4312-8E16-5B81FA6BB1FD}.Debug|Any CPU.Build.0 = Debug|x64
{88E889AD-4F51-4312-8E16-5B81FA6BB1FD}.Debug|arm64.ActiveCfg = Debug|arm64
{88E889AD-4F51-4312-8E16-5B81FA6BB1FD}.Debug|arm64.Build.0 = Debug|arm64
{88E889AD-4F51-4312-8E16-5B81FA6BB1FD}.Debug|x64.ActiveCfg = Debug|x64
{88E889AD-4F51-4312-8E16-5B81FA6BB1FD}.Debug|x64.Build.0 = Debug|x64
{88E889AD-4F51-4312-8E16-5B81FA6BB1FD}.Debug|x86.ActiveCfg = Debug|x86
{88E889AD-4F51-4312-8E16-5B81FA6BB1FD}.Debug|x86.Build.0 = Debug|x86
{88E889AD-4F51-4312-8E16-5B81FA6BB1FD}.Release|Any CPU.ActiveCfg = Release|x64
{88E889AD-4F51-4312-8E16-5B81FA6BB1FD}.Release|Any CPU.Build.0 = Release|x64
{88E889AD-4F51-4312-8E16-5B81FA6BB1FD}.Release|arm64.ActiveCfg = Release|arm64
{88E889AD-4F51-4312-8E16-5B81FA6BB1FD}.Release|arm64.Build.0 = Release|arm64
{88E889AD-4F51-4312-8E16-5B81FA6BB1FD}.Release|x64.ActiveCfg = Release|x64
{88E889AD-4F51-4312-8E16-5B81FA6BB1FD}.Release|x64.Build.0 = Release|x64
{88E889AD-4F51-4312-8E16-5B81FA6BB1FD}.Release|x86.ActiveCfg = Release|x86
{88E889AD-4F51-4312-8E16-5B81FA6BB1FD}.Release|x86.Build.0 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -486,7 +486,6 @@ Global
{60CAE3AD-C786-47B0-820C-65CA47492FFA} = {4179A05E-37F1-46CD-9218-0889EA2BB75B}
{5613EF29-63F6-4487-91C0-95F07CC37413} = {4179A05E-37F1-46CD-9218-0889EA2BB75B}
{B7312416-3E61-440F-B17E-A9D10DA29E3F} = {4179A05E-37F1-46CD-9218-0889EA2BB75B}
{CB65FC14-ACC3-49DD-B804-FA4C80BFF1B4} = {4179A05E-37F1-46CD-9218-0889EA2BB75B}
{027F1F3B-A1F4-4508-BCA5-B222F12A2D42} = {4179A05E-37F1-46CD-9218-0889EA2BB75B}
{4B979440-E731-42B7-AA7C-A8BAF98789CF} = {4179A05E-37F1-46CD-9218-0889EA2BB75B}
{14D351F0-3F40-48A8-9887-F317A37C422E} = {4179A05E-37F1-46CD-9218-0889EA2BB75B}
Expand All @@ -501,6 +500,7 @@ Global
{C5184A1B-6C10-4346-AE64-87D2157F99D2} = {222B92B1-AC7A-409D-957B-A3851D3F41B0}
{6254ADB1-B6FD-4D74-AF13-40C997919178} = {222B92B1-AC7A-409D-957B-A3851D3F41B0}
{AA13E2A1-7F04-419C-9E53-9E8CD45487A7} = {4179A05E-37F1-46CD-9218-0889EA2BB75B}
{88E889AD-4F51-4312-8E16-5B81FA6BB1FD} = {4179A05E-37F1-46CD-9218-0889EA2BB75B}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {030B5641-B206-46BB-BF71-36FF009088FA}
Expand Down
1 change: 1 addition & 0 deletions src/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public App()

// Views and ViewModels
services.AddTransient<SettingsViewModel>();
services.AddTransient<AccountsPageViewModel>();
services.AddTransient<SettingsPage>();
services.AddTransient<FeedbackViewModel>();
services.AddTransient<FeedbackPage>();
Expand Down
23 changes: 23 additions & 0 deletions src/ViewModels/AccountViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright (c) Microsoft Corporation and Contributors
// Licensed under the MIT license.

using System;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using Microsoft.Windows.DevHome.SDK;

namespace DevHome.ViewModels;

public partial class AccountViewModel : ObservableObject
{
private readonly IDeveloperId _devId;

internal IDeveloperId GetDevId() => _devId;

public AccountViewModel(IDeveloperId devId)
{
_devId = devId;
}

public string LoginId => _devId.LoginId();
}
88 changes: 88 additions & 0 deletions src/ViewModels/AccountsPageViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
// Copyright (c) Microsoft Corporation and Contributors
// Licensed under the MIT license.

using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Runtime.InteropServices;
using Microsoft.Windows.DevHome.SDK;

namespace DevHome.ViewModels;

public class AccountsPageViewModel
{
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool SetForegroundWindow(IntPtr hWnd);

private readonly IDevIdProvider? iDevIdProvider;

public ObservableCollection<AccountViewModel> LoggedInAccounts { get; } = new ();

public AccountsPageViewModel()
{
// Currently, we assume that there is only one extension
var pluginService = new DevHome.Services.PluginService();
var plugins = pluginService.GetInstalledPluginsAsync().Result;
var plugin = plugins.FirstOrDefault();
if (plugin is null)
{
// Nothing to do if there are no plugins
return;
}

if (!plugin.IsRunning())
{
_ = plugin.StartPlugin();
}

SpinWait.SpinUntil(() => plugin.IsRunning());

if (plugin.IsRunning())
{
var pluginObj = plugin?.GetPluginObject();
var devIdProvider = pluginObj?.GetProvider(ProviderType.DevId);
if (devIdProvider is null)
{
return;
}

iDevIdProvider = devIdProvider as IDevIdProvider;
if (iDevIdProvider is null)
{
return;
}
}

// Currently, we assume there is only 1 DeveloperId
var devId = iDevIdProvider?.GetLoggedInDeveloperIds()?.FirstOrDefault();
if (devId is null)
{
return;
}

LoggedInAccounts.Add(new AccountViewModel(devId));
}

public async void AddAccount()
{
// Currently, we directly open the browser rather than the AdaptiveCard flyout
var newDeveloperId = await Task.Run(async () =>
{
return await iDevIdProvider?.LoginNewDeveloperIdAsync();
});
LoggedInAccounts.Add(new AccountViewModel(newDeveloperId));

// Bring focus back to DevHome after login
SetForegroundWindow(Process.GetCurrentProcess().MainWindowHandle);
}

public void RemoveAccount(string loginId)
{
var accountToRemove = LoggedInAccounts?.FirstOrDefault(x => x.LoginId == loginId);
if (accountToRemove != null)
{
Task.Run(() => iDevIdProvider?.LogoutDeveloperId(accountToRemove.GetDevId()));
LoggedInAccounts?.Remove(accountToRemove);
}
}
}
151 changes: 106 additions & 45 deletions src/Views/SettingsPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,62 +5,123 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:helpers="using:DevHome.Helpers"
xmlns:xaml="using:Microsoft.UI.Xaml"
xmlns:xaml="using:Microsoft.UI.Xaml"
xmlns:viewmodels="using:DevHome.ViewModels"
mc:Ignorable="d">
<Page.Resources>
<helpers:EnumToBooleanConverter x:Key="EnumToBooleanConverter" />
<Style x:Key="AccountsExpander" TargetType="Expander">
<Setter Property="IsExpanded" Value="False"/>
<Setter Property="VerticalAlignment" Value="Bottom"/>
<Setter Property="HorizontalAlignment" Value="Stretch"/>
</Style>

<DataTemplate x:Key="AccountsViewTemplate" x:DataType="viewmodels:AccountViewModel">
<StackPanel>
<StackPanel>
<TextBlock Text="GitHub" Style="{ThemeResource SubtitleTextBlockStyle}" Margin="{StaticResource XSmallTopMargin}"/>
</StackPanel>
<StackPanel Margin="{StaticResource XSmallTopMargin}">
<Expander Style="{StaticResource AccountsExpander}" HorizontalAlignment="Stretch" VerticalAlignment="Bottom" IsExpanded="False">
<Expander.Header>
<RelativePanel Margin="{StaticResource XSmallLeftTopRightBottomMargin}">
<StackPanel Margin="{StaticResource XSmallTopMargin}">
</StackPanel>
<StackPanel>
<TextBlock Text="{x:Bind LoginId}" Style="{ThemeResource BodyTextStyle}" HorizontalAlignment="Left"/>
</StackPanel>
<StackPanel RelativePanel.AlignRightWithPanel="True">
<Button Tag="{x:Bind LoginId}" Content="Logout" HorizontalAlignment="Right" Click="Logout_Click"/>
</StackPanel>
</RelativePanel>
</Expander.Header>
</Expander>
</StackPanel>
</StackPanel>
</DataTemplate>
</Page.Resources>
<Grid>
<StackPanel
x:Name="ContentArea">
<TextBlock x:Uid="Settings_Personalization" Style="{ThemeResource SubtitleTextBlockStyle}" />
<StackPanel Margin="{StaticResource SmallTopBottomMargin}">
<TextBlock x:Uid="Settings_Theme" />
<StackPanel x:Name="MainStackPanel">
<!-- TODO: The following is to be in the Accounts page when it is set up -->
<StackPanel x:Name="AccountsContentArea">
<StackPanel x:Name="AccountsTitleStackPanel" Margin="{StaticResource XSmallTopMargin}">
<TextBlock Text="Accounts" Style="{ThemeResource TitleTextBlockStyle}" />
</StackPanel>

<StackPanel Margin="{StaticResource XSmallTopMargin}">
<RadioButton
x:Uid="Settings_Theme_Light"
Command="{x:Bind ViewModel.SwitchThemeCommand}"
IsChecked="{x:Bind ViewModel.ElementTheme, Converter={StaticResource EnumToBooleanConverter}, ConverterParameter=Light, Mode=OneWay}"
FontSize="15"
GroupName="AppTheme">
<RadioButton.CommandParameter>
<xaml:ElementTheme>Light</xaml:ElementTheme>
</RadioButton.CommandParameter>
</RadioButton>
<RadioButton
x:Uid="Settings_Theme_Dark"
Command="{x:Bind ViewModel.SwitchThemeCommand}"
IsChecked="{x:Bind ViewModel.ElementTheme, Converter={StaticResource EnumToBooleanConverter}, ConverterParameter=Dark, Mode=OneWay}"
FontSize="15"
GroupName="AppTheme">
<RadioButton.CommandParameter>
<xaml:ElementTheme>Dark</xaml:ElementTheme>
</RadioButton.CommandParameter>
</RadioButton>
<RadioButton
x:Uid="Settings_Theme_Default"
Command="{x:Bind ViewModel.SwitchThemeCommand}"
IsChecked="{x:Bind ViewModel.ElementTheme, Converter={StaticResource EnumToBooleanConverter}, ConverterParameter=Default, Mode=OneWay}"
FontSize="15"
GroupName="AppTheme">
<RadioButton.CommandParameter>
<xaml:ElementTheme>Default</xaml:ElementTheme>
</RadioButton.CommandParameter>
</RadioButton>
<StackPanel x:Name="AddAccountMainStackPanel" Margin="{StaticResource XSmallTopMargin}">
<Expander Style="{StaticResource AccountsExpander}">
<Expander.Header>
<RelativePanel Margin="{StaticResource XSmallLeftTopRightBottomMargin}">
<StackPanel>
<TextBlock Text="Add account" Style="{ThemeResource BodyTextStyle}" HorizontalAlignment="Left"/>
</StackPanel>
<StackPanel RelativePanel.AlignRightWithPanel="True">
<Button Content ="Add account" HorizontalAlignment="Right" Click="AddDeveloperId_Click"/>
</StackPanel>
</RelativePanel>
</Expander.Header>
</Expander>
</StackPanel>

<StackPanel>
<ItemsRepeater ItemsSource="{x:Bind AccountsViewModel.LoggedInAccounts}" ItemTemplate="{StaticResource AccountsViewTemplate}"
HorizontalAlignment="Stretch" VerticalAlignment="Center" Visibility="Visible">
</ItemsRepeater>
</StackPanel>
</StackPanel>
<StackPanel>
</StackPanel>
<StackPanel
x:Name="ContentArea">
<TextBlock x:Uid="Settings_Personalization" Style="{ThemeResource TitleTextBlockStyle}" />
<StackPanel Margin="{StaticResource SmallTopBottomMargin}">
<TextBlock x:Uid="Settings_Theme" />

<TextBlock x:Uid="Settings_About" Style="{ThemeResource SubtitleTextBlockStyle}" />
<StackPanel Margin="{StaticResource XSmallTopMargin}">
<RadioButton
x:Uid="Settings_Theme_Light"
Command="{x:Bind ViewModel.SwitchThemeCommand}"
IsChecked="{x:Bind ViewModel.ElementTheme, Converter={StaticResource EnumToBooleanConverter}, ConverterParameter=Light, Mode=OneWay}"
FontSize="15"
GroupName="AppTheme">
<RadioButton.CommandParameter>
<xaml:ElementTheme>Light</xaml:ElementTheme>
</RadioButton.CommandParameter>
</RadioButton>
<RadioButton
x:Uid="Settings_Theme_Dark"
Command="{x:Bind ViewModel.SwitchThemeCommand}"
IsChecked="{x:Bind ViewModel.ElementTheme, Converter={StaticResource EnumToBooleanConverter}, ConverterParameter=Dark, Mode=OneWay}"
FontSize="15"
GroupName="AppTheme">
<RadioButton.CommandParameter>
<xaml:ElementTheme>Dark</xaml:ElementTheme>
</RadioButton.CommandParameter>
</RadioButton>
<RadioButton
x:Uid="Settings_Theme_Default"
Command="{x:Bind ViewModel.SwitchThemeCommand}"
IsChecked="{x:Bind ViewModel.ElementTheme, Converter={StaticResource EnumToBooleanConverter}, ConverterParameter=Default, Mode=OneWay}"
FontSize="15"
GroupName="AppTheme">
<RadioButton.CommandParameter>
<xaml:ElementTheme>Default</xaml:ElementTheme>
</RadioButton.CommandParameter>
</RadioButton>
</StackPanel>
</StackPanel>

<StackPanel Margin="{StaticResource XSmallTopMargin}">
<TextBlock Text="{x:Bind ViewModel.VersionDescription, Mode=OneWay}" Style="{ThemeResource BodyTextBlockStyle}" />
<TextBlock x:Uid="Settings_About" Style="{ThemeResource TitleTextBlockStyle}" />

<TextBlock
x:Uid="Settings_AboutDescription"
Margin="{StaticResource XSmallTopMargin}"
Style="{ThemeResource BodyTextBlockStyle}" />
<HyperlinkButton x:Uid="SettingsPage_PrivacyTermsLink" Margin="{StaticResource SettingsPageHyperlinkButtonMargin}" />
<StackPanel Margin="{StaticResource XSmallTopMargin}">
<TextBlock Text="{x:Bind ViewModel.VersionDescription, Mode=OneWay}" Style="{ThemeResource BodyTextBlockStyle}" />

<TextBlock
x:Uid="Settings_AboutDescription"
Margin="{StaticResource XSmallTopMargin}"
Style="{ThemeResource BodyTextBlockStyle}" />
<HyperlinkButton x:Uid="SettingsPage_PrivacyTermsLink" Margin="{StaticResource SettingsPageHyperlinkButtonMargin}" />
</StackPanel>
</StackPanel>
</StackPanel>
</Grid>
Expand Down
Loading