Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit6e80e71

Browse files
committed
feat: Sign in Window views & view models
1 parent4c6d2bd commit6e80e71

12 files changed

+404
-16
lines changed

‎App/App.csproj

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,24 @@
4141
<PackageReferenceInclude="Microsoft.WindowsAppSDK"Version="1.6.250108002" />
4242
</ItemGroup>
4343

44+
<ItemGroup>
45+
<PageUpdate="SignInTokenPage.xaml">
46+
<Generator>MSBuild:Compile</Generator>
47+
</Page>
48+
</ItemGroup>
49+
50+
<ItemGroup>
51+
<PageUpdate="SignInWindow.xaml">
52+
<Generator>MSBuild:Compile</Generator>
53+
</Page>
54+
</ItemGroup>
55+
56+
<ItemGroup>
57+
<PageUpdate="SignInURLPage.xaml">
58+
<Generator>MSBuild:Compile</Generator>
59+
</Page>
60+
</ItemGroup>
61+
4462
<ItemGroup>
4563
<PageUpdate="TrayIcon.xaml">
4664
<Generator>MSBuild:Compile</Generator>

‎App/App.xaml.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,24 @@
1+
usingCoder.Desktop.App.ViewModels;
12
usingMicrosoft.UI.Xaml;
23

34
namespaceCoder.Desktop.App;
45

56
publicpartialclassApp:Application
67
{
78
privateTrayWindow?TrayWindow;
9+
publicSignInViewModelSignInViewModel{get;}
810

911
publicApp()
1012
{
13+
SignInViewModel=newSignInViewModel();
1114
InitializeComponent();
1215
}
1316

1417
privateboolHandleClosedEvents{get;}=true;
1518

1619
protectedoverridevoidOnLaunched(LaunchActivatedEventArgsargs)
1720
{
18-
TrayWindow=newTrayWindow();
21+
TrayWindow=newTrayWindow(SignInViewModel);
1922
TrayWindow.Closed+=(sender,args)=>
2023
{
2124
// TODO: wire up HandleClosedEvents properly

‎App/DisplayScale.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
usingSystem;
2+
usingMicrosoft.UI.Xaml;
3+
usingWinRT.Interop;
4+
usingSystem.Runtime.InteropServices;
5+
6+
namespaceCoder.Desktop.App;
7+
8+
/// <summary>
9+
/// A static utility class to house methods related to the visual scale of the display monitor.
10+
/// </summary>
11+
publicstaticclassDisplayScale
12+
{
13+
publicstaticdoubleWindowScale(Windowwin)
14+
{
15+
varhwnd=WindowNative.GetWindowHandle(win);
16+
vardpi=NativeApi.GetDpiForWindow(hwnd);
17+
if(dpi==0)return1;// assume scale of 1
18+
returndpi/96.0;// 96 DPI == 1
19+
}
20+
21+
publicclassNativeApi
22+
{
23+
[DllImport("user32.dll")]
24+
publicstaticexternintGetDpiForWindow(IntPtrhwnd);
25+
}
26+
}

‎App/SignInTokenPage.xaml

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Page
3+
x:Class="Coder.Desktop.App.SignInTokenPage"
4+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
5+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
6+
xmlns:local="using:Coder.Desktop.App"
7+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
8+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
9+
mc:Ignorable="d"
10+
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
11+
12+
<StackPanel
13+
Orientation="Vertical"
14+
HorizontalAlignment="Stretch"
15+
VerticalAlignment="Top"
16+
Padding="20"
17+
Spacing="10">
18+
19+
<TextBlock
20+
Text="Coder Desktop"
21+
FontSize="24"
22+
VerticalAlignment="Center"
23+
HorizontalAlignment="Center"/>
24+
25+
<Grid>
26+
<Grid.ColumnDefinitions>
27+
<ColumnDefinitionWidth="Auto" />
28+
<ColumnDefinitionWidth="*" />
29+
</Grid.ColumnDefinitions>
30+
<Grid.RowDefinitions>
31+
<RowDefinitionHeight="1*" />
32+
<RowDefinitionHeight="1*" />
33+
<RowDefinitionHeight="1*" />
34+
</Grid.RowDefinitions>
35+
36+
<TextBlock
37+
Grid.Column="0"
38+
Grid.Row="0"
39+
Text="Server URL"
40+
HorizontalAlignment="Right"
41+
Padding="10"/>
42+
43+
<TextBlock
44+
Grid.Column="1"
45+
Grid.Row="0"
46+
HorizontalAlignment="Stretch"
47+
VerticalAlignment="Center"
48+
Padding="10"
49+
Text="{x:Bind Path=ViewModel.Url, Mode=OneTime}"
50+
/>
51+
52+
<TextBlock
53+
Grid.Column="0"
54+
Grid.Row="1"
55+
Text="Session Token"
56+
HorizontalAlignment="Right"
57+
Padding="10"/>
58+
59+
<TextBox
60+
Grid.Column="1"
61+
Grid.Row="1"
62+
HorizontalAlignment="Stretch"
63+
PlaceholderText="paste your token here"
64+
Text="{x:Bind Path=ViewModel.CoderToken, Mode=TwoWay}"
65+
/>
66+
67+
<HyperlinkButton
68+
Grid.Column="1"
69+
Grid.Row="2"
70+
Content="Generate a token via the Web UI"
71+
NavigateUri="{x:Bind ViewModel.GenTokenURL, Mode=OneTime}" />
72+
73+
</Grid>
74+
75+
<StackPanel
76+
Orientation="Horizontal"
77+
HorizontalAlignment="Center"
78+
Spacing="10">
79+
<ButtonContent="Back"HorizontalAlignment="Right"
80+
Click="{x:Bind SignInWindow.NavigateToURLPage}"/>
81+
<ButtonContent="Sign In"HorizontalAlignment="Left"Style="{StaticResource AccentButtonStyle}"
82+
Click="{x:Bind ViewModel.SignIn_Click}"/>
83+
</StackPanel>
84+
85+
<TextBlock
86+
Text="{x:Bind ViewModel.LoginError, Mode=OneWay}"
87+
HorizontalAlignment="Center"
88+
Foreground="Red"
89+
/>
90+
91+
92+
</StackPanel>
93+
</Page>

‎App/SignInTokenPage.xaml.cs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
usingSystem;
2+
usingSystem.Collections.Generic;
3+
usingSystem.IO;
4+
usingSystem.Linq;
5+
usingSystem.Runtime.InteropServices.WindowsRuntime;
6+
usingCoder.Desktop.App.ViewModels;
7+
usingMicrosoft.UI.Xaml;
8+
usingMicrosoft.UI.Xaml.Controls;
9+
usingMicrosoft.UI.Xaml.Controls.Primitives;
10+
usingMicrosoft.UI.Xaml.Data;
11+
usingMicrosoft.UI.Xaml.Input;
12+
usingMicrosoft.UI.Xaml.Media;
13+
usingMicrosoft.UI.Xaml.Navigation;
14+
usingWindows.Foundation;
15+
usingWindows.Foundation.Collections;
16+
17+
// To learn more about WinUI, the WinUI project structure,
18+
// and more about our project templates, see: http://aka.ms/winui-project-info.
19+
20+
namespaceCoder.Desktop.App
21+
{
22+
/// <summary>
23+
/// An empty page that can be used on its own or navigated to within a Frame.
24+
/// </summary>
25+
publicsealedpartialclassSignInTokenPage:Page
26+
{
27+
publicSignInTokenPage(SignInWindowparent,SignInViewModelviewModel)
28+
{
29+
InitializeComponent();
30+
ViewModel=viewModel;
31+
SignInWindow=parent;
32+
}
33+
34+
publicreadonlySignInViewModelViewModel;
35+
publicreadonlySignInWindowSignInWindow;
36+
}
37+
}

‎App/SignInURLPage.xaml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Page
3+
x:Class="Coder.Desktop.App.SignInURLPage"
4+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
5+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
6+
xmlns:local="using:Coder.Desktop.App"
7+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
8+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
9+
mc:Ignorable="d"
10+
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
11+
12+
<StackPanel
13+
Orientation="Vertical"
14+
HorizontalAlignment="Stretch"
15+
VerticalAlignment="Top"
16+
Padding="20"
17+
Spacing="10">
18+
19+
<TextBlock
20+
Text="Coder Desktop"
21+
FontSize="24"
22+
VerticalAlignment="Center"
23+
HorizontalAlignment="Center"/>
24+
25+
<Grid>
26+
<Grid.ColumnDefinitions>
27+
<ColumnDefinitionWidth="Auto" />
28+
<ColumnDefinitionWidth="*" />
29+
</Grid.ColumnDefinitions>
30+
<TextBlock
31+
Grid.Column="0"
32+
Text="Server URL"
33+
HorizontalAlignment="Right"
34+
Padding="10"/>
35+
36+
<TextBox
37+
Name="URLTextBox"
38+
Grid.Column="1"
39+
HorizontalAlignment="Stretch"
40+
PlaceholderText="https://coder.example.com"
41+
Text="{x:Bind Path=ViewModel.Url, Mode=TwoWay}"
42+
/>
43+
44+
</Grid>
45+
46+
<Button
47+
Content="Next"
48+
HorizontalAlignment="Center"
49+
Click="{x:Bind SignInWindow.NavigateToTokenPage}"
50+
Style="{StaticResource AccentButtonStyle}" />
51+
52+
</StackPanel>
53+
</Page>

‎App/SignInURLPage.xaml.cs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
usingSystem;
2+
usingSystem.Collections.Generic;
3+
usingSystem.IO;
4+
usingSystem.Linq;
5+
usingSystem.Runtime.InteropServices.WindowsRuntime;
6+
usingCoder.Desktop.App.ViewModels;
7+
usingMicrosoft.UI.Xaml;
8+
usingMicrosoft.UI.Xaml.Controls;
9+
usingMicrosoft.UI.Xaml.Controls.Primitives;
10+
usingMicrosoft.UI.Xaml.Data;
11+
usingMicrosoft.UI.Xaml.Input;
12+
usingMicrosoft.UI.Xaml.Media;
13+
usingMicrosoft.UI.Xaml.Navigation;
14+
usingWindows.Foundation;
15+
usingWindows.Foundation.Collections;
16+
17+
namespaceCoder.Desktop.App;
18+
19+
/// <summary>
20+
/// A login page to enter the Coder Server URL
21+
/// </summary>
22+
publicsealedpartialclassSignInURLPage:Page
23+
{
24+
publicSignInURLPage(SignInWindowparent,SignInViewModelviewModel)
25+
{
26+
InitializeComponent();
27+
ViewModel=viewModel;
28+
SignInWindow=parent;
29+
}
30+
31+
publicreadonlySignInViewModelViewModel;
32+
publicreadonlySignInWindowSignInWindow;
33+
}

‎App/SignInWindow.xaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Window
3+
x:Class="Coder.Desktop.App.SignInWindow"
4+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
5+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
6+
xmlns:local="using:Coder.Desktop.App"
7+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
8+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
9+
mc:Ignorable="d"
10+
Title="Sign in to Coder">
11+
12+
<Window.SystemBackdrop>
13+
<DesktopAcrylicBackdrop />
14+
</Window.SystemBackdrop>
15+
</Window>

‎App/SignInWindow.xaml.cs

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
usingSystem;
2+
usingSystem.Collections.Generic;
3+
usingSystem.IO;
4+
usingSystem.Linq;
5+
usingSystem.Runtime.InteropServices.WindowsRuntime;
6+
usingCoder.Desktop.App.ViewModels;
7+
usingCommunityToolkit.Mvvm.Input;
8+
usingMicrosoft.UI.Xaml;
9+
usingMicrosoft.UI.Xaml.Controls;
10+
usingMicrosoft.UI.Xaml.Controls.Primitives;
11+
usingMicrosoft.UI.Xaml.Data;
12+
usingMicrosoft.UI.Xaml.Input;
13+
usingMicrosoft.UI.Xaml.Media;
14+
usingMicrosoft.UI.Xaml.Navigation;
15+
usingWindows.Foundation;
16+
usingWindows.Foundation.Collections;
17+
usingWindows.Graphics;
18+
19+
// To learn more about WinUI, the WinUI project structure,
20+
// and more about our project templates, see: http://aka.ms/winui-project-info.
21+
22+
namespaceCoder.Desktop.App;
23+
24+
25+
/// <summary>
26+
/// An empty window that can be used on its own or navigated to within a Frame.
27+
/// </summary>
28+
publicsealedpartialclassSignInWindow:Window
29+
{
30+
privateconstdoubleWIDTH=600.0;
31+
privateconstdoubleHEIGHT=300.0;
32+
33+
privatereadonlySignInViewModelviewModel;
34+
publicSignInWindow(SignInViewModelvm)
35+
{
36+
viewModel=vm;
37+
InitializeComponent();
38+
varurlPage=newSignInURLPage(this,viewModel);
39+
Content=urlPage;
40+
ResizeWindow();
41+
}
42+
43+
[RelayCommand]
44+
publicvoidNavigateToTokenPage()
45+
{
46+
vartokenPage=newSignInTokenPage(this,viewModel);
47+
Content=tokenPage;
48+
}
49+
50+
[RelayCommand]
51+
publicvoidNavigateToURLPage()
52+
{
53+
varurlPage=newSignInURLPage(this,viewModel);
54+
Content=urlPage;
55+
}
56+
57+
privatevoidResizeWindow()
58+
{
59+
varscale=DisplayScale.WindowScale(this);
60+
varheight=(int)(HEIGHT*scale);
61+
varwidth=(int)(WIDTH*scale);
62+
AppWindow.Resize(newSizeInt32(width,height));
63+
}
64+
}

‎App/TrayWindow.xaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,10 @@
159159
<HyperlinkButton
160160
Margin="-10,0,-10,0"
161161
HorizontalAlignment="Stretch"
162-
HorizontalContentAlignment="Left">
162+
HorizontalContentAlignment="Left"
163+
Click="{x:Bind SignIn_Click}">
163164

164-
<TextBlockText="Signout"Foreground="{ThemeResource DefaultTextForegroundThemeBrush}" />
165+
<TextBlockText="Signin"Foreground="{ThemeResource DefaultTextForegroundThemeBrush}" />
165166
</HyperlinkButton>
166167

167168
<!-- For some strange reason, setting OpenCommand and ExitCommand here doesn't work, see .cs-->

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp