MainPage.xaml 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. <Page
  2. x:Class="Maple_App.MainPage"
  3. xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  4. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  5. xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
  6. xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
  7. xmlns:maple_app="using:Maple_App"
  8. xmlns:pickers="using:Windows.Storage.Pickers"
  9. xmlns:Windows10FallCreatorsUpdate="http://schemas.microsoft.com/winfx/2006/xaml/presentation?IsApiContractPresent(Windows.Foundation.UniversalApiContract, 5)"
  10. xmlns:Windows10version1809="http://schemas.microsoft.com/winfx/2006/xaml/presentation?IsApiContractPresent(Windows.Foundation.UniversalApiContract, 7)"
  11. xmlns:muxc="using:Microsoft.UI.Xaml.Controls"
  12. mc:Ignorable="d"
  13. NavigationCacheMode="Required"
  14. Loaded="Page_Loaded">
  15. <Page.Resources>
  16. <maple_app:DateTimeConverter x:Key="DateTimeConverter"/>
  17. <maple_app:BoolToVisibilityConverter x:Key="BoolToVisibilityConverter"/>
  18. <pickers:FileOpenPicker x:Key="ImportFilePicker" x:Name="ImportFilePicker"/>
  19. </Page.Resources>
  20. <Grid>
  21. <Grid.RowDefinitions>
  22. <RowDefinition Height="Auto" />
  23. <RowDefinition />
  24. </Grid.RowDefinitions>
  25. <Grid.ColumnDefinitions>
  26. <ColumnDefinition x:Name="LeftPaddingColumn" Width="0"/>
  27. <ColumnDefinition />
  28. <ColumnDefinition x:Name="RightPaddingColumn" Width="0"/>
  29. </Grid.ColumnDefinitions>
  30. <Grid Grid.Column="1" x:Name="CustomTitleBar" Height="32" Background="Transparent">
  31. <TextBlock
  32. x:Name="AppTitleTextBlock"
  33. Text="Maple"
  34. VerticalAlignment="Center"
  35. FontSize="13"
  36. Margin="12, 0, 0, 0"/>
  37. </Grid>
  38. <Grid
  39. x:Name="ConnectionToggleSwitchContainer"
  40. Grid.Column="1"
  41. HorizontalAlignment="Right"
  42. VerticalAlignment="Center"
  43. Background="Transparent">
  44. <ToolTipService.ToolTip>
  45. <ToolTip x:Name="NoProfileToggleTooltip">
  46. Maple VPN profile is not ready. Please check Setting page for more information.
  47. </ToolTip>
  48. </ToolTipService.ToolTip>
  49. <ToggleSwitch x:Name="ConnectionToggleSwitch" IsEnabled="False">
  50. <ToggleSwitch.RenderTransform>
  51. <CompositeTransform ScaleX=".8" ScaleY=".8" TranslateX="90" TranslateY="3" />
  52. </ToggleSwitch.RenderTransform>
  53. </ToggleSwitch>
  54. </Grid>
  55. <SplitView
  56. x:Name="MainSplitView"
  57. RequestedTheme="Light"
  58. Grid.Row="1"
  59. Grid.ColumnSpan="3"
  60. DisplayMode="Overlay"
  61. PaneClosing="MainSplitView_PaneClosing"
  62. Background="White"
  63. OpenPaneLength="330">
  64. <SplitView.Pane>
  65. <Pivot x:Name="MainPivot" PivotItemLoaded="MainPivot_PivotItemLoaded">
  66. <PivotItem Header="Config" Margin="0">
  67. <Grid>
  68. <Grid.RowDefinitions>
  69. <RowDefinition Height="*"/>
  70. <RowDefinition Height="Auto"/>
  71. </Grid.RowDefinitions>
  72. <ListView
  73. x:Name="ConfigListView"
  74. Grid.Row="0"
  75. SelectionMode="Single"
  76. CanDragItems="True"
  77. AllowDrop="True"
  78. ItemsSource="{x:Bind ConfigItems, Mode=OneWay}"
  79. SelectionChanged="ConfigListView_SelectionChanged"
  80. DragItemsStarting="ConfigListView_DragItemsStarting"
  81. DragOver="ConfigListView_DragOver"
  82. Drop="ConfigListView_Drop">
  83. <ListView.ItemContainerStyle>
  84. <Style TargetType="ListViewItem">
  85. <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
  86. </Style>
  87. </ListView.ItemContainerStyle>
  88. <ListView.Resources>
  89. <MenuFlyout x:Key="ItemContextFlyout">
  90. <MenuFlyoutItem Icon="Favorite" Text="Set as Default" Click="ConfigSetAsDefaultMenuItem_Click"/>
  91. <MenuFlyoutItem Icon="Copy" Text="Duplicate" Click="ConfigDuplicateMenuItem_Click"/>
  92. <MenuFlyoutItem Icon="Rename" Text="Rename" Click="ConfigRenameMenuItem_Click">
  93. <Windows10FallCreatorsUpdate:MenuFlyoutItem.KeyboardAccelerators>
  94. <Windows10FallCreatorsUpdate:KeyboardAccelerator Key="F2" ScopeOwner="{x:Bind ConfigListView}"/>
  95. </Windows10FallCreatorsUpdate:MenuFlyoutItem.KeyboardAccelerators>
  96. </MenuFlyoutItem>
  97. <MenuFlyoutItem Icon="Delete" Text="Delete" Click="ConfigDeleteMenuItem_Click">
  98. <MenuFlyoutItem.Command>
  99. <Windows10version1809:StandardUICommand Kind="Delete"/>
  100. </MenuFlyoutItem.Command>
  101. </MenuFlyoutItem>
  102. </MenuFlyout>
  103. <SolidColorBrush x:Key="ListViewItemForegroundSelected" Color="Black" />
  104. <SolidColorBrush x:Key="ListViewItemBackgroundSelected" Color="{StaticResource SystemAccentColorLight3}" />
  105. <SolidColorBrush x:Key="ListViewItemBackgroundSelectedPointerOver" Color="{StaticResource SystemAccentColorLight3}" Opacity=".6" />
  106. <SolidColorBrush x:Key="ListViewItemBackgroundSelectedPressed" Color="{StaticResource SystemAccentColorLight3}" Opacity=".8" />
  107. </ListView.Resources>
  108. <ListView.ItemTemplate>
  109. <DataTemplate x:DataType="maple_app:ConfigViewModel">
  110. <Grid
  111. HorizontalAlignment="Stretch"
  112. VerticalAlignment="Stretch"
  113. ContextFlyout="{StaticResource ItemContextFlyout}"
  114. DoubleTapped="ConfigItem_DoubleTapped">
  115. <Grid.RowDefinitions>
  116. <RowDefinition Height="Auto"/>
  117. <RowDefinition Height="Auto"/>
  118. </Grid.RowDefinitions>
  119. <Grid.ColumnDefinitions>
  120. <ColumnDefinition Width="0"/>
  121. <ColumnDefinition Width="*"/>
  122. </Grid.ColumnDefinitions>
  123. <Rectangle
  124. Grid.Row="0"
  125. Grid.RowSpan="2"
  126. Grid.Column="0"
  127. Margin="-12, 6, 4, 6"
  128. Fill="{ThemeResource SystemAccentColor}"
  129. Visibility="{x:Bind IsDefault, Mode=OneWay}"/>
  130. <TextBlock
  131. Grid.Row="0"
  132. Grid.Column="1"
  133. Text="{x:Bind Name, Mode=OneWay}"/>
  134. <TextBlock
  135. Grid.Row="1"
  136. Grid.Column="1"
  137. Text="{x:Bind DateUpdated, Mode=OneWay, Converter={StaticResource DateTimeConverter}}"
  138. Style="{ThemeResource CaptionTextBlockStyle}"
  139. Foreground="{ThemeResource SystemControlPageTextBaseMediumBrush}"/>
  140. </Grid>
  141. </DataTemplate>
  142. </ListView.ItemTemplate>
  143. </ListView>
  144. <CommandBar Grid.Row="1">
  145. <AppBarButton Icon="Add" Label="Add">
  146. <AppBarButton.Flyout>
  147. <MenuFlyout Placement="Top">
  148. <MenuFlyoutItem Text="Conf" Click="ConfigCreateMenuItem_Click"/>
  149. <MenuFlyoutItem Text="JSON" Click="ConfigCreateMenuItem_Click"/>
  150. <MenuFlyoutItem Text="Minimal" Click="ConfigCreateMenuItem_Click"/>
  151. <MenuFlyoutSeparator/>
  152. <MenuFlyoutItem Text="Import…" Click="ConfigImportMenuItem_Click"/>
  153. </MenuFlyout>
  154. </AppBarButton.Flyout>
  155. </AppBarButton>
  156. </CommandBar>
  157. <ContentDialog
  158. x:Name="RenameDialog"
  159. Height="10"
  160. Title="Specify a new file name"
  161. PrimaryButtonText="Rename"
  162. SecondaryButtonText="Close"
  163. PrimaryButtonClick="RenameDialogPrimaryButton_Click">
  164. <ContentDialog.SecondaryButtonCommand>
  165. <Windows10version1809:StandardUICommand Kind="Close"/>
  166. </ContentDialog.SecondaryButtonCommand>
  167. <TextBox
  168. x:Name="RenameDialogText"
  169. MaxLength="100"
  170. Height="32"
  171. AcceptsReturn="False"
  172. TextWrapping="NoWrap"
  173. KeyDown="RenameDialogText_KeyDown"/>
  174. </ContentDialog>
  175. </Grid>
  176. </PivotItem>
  177. <PivotItem Header="Setting">
  178. <ScrollViewer>
  179. <StackPanel>
  180. <TextBlock Margin="0, 18" Text="Network Interface" Style="{ThemeResource TitleTextBlockStyle}"/>
  181. <TextBlock
  182. Text="Choose a default network interface for DNS and outbound connections"
  183. TextWrapping="WrapWholeWords"/>
  184. <ComboBox
  185. x:Name="NetifCombobox"
  186. HorizontalAlignment="Stretch"
  187. Margin="0, 8"
  188. SelectedValuePath="Addr"
  189. SelectionChanged="NetifCombobox_SelectionChanged">
  190. <ComboBox.ItemTemplate>
  191. <DataTemplate x:DataType="maple_app:Netif">
  192. <StackPanel x:Name="NetifComboboxTemplateRoot">
  193. <TextBlock Text="{x:Bind Desc}" FontWeight="Bold" />
  194. <TextBlock
  195. Text="{x:Bind IpLines}"
  196. Visibility="{Binding IsDropDownOpen, ElementName=NetifCombobox}" />
  197. <TextBlock
  198. Text="{x:Bind IpSummary}"
  199. Visibility="{Binding
  200. IsDropDownOpen,
  201. ElementName=NetifCombobox,
  202. Converter={StaticResource BoolToVisibilityConverter},
  203. ConverterParameter=true}" />
  204. </StackPanel>
  205. </DataTemplate>
  206. </ComboBox.ItemTemplate>
  207. </ComboBox>
  208. <TextBlock Margin="0, 18" Text="VPN Connection" Style="{ThemeResource TitleTextBlockStyle}"/>
  209. <TextBlock Margin="0, 0, 0, 18" TextWrapping="WrapWholeWords">
  210. <Run Text="Connect to Maple in the"/>
  211. <Hyperlink TextDecorations="None" NavigateUri="ms-settings:network-vpn">
  212. <Run Text="Windows Settings"/>
  213. </Hyperlink>
  214. <Run Text="app."/>
  215. </TextBlock>
  216. <TextBlock
  217. Margin="0, 0, 0, 8"
  218. Foreground="{ThemeResource SystemControlPageTextBaseMediumBrush}"
  219. TextWrapping="WrapWholeWords">
  220. <Run Text="For first time connection, create a VPN profile with provider"/>
  221. <Run FontFamily="Consolas" Text="Maple"/>
  222. <Run Text="and server name"/>
  223. <Run FontFamily="Consolas" Text="maple"/>
  224. <Run Text=". Alternatively, select &quot;Generate Profile&quot; to create one automatically (not recommended)."/>
  225. </TextBlock>
  226. <Button Content="Generate Profile" Click="GenerateProfileButton_Click"/>
  227. <TextBlock Margin="0, 18" Text="Config Folder" Style="{ThemeResource TitleTextBlockStyle}"/>
  228. <TextBlock
  229. Margin="0, 0, 0, 8"
  230. Text="Using app built-in local state."
  231. TextWrapping="WrapWholeWords"
  232. Visibility="{x:Bind UsingDefaultConfigFolder, Mode=OneWay}"/>
  233. <TextBlock
  234. Margin="0, 0, 0, 18"
  235. Text="Using custom configuration folder."
  236. TextWrapping="WrapWholeWords"
  237. Visibility="{x:Bind
  238. UsingDefaultConfigFolder,
  239. Converter={StaticResource BoolToVisibilityConverter},
  240. ConverterParameter=x:True,
  241. Mode=OneWay}"/>
  242. <TextBlock
  243. Margin="0, 0, 0, 8"
  244. Foreground="{ThemeResource SystemControlPageTextBaseMediumBrush}"
  245. TextWrapping="WrapWholeWords">
  246. Specify a folder for Maple and Leaf to find configuration files. External rule databases and TLS certificates will remain in the default location.
  247. </TextBlock>
  248. <StackPanel Orientation="Horizontal">
  249. <Button Content="Select Folder" Click="ConfigFolderSelectButton_Click"/>
  250. <Button
  251. Margin="4, 0, 0, 0"
  252. Content="Reset to Default"
  253. Visibility="{x:Bind
  254. UsingDefaultConfigFolder,
  255. Mode=OneWay,
  256. Converter={StaticResource BoolToVisibilityConverter},
  257. ConverterParameter=x:True}"
  258. Click="ConfigFolderResetButton_Click"/>
  259. </StackPanel>
  260. <TextBlock
  261. x:Name="CustomConfigFolderPathText"
  262. Margin="0, 4, 0, 0"
  263. TextWrapping="Wrap"
  264. IsTextSelectionEnabled="True"
  265. Visibility="{x:Bind
  266. UsingDefaultConfigFolder,
  267. Converter={StaticResource BoolToVisibilityConverter},
  268. ConverterParameter=x:True,
  269. Mode=OneWay}"
  270. />
  271. <TextBlock Margin="0, 18" Text="About" Style="{ThemeResource TitleTextBlockStyle}"/>
  272. <HyperlinkButton Padding="0" Content="Homepage" NavigateUri="https://github.com/YtFlow/Maple"/>
  273. <HyperlinkButton Padding="0" Content="Report Issues" NavigateUri="https://github.com/YtFlow/Maple/issues"/>
  274. <HyperlinkButton Padding="0" Content="License" NavigateUri="https://github.com/YtFlow/Maple/blob/main/LICENSE"/>
  275. <TextBlock Margin="0, 20, 0, 40" TextWrapping="WrapWholeWords">
  276. <Run>This product contains a</Run>
  277. <Hyperlink NavigateUri="https://github.com/YtFlow/leaf" TextDecorations="None">
  278. <Run>modified version</Run>
  279. </Hyperlink>
  280. <Run>of</Run>
  281. <Hyperlink NavigateUri="https://github.com/eycorsican/leaf" TextDecorations="None">
  282. <Run>eycorsican/leaf</Run>
  283. </Hyperlink>
  284. <Run>under</Run>
  285. <Hyperlink NavigateUri="https://github.com/eycorsican/leaf/blob/master/LICENSE" TextDecorations="None">
  286. <Run>Apache License 2.0</Run>
  287. </Hyperlink>
  288. <Run>.</Run>
  289. </TextBlock>
  290. </StackPanel>
  291. </ScrollViewer>
  292. </PivotItem>
  293. </Pivot>
  294. </SplitView.Pane>
  295. <Frame x:Name="MainContentFrame" CacheSize="2" />
  296. </SplitView>
  297. <VisualStateManager.VisualStateGroups>
  298. <VisualStateGroup CurrentStateChanged="WindowWidth_CurrentStateChanged">
  299. <VisualState>
  300. <VisualState.StateTriggers>
  301. <AdaptiveTrigger MinWindowWidth="600"/>
  302. </VisualState.StateTriggers>
  303. <VisualState.Setters>
  304. <Setter Target="MainSplitView.DisplayMode" Value="Inline"/>
  305. <Setter Target="MainSplitView.IsPaneOpen" Value="True"/>
  306. </VisualState.Setters>
  307. </VisualState>
  308. </VisualStateGroup>
  309. </VisualStateManager.VisualStateGroups>
  310. </Grid>
  311. </Page>