Browse Source

Add shell project

justin.xing 3 years ago
commit
54bc1a08fd
11 changed files with 259 additions and 0 deletions
  1. 27 0
      .vscode/launch.json
  2. 42 0
      .vscode/tasks.json
  3. 8 0
      fis/.gitignore
  4. 7 0
      fis/App.axaml
  5. 24 0
      fis/App.axaml.cs
  6. 19 0
      fis/MainWindow.axaml
  7. 39 0
      fis/MainWindow.axaml.cs
  8. 30 0
      fis/Program.cs
  9. 31 0
      fis/TextContextMenuHandler.cs
  10. 16 0
      fis/fis.Mac.csproj
  11. 16 0
      fis/fis.Win.csproj

+ 27 - 0
.vscode/launch.json

@@ -0,0 +1,27 @@
+{
+    "version": "0.2.0",
+    "configurations": [
+        {
+            // Use IntelliSense to find out which attributes exist for C# debugging
+            // Use hover for the description of the existing attributes
+            // For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
+            "name": ".NET Core Launch (console)",
+            "type": "coreclr",
+            "request": "launch",
+            "preLaunchTask": "build",
+            // If you have changed target frameworks, make sure to update the program path.
+            "program": "${workspaceFolder}/fis.WIndows/bin/Debug/net5.0/fis.dll",
+            "args": [],
+            "cwd": "${workspaceFolder}/fis.WIndows",
+            // For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console
+            "console": "internalConsole",
+            "stopAtEntry": false
+        },
+        {
+            "name": ".NET Core Attach",
+            "type": "coreclr",
+            "request": "attach",
+            "processId": "${command:pickProcess}"
+        }
+    ]
+}

+ 42 - 0
.vscode/tasks.json

@@ -0,0 +1,42 @@
+{
+    "version": "2.0.0",
+    "tasks": [
+        {
+            "label": "build",
+            "command": "dotnet",
+            "type": "process",
+            "args": [
+                "build",
+                "${workspaceFolder}/fis.WIndows/fis.csproj",
+                "/property:GenerateFullPaths=true",
+                "/consoleloggerparameters:NoSummary"
+            ],
+            "problemMatcher": "$msCompile"
+        },
+        {
+            "label": "publish",
+            "command": "dotnet",
+            "type": "process",
+            "args": [
+                "publish",
+                "${workspaceFolder}/fis.WIndows/fis.csproj",
+                "/property:GenerateFullPaths=true",
+                "/consoleloggerparameters:NoSummary"
+            ],
+            "problemMatcher": "$msCompile"
+        },
+        {
+            "label": "watch",
+            "command": "dotnet",
+            "type": "process",
+            "args": [
+                "watch",
+                "run",
+                "${workspaceFolder}/fis.WIndows/fis.csproj",
+                "/property:GenerateFullPaths=true",
+                "/consoleloggerparameters:NoSummary"
+            ],
+            "problemMatcher": "$msCompile"
+        }
+    ]
+}

+ 8 - 0
fis/.gitignore

@@ -0,0 +1,8 @@
+.idea/
+.vscode/
+.vs/
+
+bin/
+obj/
+
+*.user

+ 7 - 0
fis/App.axaml

@@ -0,0 +1,7 @@
+<Application xmlns="https://github.com/avaloniaui"
+             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+             x:Class="fis.App">
+    <Application.Styles>
+        <FluentTheme Mode="Dark"/>
+    </Application.Styles>
+</Application>

+ 24 - 0
fis/App.axaml.cs

@@ -0,0 +1,24 @@
+using Avalonia;
+using Avalonia.Controls.ApplicationLifetimes;
+using Avalonia.Markup.Xaml;
+
+namespace fis
+{
+    public class App : Application
+    {
+        public override void Initialize()
+        {
+            AvaloniaXamlLoader.Load(this);
+        }
+
+        public override void OnFrameworkInitializationCompleted()
+        {
+            if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
+            {
+                desktop.MainWindow = new MainWindow();
+            }
+
+            base.OnFrameworkInitializationCompleted();
+        }
+    }
+}

+ 19 - 0
fis/MainWindow.axaml

@@ -0,0 +1,19 @@
+<Window xmlns="https://github.com/avaloniaui"
+        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
+        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
+        mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
+        x:Class="fis.MainWindow"
+        ExtendClientAreaToDecorationsHint="True"
+        ExtendClientAreaChromeHints="PreferSystemChrome"
+        TransparencyLevelHint="Transparent"
+        Title="fis">
+   <Grid>
+      <Grid.RowDefinitions>
+          <RowDefinition Height="32"/>
+          <RowDefinition Height="*"/>
+      </Grid.RowDefinitions>
+      <Border BorderBrush="Black" BorderThickness="1,1,1,0" Grid.Row="0" VerticalAlignment="Top" Background="Black" IsHitTestVisible="False"/>
+      <Border BorderBrush="Black" BorderThickness="1,0,1,1" Grid.Row="1" x:Name="BrowserBorder"/>
+  </Grid>
+</Window>

+ 39 - 0
fis/MainWindow.axaml.cs

@@ -0,0 +1,39 @@
+using System;
+using System.IO;
+using Avalonia;
+using Avalonia.Controls;
+using Avalonia.Markup.Xaml;
+using Xilium.CefGlue.Avalonia;
+using Xilium.CefGlue.Common.Handlers;
+
+namespace fis
+{
+    public partial class MainWindow : Window
+    {
+        private AvaloniaCefBrowser? _browser;
+
+        public MainWindow()
+        {
+            WindowStartupLocation = WindowStartupLocation.CenterScreen;
+            WindowState = WindowState.Maximized;
+            InitializeComponent();
+#if DEBUG
+            this.AttachDevTools();
+#endif
+        }
+
+        private void InitializeComponent()
+        {
+            AvaloniaXamlLoader.Load(this);
+            var browserContainer = this.FindControl<Border>("BrowserBorder");
+            var flyinsonoHandler = new FileSystemHostHandler("flyinsono.com",Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "flyinsono.com"));
+            var handler = new HostRequestHandler();
+            handler.RegisterHostHandler(flyinsonoHandler);
+            _browser = new AvaloniaCefBrowser();
+            _browser.Address = "http://flyinsono.com/index.html";
+            _browser.RequestHandler = handler;
+            _browser.ContextMenuHandler = new TextContextMenuHandler(_browser);
+            browserContainer.Child = _browser;
+        }
+    }
+}

+ 30 - 0
fis/Program.cs

@@ -0,0 +1,30 @@
+using System;
+using System.Collections.Generic;
+using System.Globalization;
+using Avalonia;
+using Avalonia.Controls;
+using Avalonia.Controls.ApplicationLifetimes;
+using Xilium.CefGlue;
+using Xilium.CefGlue.Common;
+
+namespace fis
+{
+    class Program
+    {
+        // Initialization code. Don't use any Avalonia, third-party APIs or any
+        // SynchronizationContext-reliant code before AppMain is called: things aren't initialized
+        // yet and stuff might break.
+        public static void Main(string[] args) => BuildAvaloniaApp()
+            .StartWithClassicDesktopLifetime(args);
+
+        // Avalonia configuration, don't remove; also used by visual designer.
+        public static AppBuilder BuildAvaloniaApp()
+        {
+            return AppBuilder.Configure<App>().UsePlatformDetect().AfterSetup(_ => CefRuntimeLoader.Initialize(
+                //浏览器菜单语言设置为当前语言
+                settings: new CefSettings() { Locale = CultureInfo.CurrentCulture.Name }, 
+                //启用Chrome自动播放
+                flags: new[] { new KeyValuePair<string, string>("autoplay-policy", "no-user-gesture-required") }));
+        }
+    }
+}

+ 31 - 0
fis/TextContextMenuHandler.cs

@@ -0,0 +1,31 @@
+using Xilium.CefGlue;
+using Xilium.CefGlue.Common;
+using Xilium.CefGlue.Common.Handlers;
+
+//Chrome菜单管理,禁用在非编辑状态下的浏览器菜单
+public class TextContextMenuHandler : ContextMenuHandler
+{
+    private readonly BaseCefBrowser _owner;
+
+    public TextContextMenuHandler(BaseCefBrowser owner)
+    {
+        _owner = owner;
+    }
+
+    protected override void OnBeforeContextMenu(CefBrowser browser, CefFrame frame, CefContextMenuParams state, CefMenuModel model)
+    {
+        //If it is not focusing on text editor, just clear all popup menus.
+        if (!((state.ContextMenuType & CefContextMenuTypeFlags.Editable) != 0 || (state.ContextMenuType & CefContextMenuTypeFlags.Selection) != 0))
+        {
+            model.Clear();
+        }
+        base.OnBeforeContextMenu(browser, frame, state, model);
+    }
+
+    protected override bool RunContextMenu(CefBrowser browser, CefFrame frame, CefContextMenuParams parameters, CefMenuModel model, CefRunContextMenuCallback callback)
+    {
+        //This is for enable the style.
+        _owner.HandleOpenContextMenu(parameters, model, callback);
+        return true;
+    }
+}

+ 16 - 0
fis/fis.Mac.csproj

@@ -0,0 +1,16 @@
+<Project Sdk="Microsoft.NET.Sdk">
+  <PropertyGroup>
+    <OutputType>WinExe</OutputType>
+    <TargetFramework>net5.0</TargetFramework>
+    <Nullable>enable</Nullable>
+	  <AssemblyName>fis</AssemblyName>
+  </PropertyGroup>
+  <ItemGroup>
+    <PackageReference Include="Avalonia" Version="0.10.3" />
+    <PackageReference Include="Avalonia.Desktop" Version="0.10.3" />
+    <PackageReference Include="Avalonia.Diagnostics" Version="0.10.3" />
+    <PackageReference Include="Cef.Native.osx-x64" Version="1.0.0" />
+    <PackageReference Include="CefGlueBrowserProcess.osx-x64" Version="1.0.0" />
+    <PackageReference Include="Vinno.CefGlue.Avalonia" Version="1.0.0" />
+   </ItemGroup>
+</Project>

+ 16 - 0
fis/fis.Win.csproj

@@ -0,0 +1,16 @@
+<Project Sdk="Microsoft.NET.Sdk">
+  <PropertyGroup>
+    <OutputType>WinExe</OutputType>
+    <TargetFramework>net5.0</TargetFramework>
+    <Nullable>enable</Nullable>
+    <AssemblyName>fis</AssemblyName>
+  </PropertyGroup>
+  <ItemGroup>
+    <PackageReference Include="Avalonia" Version="0.10.3" />
+    <PackageReference Include="Avalonia.Desktop" Version="0.10.3" />
+    <PackageReference Include="Avalonia.Diagnostics" Version="0.10.3" />
+    <PackageReference Include="Cef.Native.win-x86" Version="1.0.0" />
+    <PackageReference Include="CefGlueBrowserProcess.win-x86" Version="1.0.0" />
+    <PackageReference Include="Vinno.CefGlue.Avalonia" Version="1.0.0" />
+   </ItemGroup>
+</Project>