mirror of
https://github.com/chylex/TweetDuck.git
synced 2025-04-11 12:15:44 +02:00
Add Linux project (WIP)
This commit is contained in:
parent
acafbc3706
commit
2af864f337
.gitignoreREADME.md
lib
TweetLib.Browser.CEF
TweetLib.Browser
TweetLib.Core
TweetLib.Utils
linux
.gitignoreglobal.jsonpublish.sh
.idea/.idea.TweetDuck.Linux/.idea
Directory.Build.propsTweetDuck.Linux.slnTweetDuck
Application
Browser
Configuration
Program.csResources
TweetDuck.csprojUtils
TweetImpl.CefGlue
Adapters
CefAdapter.csCefBrowserAdapter.csCefDragDataAdapter.csCefErrorCodeAdapter.csCefFileDialogCallbackAdapter.csCefFrameAdapter.csCefJsDialogCallbackAdapter.csCefMenuModelAdapter.csCefRequestAdapter.csCefResourceHandlerFactory.csCefResponseAdapter.cs
Component
Dialogs
Handlers
ContextMenuHandler.csDialogHandler.csDownloadRequestClient.csDragHandler.csJsDialogHandler.csLifeSpanHandler.csRequestHandler.cs
Lib.csResource
ResourceRequestHandler.csResourceRequestHandlerFactory.csResponseFilter.csResources
TweetImpl.CefGlue.csprojUtils
4
.gitignore
vendored
4
.gitignore
vendored
@ -10,8 +10,8 @@ bld/*
|
||||
!bld/Resources
|
||||
|
||||
# Rider
|
||||
.idea/.idea.TweetDuck/.idea/dictionaries
|
||||
.idea/.idea.TweetDuck/.idea/misc.xml
|
||||
**/.idea/dictionaries
|
||||
**/.idea/misc.xml
|
||||
|
||||
# User-specific files
|
||||
*.suo
|
||||
|
65
README.md
65
README.md
@ -17,15 +17,21 @@
|
||||
- [TweetDuck.Browser](#tweetduckbrowser)
|
||||
- [TweetDuck.Video](#tweetduckvideo)
|
||||
- [TweetImpl.CefSharp](#tweetimplcefsharp)
|
||||
+ [Linux Projects](#linux-projects)
|
||||
- [TweetDuck](#tweetduck-1)
|
||||
- [TweetImpl.CefGlue](#tweetimplcefglue)
|
||||
+ [Miscellaneous](#miscellaneous)
|
||||
- [TweetLib.Communication](#tweetlibcommunication)
|
||||
- [TweetLib.Utils](#tweetlibutils)
|
||||
- [TweetTest.*](#tweettest)
|
||||
* [Development](#development)
|
||||
+ [Building](#building)
|
||||
+ [Debugging](#debugging)
|
||||
3. [Development (Windows)](#development-windows)
|
||||
* [Building](#building)
|
||||
* [Debugging](#debugging)
|
||||
* [Release](#release)
|
||||
+ [Installers](#installers-1)
|
||||
4. [Development (Linux)](#development-linux)
|
||||
* [Building](#building-1)
|
||||
* [Release](#release-1)
|
||||
|
||||
# Installation
|
||||
|
||||
@ -35,7 +41,7 @@ Download links and system requirements are on the [official website](https://twe
|
||||
|
||||
## Requirements
|
||||
|
||||
Building TweetDuck requires at minimum [Visual Studio 2019](https://visualstudio.microsoft.com/downloads) and Windows 7. Before opening the solution, open Visual Studio Installer and make sure you have the following Visual Studio workloads and components installed:
|
||||
Building TweetDuck for Windows requires at minimum [Visual Studio 2019](https://visualstudio.microsoft.com/downloads) and Windows 7. Before opening the solution, open Visual Studio Installer and make sure you have the following Visual Studio workloads and components installed:
|
||||
* **.NET desktop development**
|
||||
* .NET Framework 4.7.2 targeting pack
|
||||
* F# desktop language support
|
||||
@ -44,6 +50,8 @@ Building TweetDuck requires at minimum [Visual Studio 2019](https://visualstudio
|
||||
|
||||
In the **Installation details** panel, you can expand the workloads you selected, and uncheck any components that are not listed above to save space.
|
||||
|
||||
Building TweetDuck for Linux requires [.NET 5](https://docs.microsoft.com/en-us/dotnet/core/install/linux). The Linux project has its own solution file in the `linux/` folder.
|
||||
|
||||
### Editors
|
||||
|
||||
For editing code, I recommend either:
|
||||
@ -57,7 +65,7 @@ Icons and logos were designed in [Affinity Designer](https://affinity.serif.com/
|
||||
|
||||
> If you don't want to build installers using the existing foundations, you can skip this section.
|
||||
|
||||
Official installers are built using [InnoSetup](https://jrsoftware.org/isinfo.php) and [Inno Download Plugin](https://mitrichsoftware.wordpress.com/inno-setup-tools/inno-download-plugin/), specifically:
|
||||
Official Windows installers are built using [InnoSetup](https://jrsoftware.org/isinfo.php) and [Inno Download Plugin](https://mitrichsoftware.wordpress.com/inno-setup-tools/inno-download-plugin/), specifically:
|
||||
* [InnoSetup 5.6.1](https://files.jrsoftware.org/is/5/innosetup-5.6.1.exe) with Preprocessor support
|
||||
* [Inno Download Plugin 1.5.0](https://drive.google.com/folderview?id=0Bzw1xBVt0mokSXZrUEFIanV4azA&usp=sharing#list)
|
||||
|
||||
@ -70,12 +78,17 @@ You may need to restart Visual Studio after changing `PATH` for the change to ta
|
||||
|
||||
## Solution Overview
|
||||
|
||||
Open the solution file `TweetDuck.sln` in an IDE, and use the **Restore NuGet Packages** option in your IDE to install dependencies. TweetDuck uses the [CefSharp](https://github.com/cefsharp/CefSharp/) library for the browser component, which is based on the [CEF](https://bitbucket.org/chromiumembedded/cef/) project.
|
||||
Open the solution file `TweetDuck.sln` (or `linux/TweetDuck.Linux.sln`) in an IDE, and use the **Restore NuGet Packages** option in your IDE to install dependencies.
|
||||
|
||||
On Windows, TweetDuck uses the [CefSharp](https://github.com/cefsharp/CefSharp/) library for the browser component, and Windows Forms for the GUI.
|
||||
|
||||
On Linux, TweetDuck uses the [ChromiumGtk](https://github.com/lunixo/ChromiumGtk) library, which combines [CefGlue](https://gitlab.com/xiliumhq/chromiumembedded/cefglue) for the browser component and [GtkSharp](https://github.com/GtkSharp/GtkSharp) for the GUI.
|
||||
|
||||
The solution contains several C# projects for executables and libraries, and F# projects for automated tests.
|
||||
|
||||
Projects are organized into folders:
|
||||
* Windows projects are in the `windows/` folder, and target `.NET Framework 4.7.2` + `C# 8.0`
|
||||
* Linux projects are in the `linux/` folder, and target `.NET 5` + `C#`
|
||||
* Libraries (`TweetLib.*`) are in the `lib/` folder, and target `.NET Standard 2.0` + `C# 9.0`
|
||||
* Tests (`TweetTest.*`) are also in the `lib/` folder, and target `.NET Framework 4.7.2` + `F#`
|
||||
|
||||
@ -109,8 +122,6 @@ This library is a partial implementation of `TweetLib.Browser` based on [CEF](ht
|
||||
|
||||
While `TweetLib.Browser` is highly generic, most browser libraries are likely to be using some form of [CEF](https://bitbucket.org/chromiumembedded/cef/), so this library significantly reduces the amount of work required to swap between browser libraries that are based on [CEF](https://bitbucket.org/chromiumembedded/cef/).
|
||||
|
||||
Note: The repository contains an experimental `linux` branch, which uses [CefGlue](https://gitlab.com/xiliumhq/chromiumembedded/cefglue) as its browser library instead of [CefSharp](https://github.com/cefsharp/CefSharp/) which only works on Windows.
|
||||
|
||||
### Windows Projects
|
||||
|
||||
#### TweetDuck
|
||||
@ -131,6 +142,16 @@ By default, [CefSharp](https://github.com/cefsharp/CefSharp/) is not built with
|
||||
|
||||
Windows library that implements `TweetLib.Browser.CEF` using the [CefSharp](https://github.com/cefsharp/CefSharp/) library and Windows Forms.
|
||||
|
||||
### Linux Projects
|
||||
|
||||
#### TweetDuck
|
||||
|
||||
Main Linux executable. It has a transitive dependency on [ChromiumGtk](https://github.com/lunixo/ChromiumGtk). Here you will find the entry point that bootstraps the main application, as well as code for GUIs and Linux-specific functionality.
|
||||
|
||||
#### TweetImpl.CefGlue
|
||||
|
||||
Linux library that implements `TweetLib.Browser.CEF` using [ChromiumGtk](https://github.com/lunixo/ChromiumGtk), which is based on [CefGlue](https://gitlab.com/xiliumhq/chromiumembedded/cefglue) and [GtkSharp](https://github.com/GtkSharp/GtkSharp).
|
||||
|
||||
### Miscellaneous
|
||||
|
||||
#### TweetLib.Communication
|
||||
@ -145,22 +166,22 @@ This library contains various utilities that fill some very specific holes in th
|
||||
|
||||
These are F# projects with automated tests.
|
||||
|
||||
## Development
|
||||
# Development (Windows)
|
||||
|
||||
When developing with [Rider](https://www.jetbrains.com/rider/), it must be configured to use MSBuild from Visual Studio. You can set it in **File | Settings | Build, Execution, Deployment | Toolset and Build** with the `Use MSBuild version` drop-down.
|
||||
|
||||
### Building
|
||||
## Building
|
||||
|
||||
The `windows/TweetDuck/TweetDuck.csproj` project file has several tasks (targets) that run before and after a build:
|
||||
* `PreBuildEvent` runs a PowerShell script that kills `TweetDuck.Browser` processes, in case they got stuck
|
||||
* `CopyResources` copies resource files into the build folder, and validates them using the `PostBuild.ps1` PowerShell script
|
||||
* `CopyResources` copies resource files into the build folder, and patches and validates them using the `PostBuild.ps1` PowerShell script
|
||||
* `FinalizeDebug` copies a debug plugin (`Resources/Plugins/.debug`) into the build folder (Debug only)
|
||||
* `FinalizeRelease` prepares the build folder for publishing, and if InnoSetup is installed, regenerates the [update installer](#installers-1) (Release only)
|
||||
|
||||
If the build fails, usually with an error like `The command (...) exited with code 1`, open the **Output** tab for detailed logs. A possible cause is the `PostBuild.ps1` script's file validation:
|
||||
* `Resources/Plugins/emoji-keyboard/emoji-ordering.txt` line endings must be LF (line feed); if the file contains any CR (carriage return) characters, the build will fail
|
||||
|
||||
### Debugging
|
||||
## Debugging
|
||||
|
||||
The `Debug` configuration uses a separate data folder by default (`%LOCALAPPDATA%\TweetDuckDebug`) to avoid affecting an existing installation of TweetDuck. You can modify this by opening **TweetDuck Properties** in Visual Studio, clicking the **Debug** tab, and changing the **Command line arguments** field.
|
||||
|
||||
@ -193,3 +214,23 @@ If you plan to distribute your own installers, you can change the variables in t
|
||||
> There is a small chance running `GEN INSTALLERS.bat` immediately shows a resource error. If that happens, close the console window (which terminates all Inno Setup processes and leaves corrupted installers in the output folder), and run it again.
|
||||
|
||||
> Running `GEN INSTALLERS.bat` uses about 400 MB of RAM due to high compression. You can lower this to about 140 MB by opening `gen_full.iss` and `gen_port.iss`, and changing `LZMADictionarySize=15360` to `LZMADictionarySize=4096`.
|
||||
|
||||
## Development (Linux)
|
||||
|
||||
Unfortunately the development experience on Linux is terrible, likely due to mixed C# and native code. The .NET debugger seems to crash the moment it enters native code, so the only way to run the app is without the debugger attached. If any C# code throws an exception, it will crash the whole application with no usable stack trace or error message. Please let me know if you find a way to make this better.
|
||||
|
||||
### Building
|
||||
|
||||
The `linux/TweetDuck/TweetDuck.csproj` project file has several tasks (targets) that run after a build:
|
||||
|
||||
* `CopyResources` copies resource files into the build folder, and patches and validates them using the `build.sh` Bash script
|
||||
* `FinalizeDebug` copies a debug plugin (`Resources/Plugins/.debug`) into the build folder (Debug only)
|
||||
* `FinalizeRelease` prepares the build folder for publishing (Release only)
|
||||
|
||||
### Release
|
||||
|
||||
To change the application version before a release, search for the `<Version>` tag in every `.csproj` file in the `linux/` folder and modify it.
|
||||
|
||||
To build the application, execute the `linux/publish.sh` Bash script. This will build the Release configuration for the `linux-x64` runtime platform, and create a tarball in the `linux/bld/` folder.
|
||||
|
||||
If you decide to publicly release a custom version, please change all references to the TweetDuck name, website, and other links such as the issue tracker. The source files contain several constants and references to the official website and this repository, so don't forget to search all files for `chylex.com` and `github.com` in all files and replace them appropriately.
|
||||
|
@ -10,6 +10,8 @@ public abstract class ByteArrayResourceHandlerLogic {
|
||||
|
||||
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global")]
|
||||
public sealed class ByteArrayResourceHandlerLogic<TResponse> : ByteArrayResourceHandlerLogic {
|
||||
public int RemainingBytes => resource.Length - position;
|
||||
|
||||
private readonly ByteArrayResource resource;
|
||||
private readonly IResponseAdapter<TResponse> responseAdapter;
|
||||
|
||||
@ -57,7 +59,7 @@ public bool Read<T>(WriteToOut<T> write, T dataOut, int bytesToRead, out int byt
|
||||
}
|
||||
|
||||
public bool Read<T>(WriteToOut<T> write, T dataOut, out int bytesRead, IDisposable callback) {
|
||||
return Read(write, dataOut, resource.Length - position, out bytesRead, callback);
|
||||
return Read(write, dataOut, RemainingBytes, out bytesRead, callback);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,8 @@
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
<Platforms>x86</Platforms>
|
||||
<Configurations>Debug;Release</Configurations>
|
||||
<Platforms>x86;x64</Platforms>
|
||||
<LangVersion>9</LangVersion>
|
||||
<Nullable>enable</Nullable>
|
||||
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
||||
|
@ -2,7 +2,8 @@
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
<Platforms>x86</Platforms>
|
||||
<Configurations>Debug;Release</Configurations>
|
||||
<Platforms>x86;x64</Platforms>
|
||||
<LangVersion>9</LangVersion>
|
||||
<Nullable>enable</Nullable>
|
||||
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
||||
|
@ -7,7 +7,7 @@
|
||||
|
||||
namespace TweetLib.Core.Features.Plugins {
|
||||
public sealed class Plugin {
|
||||
private static readonly Version AppVersion = new (TweetDuck.Version.Tag);
|
||||
public static Version LibVersion { get; } = new (TweetDuck.Version.Tag);
|
||||
|
||||
public string Identifier { get; }
|
||||
public PluginGroup Group { get; }
|
||||
@ -40,7 +40,7 @@ private string DefaultConfigPath {
|
||||
private readonly string pathRoot;
|
||||
private readonly string pathData;
|
||||
private readonly ISet<PluginEnvironment> environments;
|
||||
|
||||
|
||||
private readonly string configFile;
|
||||
private readonly string configDefault;
|
||||
|
||||
@ -61,7 +61,7 @@ private Plugin(PluginGroup group, string identifier, string pathRoot, string pat
|
||||
this.configDefault = builder.ConfigDefault;
|
||||
this.RequiredVersion = builder.RequiredVersion;
|
||||
|
||||
this.CanRun = AppVersion >= RequiredVersion;
|
||||
this.CanRun = LibVersion >= RequiredVersion;
|
||||
}
|
||||
|
||||
internal bool HasEnvironment(PluginEnvironment environment) {
|
||||
@ -141,7 +141,7 @@ public Plugin BuildAndSetup() {
|
||||
}
|
||||
|
||||
if (plugin.Group == PluginGroup.Official) {
|
||||
if (plugin.RequiredVersion != AppVersion) {
|
||||
if (plugin.RequiredVersion != LibVersion) {
|
||||
throw new InvalidOperationException("Plugin is not supported in this version of TweetDuck, this may indicate a failed update or an unsupported plugin that was not removed automatically.");
|
||||
}
|
||||
else if (!string.IsNullOrEmpty(plugin.Version)) {
|
||||
|
@ -2,7 +2,8 @@
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
<Platforms>x86</Platforms>
|
||||
<Configurations>Debug;Release</Configurations>
|
||||
<Platforms>x86;x64</Platforms>
|
||||
<LangVersion>9</LangVersion>
|
||||
<Nullable>enable</Nullable>
|
||||
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
||||
@ -18,13 +19,13 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Include="$(SolutionDir)resources\Content\**\*.*">
|
||||
<Content Include="$(ProjectDir)..\..\resources\Content\**\*.*">
|
||||
<Link>Resources\Content\%(RecursiveDir)%(Filename)%(Extension)</Link>
|
||||
</Content>
|
||||
<Content Include="$(SolutionDir)resources\Guide\**\*.*">
|
||||
<Content Include="$(ProjectDir)..\..\resources\Guide\**\*.*">
|
||||
<Link>Resources\Guide\%(RecursiveDir)%(Filename)%(Extension)</Link>
|
||||
</Content>
|
||||
<Content Include="$(SolutionDir)resources\Plugins\**\*.*">
|
||||
<Content Include="$(ProjectDir)..\..\resources\Plugins\**\*.*">
|
||||
<Link>Resources\Plugins\%(RecursiveDir)%(Filename)%(Extension)</Link>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
|
@ -59,6 +59,11 @@ public SimpleObjectSerializer(TypeConverterRegistry converterRegistry) {
|
||||
}
|
||||
|
||||
public void Write(string file, T obj) {
|
||||
if (props.Count == 0) {
|
||||
File.Delete(file);
|
||||
return;
|
||||
}
|
||||
|
||||
var errors = new LinkedList<string>();
|
||||
|
||||
FileUtils.CreateDirectoryForFile(file);
|
||||
|
@ -2,7 +2,8 @@
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
<Platforms>x86</Platforms>
|
||||
<Configurations>Debug;Release</Configurations>
|
||||
<Platforms>x86;x64</Platforms>
|
||||
<LangVersion>9</LangVersion>
|
||||
<Nullable>enable</Nullable>
|
||||
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
||||
|
2
linux/.gitignore
vendored
Normal file
2
linux/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
bld/
|
||||
lib/
|
8
linux/.idea/.idea.TweetDuck.Linux/.idea/.gitignore
vendored
Normal file
8
linux/.idea/.idea.TweetDuck.Linux/.idea/.gitignore
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# Rider ignored files
|
||||
/projectSettingsUpdater.xml
|
||||
/modules.xml
|
||||
/contentModel.xml
|
||||
/.idea.TweetDuck.Linux.iml
|
1
linux/.idea/.idea.TweetDuck.Linux/.idea/.name
Normal file
1
linux/.idea/.idea.TweetDuck.Linux/.idea/.name
Normal file
@ -0,0 +1 @@
|
||||
TweetDuck.Linux
|
1
linux/.idea/.idea.TweetDuck.Linux/.idea/codeStyles
Symbolic link
1
linux/.idea/.idea.TweetDuck.Linux/.idea/codeStyles
Symbolic link
@ -0,0 +1 @@
|
||||
../../../../.idea/.idea.TweetDuck/.idea/codeStyles
|
8
linux/.idea/.idea.TweetDuck.Linux/.idea/indexLayout.xml
Normal file
8
linux/.idea/.idea.TweetDuck.Linux/.idea/indexLayout.xml
Normal file
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="UserContentModel">
|
||||
<attachedFolders />
|
||||
<explicitIncludes />
|
||||
<explicitExcludes />
|
||||
</component>
|
||||
</project>
|
1
linux/.idea/.idea.TweetDuck.Linux/.idea/inspectionProfiles
Symbolic link
1
linux/.idea/.idea.TweetDuck.Linux/.idea/inspectionProfiles
Symbolic link
@ -0,0 +1 @@
|
||||
../../../../.idea/.idea.TweetDuck/.idea/inspectionProfiles
|
11
linux/.idea/.idea.TweetDuck.Linux/.idea/vcs.xml
Normal file
11
linux/.idea/.idea.TweetDuck.Linux/.idea/vcs.xml
Normal file
@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="GitSharedSettings">
|
||||
<option name="FORCE_PUSH_PROHIBITED_PATTERNS">
|
||||
<list />
|
||||
</option>
|
||||
</component>
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
|
||||
</component>
|
||||
</project>
|
9
linux/Directory.Build.props
Normal file
9
linux/Directory.Build.props
Normal file
@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Packaging.Targets">
|
||||
<Version>0.1.220-*</Version>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
</Project>
|
46
linux/TweetDuck.Linux.sln
Normal file
46
linux/TweetDuck.Linux.sln
Normal file
@ -0,0 +1,46 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TweetDuck.Linux", "TweetDuck\TweetDuck.csproj", "{8F1110E1-F9A6-4DE0-A56B-053759876AEB}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TweetImpl.CefGlue", "TweetImpl.CefGlue\TweetImpl.CefGlue.csproj", "{E4C03F28-9717-4BBE-BEAF-62919E69FB29}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TweetLib.Core", "..\lib\TweetLib.Core\TweetLib.Core.csproj", "{E0D41A1B-4446-4B94-8A2C-40AE14B6F920}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TweetLib.Browser", "..\lib\TweetLib.Browser\TweetLib.Browser.csproj", "{4E328871-EC1D-4EA0-B833-4B4ED6C19F05}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TweetLib.Browser.CEF", "..\lib\TweetLib.Browser.CEF\TweetLib.Browser.CEF.csproj", "{37B9B83F-DE7E-49E0-8B56-AAE413C5E5FD}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TweetLib.Utils", "..\lib\TweetLib.Utils\TweetLib.Utils.csproj", "{755D7F1C-171A-436B-B233-162240601DE3}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Release|x64 = Release|x64
|
||||
Debug|x64 = Debug|x64
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{8F1110E1-F9A6-4DE0-A56B-053759876AEB}.Release|x64.ActiveCfg = Release|x64
|
||||
{8F1110E1-F9A6-4DE0-A56B-053759876AEB}.Release|x64.Build.0 = Release|x64
|
||||
{8F1110E1-F9A6-4DE0-A56B-053759876AEB}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{8F1110E1-F9A6-4DE0-A56B-053759876AEB}.Debug|x64.Build.0 = Debug|x64
|
||||
{E4C03F28-9717-4BBE-BEAF-62919E69FB29}.Release|x64.ActiveCfg = Release|x64
|
||||
{E4C03F28-9717-4BBE-BEAF-62919E69FB29}.Release|x64.Build.0 = Release|x64
|
||||
{E4C03F28-9717-4BBE-BEAF-62919E69FB29}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{E4C03F28-9717-4BBE-BEAF-62919E69FB29}.Debug|x64.Build.0 = Debug|x64
|
||||
{E0D41A1B-4446-4B94-8A2C-40AE14B6F920}.Release|x64.ActiveCfg = Release|x64
|
||||
{E0D41A1B-4446-4B94-8A2C-40AE14B6F920}.Release|x64.Build.0 = Release|x64
|
||||
{E0D41A1B-4446-4B94-8A2C-40AE14B6F920}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{E0D41A1B-4446-4B94-8A2C-40AE14B6F920}.Debug|x64.Build.0 = Debug|x64
|
||||
{4E328871-EC1D-4EA0-B833-4B4ED6C19F05}.Release|x64.ActiveCfg = Release|x64
|
||||
{4E328871-EC1D-4EA0-B833-4B4ED6C19F05}.Release|x64.Build.0 = Release|x64
|
||||
{4E328871-EC1D-4EA0-B833-4B4ED6C19F05}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{4E328871-EC1D-4EA0-B833-4B4ED6C19F05}.Debug|x64.Build.0 = Debug|x64
|
||||
{37B9B83F-DE7E-49E0-8B56-AAE413C5E5FD}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{37B9B83F-DE7E-49E0-8B56-AAE413C5E5FD}.Debug|x64.Build.0 = Debug|x64
|
||||
{37B9B83F-DE7E-49E0-8B56-AAE413C5E5FD}.Release|x64.ActiveCfg = Release|x64
|
||||
{37B9B83F-DE7E-49E0-8B56-AAE413C5E5FD}.Release|x64.Build.0 = Release|x64
|
||||
{755D7F1C-171A-436B-B233-162240601DE3}.Release|x64.ActiveCfg = Release|x64
|
||||
{755D7F1C-171A-436B-B233-162240601DE3}.Release|x64.Build.0 = Release|x64
|
||||
{755D7F1C-171A-436B-B233-162240601DE3}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{755D7F1C-171A-436B-B233-162240601DE3}.Debug|x64.Build.0 = Debug|x64
|
||||
EndGlobalSection
|
||||
EndGlobal
|
57
linux/TweetDuck/Application/ErrorHandler.cs
Normal file
57
linux/TweetDuck/Application/ErrorHandler.cs
Normal file
@ -0,0 +1,57 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Threading;
|
||||
using Gtk;
|
||||
using TweetDuck.Utils;
|
||||
using TweetImpl.CefGlue.Utils;
|
||||
using TweetLib.Core;
|
||||
using TweetLib.Core.Application;
|
||||
|
||||
namespace TweetDuck.Application {
|
||||
sealed class ErrorHandler : IAppErrorHandler {
|
||||
private readonly int originalThread = Thread.CurrentThread.ManagedThreadId;
|
||||
|
||||
public void HandleException(string caption, string message, bool canIgnore, Exception e) {
|
||||
App.Logger.Error(e.ToString());
|
||||
|
||||
Window? window = WindowManager.MainWindow;
|
||||
bool isWindowOwned = false;
|
||||
|
||||
if (window == null) {
|
||||
window = WindowManager.CreateWindow(Lib.BrandName);
|
||||
isWindowOwned = true;
|
||||
}
|
||||
|
||||
if (Thread.CurrentThread.ManagedThreadId == originalThread) {
|
||||
DoShow();
|
||||
}
|
||||
else {
|
||||
Gtk.Application.Invoke((_, _) => DoShow());
|
||||
}
|
||||
|
||||
void DoShow() {
|
||||
using var dialog = GtkUtils.CreateMessageDialog(window, MessageType.Error, caption, message, ButtonsType.None);
|
||||
dialog.AddButton("Exit", ResponseType.Close);
|
||||
|
||||
if (canIgnore) {
|
||||
dialog.AddButton("Ignore", ResponseType.Ok);
|
||||
}
|
||||
|
||||
ResponseType response = (ResponseType) dialog.Run();
|
||||
dialog.Hide();
|
||||
|
||||
if (isWindowOwned) {
|
||||
window.Dispose();
|
||||
}
|
||||
|
||||
if (response == ResponseType.Close) {
|
||||
try {
|
||||
Process.GetCurrentProcess().Kill();
|
||||
} catch {
|
||||
Environment.FailFast(message, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
30
linux/TweetDuck/Application/FileDialogs.cs
Normal file
30
linux/TweetDuck/Application/FileDialogs.cs
Normal file
@ -0,0 +1,30 @@
|
||||
using System;
|
||||
using Gtk;
|
||||
using TweetDuck.Utils;
|
||||
using TweetImpl.CefGlue.Utils;
|
||||
using TweetLib.Core.Application;
|
||||
using TweetLib.Utils.Dialogs;
|
||||
|
||||
namespace TweetDuck.Application {
|
||||
sealed class FileDialogs : IAppFileDialogs {
|
||||
public void SaveFile(SaveFileDialogSettings settings, Action<string> onAccepted) {
|
||||
Gtk.Application.Invoke(delegate {
|
||||
using FileChooserDialog dialog = new FileChooserDialog(settings.DialogTitle, WindowManager.MainWindow, FileChooserAction.Save);
|
||||
dialog.AddButton(Stock.Cancel, ResponseType.Cancel);
|
||||
dialog.AddButton(Stock.Save, ResponseType.Accept);
|
||||
dialog.DoOverwriteConfirmation = settings.OverwritePrompt;
|
||||
dialog.CurrentName = settings.FileName;
|
||||
|
||||
if (settings.Filters is {} filters) {
|
||||
foreach (var filter in filters) {
|
||||
dialog.AddFilter(GtkUtils.CreateFileFilter(filter));
|
||||
}
|
||||
}
|
||||
|
||||
if (dialog.Run() == (int) ResponseType.Accept) {
|
||||
onAccepted.Invoke(dialog.Filename);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
24
linux/TweetDuck/Application/MessageDialogs.cs
Normal file
24
linux/TweetDuck/Application/MessageDialogs.cs
Normal file
@ -0,0 +1,24 @@
|
||||
using Gtk;
|
||||
using TweetDuck.Utils;
|
||||
using TweetImpl.CefGlue.Utils;
|
||||
using TweetLib.Core.Application;
|
||||
|
||||
namespace TweetDuck.Application {
|
||||
sealed class MessageDialogs : IAppMessageDialogs {
|
||||
public static void Show(MessageType type, string caption, string text) {
|
||||
Gtk.Application.Invoke(delegate {
|
||||
using var dialog = GtkUtils.CreateMessageDialog(WindowManager.MainWindow!, type, caption, text, ButtonsType.Ok);
|
||||
dialog.Run();
|
||||
dialog.Hide();
|
||||
});
|
||||
}
|
||||
|
||||
public void Information(string caption, string text) {
|
||||
Show(MessageType.Info, caption, text);
|
||||
}
|
||||
|
||||
public void Error(string caption, string text) {
|
||||
Show(MessageType.Error, caption, text);
|
||||
}
|
||||
}
|
||||
}
|
32
linux/TweetDuck/Application/SystemHandler.cs
Normal file
32
linux/TweetDuck/Application/SystemHandler.cs
Normal file
@ -0,0 +1,32 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using TweetLib.Core.Application;
|
||||
|
||||
namespace TweetDuck.Application {
|
||||
sealed class SystemHandler : IAppSystemHandler {
|
||||
public void OpenBrowser(string? url) {
|
||||
if (string.IsNullOrWhiteSpace(url)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Console.WriteLine(url);
|
||||
using (Process.Start(new ProcessStartInfo {
|
||||
FileName = url,
|
||||
ErrorDialog = true,
|
||||
UseShellExecute = true
|
||||
})) {}
|
||||
}
|
||||
|
||||
public void OpenFileExplorer(string path) {
|
||||
using (Process.Start("xdg-open", path)) {}
|
||||
}
|
||||
|
||||
public IAppSystemHandler.OpenAssociatedProgramFunc? OpenAssociatedProgram => null;
|
||||
|
||||
public IAppSystemHandler.CopyImageFromFileFunc? CopyImageFromFile => null;
|
||||
|
||||
public IAppSystemHandler.CopyTextFunc? CopyText => null;
|
||||
|
||||
public IAppSystemHandler.SearchTextFunc? SearchText => null;
|
||||
}
|
||||
}
|
13
linux/TweetDuck/Browser/Base/CefBrowserComponent.cs
Normal file
13
linux/TweetDuck/Browser/Base/CefBrowserComponent.cs
Normal file
@ -0,0 +1,13 @@
|
||||
using Gtk;
|
||||
using Lunixo.ChromiumGtk;
|
||||
using TweetImpl.CefGlue.Component;
|
||||
using TweetLib.Browser.CEF.Utils;
|
||||
using TweetLib.Core;
|
||||
|
||||
namespace TweetDuck.Browser.Base {
|
||||
sealed class CefBrowserComponent : BrowserComponentBase {
|
||||
public override string CacheFolder => CefUtils.GetCacheFolder(App.StoragePath);
|
||||
|
||||
public CefBrowserComponent(Window window, WebView view, CreateContextMenu createContextMenu, bool autoReload = true) : base(window, view.Browser, createContextMenu, autoReload) {}
|
||||
}
|
||||
}
|
95
linux/TweetDuck/Browser/Base/ContextMenuBase.cs
Normal file
95
linux/TweetDuck/Browser/Base/ContextMenuBase.cs
Normal file
@ -0,0 +1,95 @@
|
||||
using System;
|
||||
using TweetImpl.CefGlue.Handlers;
|
||||
using TweetLib.Browser.Contexts;
|
||||
using TweetLib.Browser.Interfaces;
|
||||
using TweetLib.Core.Features.TweetDeck;
|
||||
using TweetLib.Core.Features.Twitter;
|
||||
using Xilium.CefGlue;
|
||||
|
||||
namespace TweetDuck.Browser.Base {
|
||||
class ContextMenuBase : ContextMenuHandler {
|
||||
private DevTools? devTools;
|
||||
|
||||
protected ContextMenuBase(IContextMenuHandler? handler) : base(handler) {}
|
||||
|
||||
protected override Context CreateContext(CefContextMenuParams parameters) {
|
||||
return CreateContext(parameters, null, ImageQuality.Best);
|
||||
}
|
||||
|
||||
protected override void OnBeforeContextMenu(CefBrowser browser, CefFrame frame, CefContextMenuParams state, CefMenuModel model) {
|
||||
base.OnBeforeContextMenu(browser, frame, state, model);
|
||||
AddSeparator(model);
|
||||
model.AddItem(26500, "Open dev tools");
|
||||
}
|
||||
|
||||
protected override bool OnContextMenuCommand(CefBrowser browser, CefFrame frame, CefContextMenuParams state, int commandId, CefEventFlags eventFlags) {
|
||||
if (base.OnContextMenuCommand(browser, frame, state, commandId, eventFlags)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (commandId == 26500) {
|
||||
devTools ??= new DevTools(browser.GetHost());
|
||||
devTools.Disposed += OnDevToolsDisposed;
|
||||
devTools.Show(state.X, state.Y);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private void OnDevToolsDisposed(object? sender, EventArgs e) {
|
||||
devTools = null;
|
||||
}
|
||||
|
||||
private static void AddSeparator(CefMenuModel model) {
|
||||
if (model.Count > 0 && model.GetItemTypeAt(model.Count - 1) != CefMenuItemType.Separator) {
|
||||
model.AddSeparator();
|
||||
}
|
||||
}
|
||||
|
||||
protected static Context CreateContext(CefContextMenuParams parameters, TweetDeckExtraContext? extraContext, ImageQuality imageQuality) {
|
||||
var context = new Context();
|
||||
var flags = parameters.ContextMenuType;
|
||||
|
||||
var tweet = extraContext?.Tweet;
|
||||
if (tweet != null && !flags.HasFlag(CefContextMenuTypeFlags.Editable)) {
|
||||
context.Tweet = tweet;
|
||||
}
|
||||
|
||||
context.Link = GetLink(parameters, extraContext);
|
||||
context.Media = GetMedia(parameters, extraContext, imageQuality);
|
||||
|
||||
if (flags.HasFlag(CefContextMenuTypeFlags.Selection)) {
|
||||
context.Selection = new Selection(parameters.SelectionText, flags.HasFlag(CefContextMenuTypeFlags.Editable));
|
||||
}
|
||||
|
||||
return context;
|
||||
}
|
||||
|
||||
private static Link? GetLink(CefContextMenuParams parameters, TweetDeckExtraContext? extraContext) {
|
||||
var link = extraContext?.Link;
|
||||
if (link != null) {
|
||||
return link;
|
||||
}
|
||||
|
||||
if (parameters.ContextMenuType.HasFlag(CefContextMenuTypeFlags.Link) && extraContext?.Media == null) {
|
||||
return new Link(parameters.LinkUrl, parameters.UnfilteredLinkUrl);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private static Media? GetMedia(CefContextMenuParams parameters, TweetDeckExtraContext? extraContext, ImageQuality imageQuality) {
|
||||
var media = extraContext?.Media;
|
||||
if (media != null) {
|
||||
return media;
|
||||
}
|
||||
|
||||
if (parameters.ContextMenuType.HasFlag(CefContextMenuTypeFlags.Media) && parameters.HasImageContents) {
|
||||
return new Media(Media.Type.Image, TwitterUrls.GetMediaLink(parameters.SourceUrl, imageQuality));
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
32
linux/TweetDuck/Browser/Base/ContextMenuBrowser.cs
Normal file
32
linux/TweetDuck/Browser/Base/ContextMenuBrowser.cs
Normal file
@ -0,0 +1,32 @@
|
||||
using TweetLib.Browser.Contexts;
|
||||
using TweetLib.Browser.Interfaces;
|
||||
using TweetLib.Core.Features.TweetDeck;
|
||||
using TweetLib.Core.Features.Twitter;
|
||||
using Xilium.CefGlue;
|
||||
|
||||
namespace TweetDuck.Browser.Base {
|
||||
sealed class ContextMenuBrowser : ContextMenuBase {
|
||||
private readonly TweetDeckExtraContext extraContext;
|
||||
|
||||
public ContextMenuBrowser(IContextMenuHandler? handler, TweetDeckExtraContext extraContext) : base(handler) {
|
||||
this.extraContext = extraContext;
|
||||
}
|
||||
|
||||
protected override Context CreateContext(CefContextMenuParams parameters) {
|
||||
return CreateContext(parameters, extraContext, ImageQuality.Best);
|
||||
}
|
||||
|
||||
protected override void OnBeforeContextMenu(CefBrowser browser, CefFrame frame, CefContextMenuParams state, CefMenuModel model) {
|
||||
if (!TwitterUrls.IsTweetDeck(frame.Url) || browser.IsLoading) {
|
||||
extraContext.Reset();
|
||||
}
|
||||
|
||||
base.OnBeforeContextMenu(browser, frame, state, model);
|
||||
}
|
||||
|
||||
protected override void OnContextMenuDismissed(CefBrowser browser, CefFrame frame) {
|
||||
base.OnContextMenuDismissed(browser, frame);
|
||||
extraContext.Reset();
|
||||
}
|
||||
}
|
||||
}
|
19
linux/TweetDuck/Browser/Base/PopupHandler.cs
Normal file
19
linux/TweetDuck/Browser/Base/PopupHandler.cs
Normal file
@ -0,0 +1,19 @@
|
||||
using TweetLib.Browser.CEF.Interfaces;
|
||||
using TweetLib.Core;
|
||||
using TweetLib.Core.Features.Twitter;
|
||||
|
||||
namespace TweetDuck.Browser.Base {
|
||||
sealed class PopupHandler : IPopupHandler {
|
||||
public static PopupHandler Instance { get; } = new ();
|
||||
|
||||
private PopupHandler() {}
|
||||
|
||||
public bool IsPopupAllowed(string url) {
|
||||
return TwitterUrls.IsAllowedPopupUrl(url);
|
||||
}
|
||||
|
||||
public void OpenExternalBrowser(string url) {
|
||||
App.SystemHandler.OpenBrowser(url);
|
||||
}
|
||||
}
|
||||
}
|
54
linux/TweetDuck/Browser/DevTools.cs
Normal file
54
linux/TweetDuck/Browser/DevTools.cs
Normal file
@ -0,0 +1,54 @@
|
||||
using System;
|
||||
using Gtk;
|
||||
using Lunixo.ChromiumGtk.Interop;
|
||||
using TweetDuck.Utils;
|
||||
using Xilium.CefGlue;
|
||||
|
||||
namespace TweetDuck.Browser {
|
||||
sealed class DevTools : IDisposable {
|
||||
public event EventHandler? Disposed;
|
||||
|
||||
private readonly CefBrowserHost host;
|
||||
private readonly Window window;
|
||||
private bool isShown;
|
||||
private int initialX, initialY;
|
||||
|
||||
public DevTools(CefBrowserHost host) {
|
||||
this.host = host;
|
||||
this.window = WindowManager.CreateWindow("Dev Tools");
|
||||
this.window.SizeAllocated += WindowOnSizeAllocated;
|
||||
this.window.Destroyed += (_, _) => Dispose();
|
||||
}
|
||||
|
||||
private void WindowOnSizeAllocated(object o, SizeAllocatedArgs args) {
|
||||
if (args.Allocation.Width != 200) {
|
||||
isShown = true;
|
||||
window.SizeAllocated -= WindowOnSizeAllocated;
|
||||
Show(initialX, initialY);
|
||||
}
|
||||
}
|
||||
|
||||
public void Show(int x, int y) {
|
||||
if (!isShown) {
|
||||
initialX = x;
|
||||
initialY = y;
|
||||
window.ShowAll();
|
||||
return;
|
||||
}
|
||||
|
||||
var xid = InteropLinux.gdk_x11_window_get_xid(InteropLinux.gtk_widget_get_window(window.Handle));
|
||||
var windowInfo = CefWindowInfo.Create();
|
||||
windowInfo.SetAsChild(xid, new CefRectangle(0, 0, window.AllocatedWidth, window.AllocatedHeight));
|
||||
host.ShowDevTools(windowInfo, new DummyClient(), new CefBrowserSettings(), new CefPoint(x, y));
|
||||
window.Present();
|
||||
}
|
||||
|
||||
public void Dispose() {
|
||||
host.CloseDevTools();
|
||||
host.Dispose();
|
||||
Disposed?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
|
||||
private sealed class DummyClient : CefClient {}
|
||||
}
|
||||
}
|
102
linux/TweetDuck/Browser/TweetDeckBrowser.cs
Normal file
102
linux/TweetDuck/Browser/TweetDeckBrowser.cs
Normal file
@ -0,0 +1,102 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Gtk;
|
||||
using Lunixo.ChromiumGtk;
|
||||
using TweetDuck.Application;
|
||||
using TweetDuck.Browser.Base;
|
||||
using TweetImpl.CefGlue.Component;
|
||||
using TweetLib.Core;
|
||||
using TweetLib.Core.Features;
|
||||
using TweetLib.Core.Features.Notifications;
|
||||
using TweetLib.Core.Features.Plugins;
|
||||
using TweetLib.Core.Features.TweetDeck;
|
||||
using TweetLib.Core.Features.Twitter;
|
||||
using TweetDeckBrowserImpl = TweetLib.Core.Features.TweetDeck.TweetDeckBrowser;
|
||||
|
||||
namespace TweetDuck.Browser {
|
||||
sealed class TweetDeckBrowser : ISoundNotificationHandler, IDisposable {
|
||||
public WebView View { get; }
|
||||
|
||||
public TweetDeckBrowser(Window window, PluginManager pluginManager) {
|
||||
this.View = CustomWebClient.CreateWebView(PopupHandler.Instance);
|
||||
|
||||
var extraContext = new TweetDeckExtraContext();
|
||||
var browserComponent = new CefBrowserComponent(window, View, handler => new ContextMenuBrowser(handler, extraContext));
|
||||
var _ = new TweetDeckBrowserImpl(browserComponent, new TweetDeckInterfaceImpl(this), extraContext, this, pluginManager);
|
||||
|
||||
View.LoadUrl(TwitterUrls.TweetDeck);
|
||||
}
|
||||
|
||||
public void Dispose() {
|
||||
View.Dispose();
|
||||
}
|
||||
|
||||
private sealed class TweetDeckInterfaceImpl : ITweetDeckInterface {
|
||||
private readonly TweetDeckBrowser owner;
|
||||
|
||||
public TweetDeckInterfaceImpl(TweetDeckBrowser owner) {
|
||||
this.owner = owner;
|
||||
}
|
||||
|
||||
void ICommonInterface.Alert(string type, string contents) {
|
||||
MessageType messageType = type switch {
|
||||
"error" => MessageType.Error,
|
||||
"warning" => MessageType.Warning,
|
||||
"info" => MessageType.Error,
|
||||
_ => MessageType.Other
|
||||
};
|
||||
|
||||
MessageDialogs.Show(messageType, "TweetDuck Browser Message", contents);
|
||||
}
|
||||
|
||||
void ICommonInterface.DisplayTooltip(string? text) {
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
void ICommonInterface.FixClipboard() {}
|
||||
|
||||
int ICommonInterface.GetIdleSeconds() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ICommonInterface.OnSoundNotification() {
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
void ICommonInterface.PlayVideo(string videoUrl, string tweetUrl, string username, object callShowOverlay) {
|
||||
App.SystemHandler.OpenBrowser(videoUrl);
|
||||
}
|
||||
|
||||
void ICommonInterface.ScreenshotTweet(string html, int width) {
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
void ICommonInterface.ShowDesktopNotification(DesktopNotification notification) {
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
void ICommonInterface.StopVideo() {
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
void ITweetDeckInterface.OnIntroductionClosed(bool showGuide) {
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
void ITweetDeckInterface.OpenContextMenu() {
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
void ITweetDeckInterface.OpenProfileImport() {
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
Task ICommonInterface.ExecuteCallback(object callback, params object[] parameters) {
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
}
|
||||
|
||||
void ISoundNotificationHandler.Unregister(string url) {}
|
||||
void ISoundNotificationHandler.Register(string url, string path) {}
|
||||
}
|
||||
}
|
12
linux/TweetDuck/Configuration/SystemConfiguration.cs
Normal file
12
linux/TweetDuck/Configuration/SystemConfiguration.cs
Normal file
@ -0,0 +1,12 @@
|
||||
using TweetLib.Core.Application;
|
||||
using TweetLib.Core.Systems.Configuration;
|
||||
|
||||
namespace TweetDuck.Configuration {
|
||||
sealed class SystemConfiguration : IConfigObject<SystemConfiguration>, IAppSystemConfiguration {
|
||||
public bool UseSystemProxyForAllConnections => true;
|
||||
|
||||
public SystemConfiguration ConstructWithDefaults() {
|
||||
return new SystemConfiguration();
|
||||
}
|
||||
}
|
||||
}
|
38
linux/TweetDuck/Configuration/UserConfiguration.cs
Normal file
38
linux/TweetDuck/Configuration/UserConfiguration.cs
Normal file
@ -0,0 +1,38 @@
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using TweetLib.Core.Application;
|
||||
using TweetLib.Core.Features.Twitter;
|
||||
using TweetLib.Core.Systems.Configuration;
|
||||
|
||||
namespace TweetDuck.Configuration {
|
||||
[SuppressMessage("ReSharper", "AutoPropertyCanBeMadeGetOnly.Global")]
|
||||
sealed class UserConfiguration : IConfigObject<UserConfiguration>, IAppUserConfiguration {
|
||||
public string CustomBrowserCSS => string.Empty;
|
||||
public string CustomNotificationCSS => string.Empty;
|
||||
public string? DismissedUpdate => null;
|
||||
public bool ExpandLinksOnHover => true;
|
||||
public bool FirstRun => false;
|
||||
public bool IsCustomSoundNotificationSet => false;
|
||||
public bool MuteNotifications => false;
|
||||
public bool NotificationMediaPreviews => false;
|
||||
public bool NotificationSkipOnLinkClick => false;
|
||||
public string NotificationSoundPath => string.Empty;
|
||||
public int NotificationSoundVolume => 0;
|
||||
|
||||
public bool FocusDmInput { get; set; } = false;
|
||||
public bool HideTweetsByNftUsers { get; set; } = false;
|
||||
public bool KeepLikeFollowDialogsOpen { get; set; } = false;
|
||||
public bool OpenSearchInFirstColumn { get; set; } = false;
|
||||
public int CalendarFirstDay { get; set; } = JQuery.GetDatePickerDayOfWeek(DayOfWeek.Monday);
|
||||
public string TranslationTarget { get; set; } = "en";
|
||||
public ImageQuality TwitterImageQuality { get; set; } = ImageQuality.Best;
|
||||
|
||||
public event EventHandler? MuteToggled;
|
||||
public event EventHandler? OptionsDialogClosed;
|
||||
public event EventHandler? SoundNotificationChanged;
|
||||
|
||||
public UserConfiguration ConstructWithDefaults() {
|
||||
return new UserConfiguration();
|
||||
}
|
||||
}
|
||||
}
|
138
linux/TweetDuck/Program.cs
Normal file
138
linux/TweetDuck/Program.cs
Normal file
@ -0,0 +1,138 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using Lunixo.ChromiumGtk.Core;
|
||||
using TweetDuck.Application;
|
||||
using TweetDuck.Configuration;
|
||||
using TweetDuck.Utils;
|
||||
using TweetImpl.CefGlue.Utils;
|
||||
using TweetLib.Browser.Request;
|
||||
using TweetLib.Core;
|
||||
using TweetLib.Core.Application;
|
||||
using TweetLib.Core.Features.Plugins;
|
||||
using TweetLib.Core.Features.Plugins.Config;
|
||||
using TweetLib.Core.Features.TweetDeck;
|
||||
using TweetLib.Core.Systems.Configuration;
|
||||
using TweetLib.Utils.Collections;
|
||||
using Xilium.CefGlue;
|
||||
using TweetDeckBrowser = TweetDuck.Browser.TweetDeckBrowser;
|
||||
|
||||
namespace TweetDuck {
|
||||
static class Program {
|
||||
private const string CefDataFolder = "TD_Chromium";
|
||||
private const string ConsoleLogFile = "TD_Console.txt";
|
||||
|
||||
[STAThread]
|
||||
private static void Main(string[] args) {
|
||||
var arguments = CommandLineArgs.FromStringArray('-', args);
|
||||
if (arguments.HasFlag("-appversion")) {
|
||||
var version = Assembly.GetEntryAssembly()?.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?.InformationalVersion;
|
||||
version = version?[..version.LastIndexOf('.')];
|
||||
Console.WriteLine(version ?? "unknown");
|
||||
return;
|
||||
}
|
||||
else if (arguments.HasFlag("-pluginversion")) {
|
||||
Console.WriteLine(Plugin.LibVersion);
|
||||
return;
|
||||
}
|
||||
|
||||
AppDomain.CurrentDomain.UnhandledException += OnUnhandledException;
|
||||
|
||||
Gtk.Application.Init();
|
||||
|
||||
Lib.AppLauncher launch = Lib.Initialize(new AppBuilder {
|
||||
Setup = new Setup(arguments),
|
||||
ErrorHandler = new ErrorHandler(),
|
||||
SystemHandler = new SystemHandler(),
|
||||
MessageDialogs = new MessageDialogs(),
|
||||
FileDialogs = new FileDialogs()
|
||||
});
|
||||
|
||||
launch();
|
||||
}
|
||||
|
||||
private static void OnUnhandledException(object sender, UnhandledExceptionEventArgs e) {
|
||||
Debug.WriteLine(e.ExceptionObject);
|
||||
}
|
||||
|
||||
private sealed class Setup : IAppSetup {
|
||||
public bool IsPortable { get; }
|
||||
public bool IsDebugLogging => true;
|
||||
public string? CustomDataFolder { get; }
|
||||
public string? ResourceRewriteRules => null;
|
||||
|
||||
public Setup(CommandLineArgs args) {
|
||||
CustomDataFolder = args.GetValue("-datafolder");
|
||||
IsPortable = CustomDataFolder == null;
|
||||
}
|
||||
|
||||
public ConfigManager CreateConfigManager(string storagePath) {
|
||||
var objects = new ConfigObjects<UserConfiguration, SystemConfiguration>(
|
||||
new UserConfiguration(),
|
||||
new SystemConfiguration(),
|
||||
new PluginConfig(Array.Empty<string>())
|
||||
);
|
||||
|
||||
return new ConfigManager<UserConfiguration, SystemConfiguration>(storagePath, objects);
|
||||
}
|
||||
|
||||
public bool TryLockDataFolder(string lockFile) {
|
||||
return true;
|
||||
}
|
||||
|
||||
public void BeforeLaunch() {}
|
||||
|
||||
public void Launch(ResourceCache resourceCache, PluginManager pluginManager) {
|
||||
var programPath = App.ProgramPath;
|
||||
var storagePath = App.StoragePath;
|
||||
|
||||
#if DEBUG
|
||||
const CefLogSeverity LogSeverity = CefLogSeverity.Debug;
|
||||
#else
|
||||
const CefLogSeverity LogSeverity = CefLogSeverity.Disable;
|
||||
#endif
|
||||
|
||||
var runtime = new Runtime(new CefSettings {
|
||||
BackgroundColor = new CefColor(255, 28, 99, 153),
|
||||
CachePath = storagePath,
|
||||
BrowserSubprocessPath = Path.Combine(programPath, Lib.BrandName + ".Browser"),
|
||||
UserDataPath = Path.Combine(storagePath, CefDataFolder),
|
||||
LogFile = Path.Combine(storagePath, ConsoleLogFile),
|
||||
LogSeverity = LogSeverity,
|
||||
MultiThreadedMessageLoop = false,
|
||||
ExternalMessagePump = false
|
||||
}, Array.Empty<string>());
|
||||
|
||||
runtime.Initialize(new CustomCefApp(resourceCache, pluginManager));
|
||||
|
||||
using var window = WindowManager.CreateMainWindow(Lib.BrandName);
|
||||
window.Destroyed += (_, _) => {
|
||||
runtime.QuitMessageLoop();
|
||||
App.Close();
|
||||
};
|
||||
|
||||
using var tweetDeckBrowser = new TweetDeckBrowser(window, pluginManager);
|
||||
window.Add(tweetDeckBrowser.View);
|
||||
window.ShowAll();
|
||||
runtime.RunMessageLoop();
|
||||
runtime.Shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
private sealed class CustomCefApp : CefApp {
|
||||
private readonly ResourceCache resourceCache;
|
||||
private readonly PluginManager pluginManager;
|
||||
|
||||
public CustomCefApp(ResourceCache resourceCache, PluginManager pluginManager) {
|
||||
this.resourceCache = resourceCache;
|
||||
this.pluginManager = pluginManager;
|
||||
}
|
||||
|
||||
protected override void OnRegisterCustomSchemes(CefSchemeRegistrar registrar) {
|
||||
SchemeHandlerFactory.Register(registrar, new TweetDuckSchemeHandler(resourceCache));
|
||||
SchemeHandlerFactory.Register(registrar, new PluginSchemeHandler(resourceCache, pluginManager));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
548
linux/TweetDuck/Resources/LICENSES.txt
Normal file
548
linux/TweetDuck/Resources/LICENSES.txt
Normal file
@ -0,0 +1,548 @@
|
||||
===============================================================================
|
||||
ChromiumGtk
|
||||
===============================================================================
|
||||
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2020 Lunixo GmbH
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
||||
|
||||
|
||||
===============================================================================
|
||||
Chromium Embedded Framework
|
||||
===============================================================================
|
||||
|
||||
// Copyright (c) 2008-2020 Marshall A. Greenblatt. Portions Copyright (c)
|
||||
// 2006-2009 Google Inc. All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the name Chromium Embedded
|
||||
// Framework nor the names of its contributors may be used to endorse
|
||||
// or promote products derived from this software without specific prior
|
||||
// written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
|
||||
|
||||
===============================================================================
|
||||
GtkSharp
|
||||
===============================================================================
|
||||
|
||||
GNU LIBRARY GENERAL PUBLIC LICENSE
|
||||
Version 2, June 1991
|
||||
|
||||
Copyright (C) 1991 Free Software Foundation, Inc.
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
[This is the first released version of the library GPL. It is
|
||||
numbered 2 because it goes with version 2 of the ordinary GPL.]
|
||||
|
||||
Preamble
|
||||
|
||||
The licenses for most software are designed to take away your
|
||||
freedom to share and change it. By contrast, the GNU General Public
|
||||
Licenses are intended to guarantee your freedom to share and change
|
||||
free software--to make sure the software is free for all its users.
|
||||
|
||||
This license, the Library General Public License, applies to some
|
||||
specially designated Free Software Foundation software, and to any
|
||||
other libraries whose authors decide to use it. You can use it for
|
||||
your libraries, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
this service if you wish), that you receive source code or can get it
|
||||
if you want it, that you can change the software or use pieces of it
|
||||
in new free programs; and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to make restrictions that forbid
|
||||
anyone to deny you these rights or to ask you to surrender the rights.
|
||||
These restrictions translate to certain responsibilities for you if
|
||||
you distribute copies of the library, or if you modify it.
|
||||
|
||||
For example, if you distribute copies of the library, whether gratis
|
||||
or for a fee, you must give the recipients all the rights that we gave
|
||||
you. You must make sure that they, too, receive or can get the source
|
||||
code. If you link a program with the library, you must provide
|
||||
complete object files to the recipients so that they can relink them
|
||||
with the library, after making changes to the library and recompiling
|
||||
it. And you must show them these terms so they know their rights.
|
||||
|
||||
Our method of protecting your rights has two steps: (1) copyright
|
||||
the library, and (2) offer you this license which gives you legal
|
||||
permission to copy, distribute and/or modify the library.
|
||||
|
||||
Also, for each distributor's protection, we want to make certain
|
||||
that everyone understands that there is no warranty for this free
|
||||
library. If the library is modified by someone else and passed on, we
|
||||
want its recipients to know that what they have is not the original
|
||||
version, so that any problems introduced by others will not reflect on
|
||||
the original authors' reputations.
|
||||
|
||||
Finally, any free program is threatened constantly by software
|
||||
patents. We wish to avoid the danger that companies distributing free
|
||||
software will individually obtain patent licenses, thus in effect
|
||||
transforming the program into proprietary software. To prevent this,
|
||||
we have made it clear that any patent must be licensed for everyone's
|
||||
free use or not licensed at all.
|
||||
|
||||
Most GNU software, including some libraries, is covered by the ordinary
|
||||
GNU General Public License, which was designed for utility programs. This
|
||||
license, the GNU Library General Public License, applies to certain
|
||||
designated libraries. This license is quite different from the ordinary
|
||||
one; be sure to read it in full, and don't assume that anything in it is
|
||||
the same as in the ordinary license.
|
||||
|
||||
The reason we have a separate public license for some libraries is that
|
||||
they blur the distinction we usually make between modifying or adding to a
|
||||
program and simply using it. Linking a program with a library, without
|
||||
changing the library, is in some sense simply using the library, and is
|
||||
analogous to running a utility program or application program. However, in
|
||||
a textual and legal sense, the linked executable is a combined work, a
|
||||
derivative of the original library, and the ordinary General Public License
|
||||
treats it as such.
|
||||
|
||||
Because of this blurred distinction, using the ordinary General
|
||||
Public License for libraries did not effectively promote software
|
||||
sharing, because most developers did not use the libraries. We
|
||||
concluded that weaker conditions might promote sharing better.
|
||||
|
||||
However, unrestricted linking of non-free programs would deprive the
|
||||
users of those programs of all benefit from the free status of the
|
||||
libraries themselves. This Library General Public License is intended to
|
||||
permit developers of non-free programs to use free libraries, while
|
||||
preserving your freedom as a user of such programs to change the free
|
||||
libraries that are incorporated in them. (We have not seen how to achieve
|
||||
this as regards changes in header files, but we have achieved it as regards
|
||||
changes in the actual functions of the Library.) The hope is that this
|
||||
will lead to faster development of free libraries.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow. Pay close attention to the difference between a
|
||||
"work based on the library" and a "work that uses the library". The
|
||||
former contains code derived from the library, while the latter only
|
||||
works together with the library.
|
||||
|
||||
Note that it is possible for a library to be covered by the ordinary
|
||||
General Public License rather than by this special one.
|
||||
|
||||
GNU LIBRARY GENERAL PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License Agreement applies to any software library which
|
||||
contains a notice placed by the copyright holder or other authorized
|
||||
party saying it may be distributed under the terms of this Library
|
||||
General Public License (also called "this License"). Each licensee is
|
||||
addressed as "you".
|
||||
|
||||
A "library" means a collection of software functions and/or data
|
||||
prepared so as to be conveniently linked with application programs
|
||||
(which use some of those functions and data) to form executables.
|
||||
|
||||
The "Library", below, refers to any such software library or work
|
||||
which has been distributed under these terms. A "work based on the
|
||||
Library" means either the Library or any derivative work under
|
||||
copyright law: that is to say, a work containing the Library or a
|
||||
portion of it, either verbatim or with modifications and/or translated
|
||||
straightforwardly into another language. (Hereinafter, translation is
|
||||
included without limitation in the term "modification".)
|
||||
|
||||
"Source code" for a work means the preferred form of the work for
|
||||
making modifications to it. For a library, complete source code means
|
||||
all the source code for all modules it contains, plus any associated
|
||||
interface definition files, plus the scripts used to control compilation
|
||||
and installation of the library.
|
||||
|
||||
Activities other than copying, distribution and modification are not
|
||||
covered by this License; they are outside its scope. The act of
|
||||
running a program using the Library is not restricted, and output from
|
||||
such a program is covered only if its contents constitute a work based
|
||||
on the Library (independent of the use of the Library in a tool for
|
||||
writing it). Whether that is true depends on what the Library does
|
||||
and what the program that uses the Library does.
|
||||
|
||||
1. You may copy and distribute verbatim copies of the Library's
|
||||
complete source code as you receive it, in any medium, provided that
|
||||
you conspicuously and appropriately publish on each copy an
|
||||
appropriate copyright notice and disclaimer of warranty; keep intact
|
||||
all the notices that refer to this License and to the absence of any
|
||||
warranty; and distribute a copy of this License along with the
|
||||
Library.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy,
|
||||
and you may at your option offer warranty protection in exchange for a
|
||||
fee.
|
||||
|
||||
2. You may modify your copy or copies of the Library or any portion
|
||||
of it, thus forming a work based on the Library, and copy and
|
||||
distribute such modifications or work under the terms of Section 1
|
||||
above, provided that you also meet all of these conditions:
|
||||
|
||||
a) The modified work must itself be a software library.
|
||||
|
||||
b) You must cause the files modified to carry prominent notices
|
||||
stating that you changed the files and the date of any change.
|
||||
|
||||
c) You must cause the whole of the work to be licensed at no
|
||||
charge to all third parties under the terms of this License.
|
||||
|
||||
d) If a facility in the modified Library refers to a function or a
|
||||
table of data to be supplied by an application program that uses
|
||||
the facility, other than as an argument passed when the facility
|
||||
is invoked, then you must make a good faith effort to ensure that,
|
||||
in the event an application does not supply such function or
|
||||
table, the facility still operates, and performs whatever part of
|
||||
its purpose remains meaningful.
|
||||
|
||||
(For example, a function in a library to compute square roots has
|
||||
a purpose that is entirely well-defined independent of the
|
||||
application. Therefore, Subsection 2d requires that any
|
||||
application-supplied function or table used by this function must
|
||||
be optional: if the application does not supply it, the square
|
||||
root function must still compute square roots.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If
|
||||
identifiable sections of that work are not derived from the Library,
|
||||
and can be reasonably considered independent and separate works in
|
||||
themselves, then this License, and its terms, do not apply to those
|
||||
sections when you distribute them as separate works. But when you
|
||||
distribute the same sections as part of a whole which is a work based
|
||||
on the Library, the distribution of the whole must be on the terms of
|
||||
this License, whose permissions for other licensees extend to the
|
||||
entire whole, and thus to each and every part regardless of who wrote
|
||||
it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest
|
||||
your rights to work written entirely by you; rather, the intent is to
|
||||
exercise the right to control the distribution of derivative or
|
||||
collective works based on the Library.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Library
|
||||
with the Library (or with a work based on the Library) on a volume of
|
||||
a storage or distribution medium does not bring the other work under
|
||||
the scope of this License.
|
||||
|
||||
3. You may opt to apply the terms of the ordinary GNU General Public
|
||||
License instead of this License to a given copy of the Library. To do
|
||||
this, you must alter all the notices that refer to this License, so
|
||||
that they refer to the ordinary GNU General Public License, version 2,
|
||||
instead of to this License. (If a newer version than version 2 of the
|
||||
ordinary GNU General Public License has appeared, then you can specify
|
||||
that version instead if you wish.) Do not make any other change in
|
||||
these notices.
|
||||
|
||||
Once this change is made in a given copy, it is irreversible for
|
||||
that copy, so the ordinary GNU General Public License applies to all
|
||||
subsequent copies and derivative works made from that copy.
|
||||
|
||||
This option is useful when you wish to copy part of the code of
|
||||
the Library into a program that is not a library.
|
||||
|
||||
4. You may copy and distribute the Library (or a portion or
|
||||
derivative of it, under Section 2) in object code or executable form
|
||||
under the terms of Sections 1 and 2 above provided that you accompany
|
||||
it with the complete corresponding machine-readable source code, which
|
||||
must be distributed under the terms of Sections 1 and 2 above on a
|
||||
medium customarily used for software interchange.
|
||||
|
||||
If distribution of object code is made by offering access to copy
|
||||
from a designated place, then offering equivalent access to copy the
|
||||
source code from the same place satisfies the requirement to
|
||||
distribute the source code, even though third parties are not
|
||||
compelled to copy the source along with the object code.
|
||||
|
||||
5. A program that contains no derivative of any portion of the
|
||||
Library, but is designed to work with the Library by being compiled or
|
||||
linked with it, is called a "work that uses the Library". Such a
|
||||
work, in isolation, is not a derivative work of the Library, and
|
||||
therefore falls outside the scope of this License.
|
||||
|
||||
However, linking a "work that uses the Library" with the Library
|
||||
creates an executable that is a derivative of the Library (because it
|
||||
contains portions of the Library), rather than a "work that uses the
|
||||
library". The executable is therefore covered by this License.
|
||||
Section 6 states terms for distribution of such executables.
|
||||
|
||||
When a "work that uses the Library" uses material from a header file
|
||||
that is part of the Library, the object code for the work may be a
|
||||
derivative work of the Library even though the source code is not.
|
||||
Whether this is true is especially significant if the work can be
|
||||
linked without the Library, or if the work is itself a library. The
|
||||
threshold for this to be true is not precisely defined by law.
|
||||
|
||||
If such an object file uses only numerical parameters, data
|
||||
structure layouts and accessors, and small macros and small inline
|
||||
functions (ten lines or less in length), then the use of the object
|
||||
file is unrestricted, regardless of whether it is legally a derivative
|
||||
work. (Executables containing this object code plus portions of the
|
||||
Library will still fall under Section 6.)
|
||||
|
||||
Otherwise, if the work is a derivative of the Library, you may
|
||||
distribute the object code for the work under the terms of Section 6.
|
||||
Any executables containing that work also fall under Section 6,
|
||||
whether or not they are linked directly with the Library itself.
|
||||
|
||||
6. As an exception to the Sections above, you may also compile or
|
||||
link a "work that uses the Library" with the Library to produce a
|
||||
work containing portions of the Library, and distribute that work
|
||||
under terms of your choice, provided that the terms permit
|
||||
modification of the work for the customer's own use and reverse
|
||||
engineering for debugging such modifications.
|
||||
|
||||
You must give prominent notice with each copy of the work that the
|
||||
Library is used in it and that the Library and its use are covered by
|
||||
this License. You must supply a copy of this License. If the work
|
||||
during execution displays copyright notices, you must include the
|
||||
copyright notice for the Library among them, as well as a reference
|
||||
directing the user to the copy of this License. Also, you must do one
|
||||
of these things:
|
||||
|
||||
a) Accompany the work with the complete corresponding
|
||||
machine-readable source code for the Library including whatever
|
||||
changes were used in the work (which must be distributed under
|
||||
Sections 1 and 2 above); and, if the work is an executable linked
|
||||
with the Library, with the complete machine-readable "work that
|
||||
uses the Library", as object code and/or source code, so that the
|
||||
user can modify the Library and then relink to produce a modified
|
||||
executable containing the modified Library. (It is understood
|
||||
that the user who changes the contents of definitions files in the
|
||||
Library will not necessarily be able to recompile the application
|
||||
to use the modified definitions.)
|
||||
|
||||
b) Accompany the work with a written offer, valid for at
|
||||
least three years, to give the same user the materials
|
||||
specified in Subsection 6a, above, for a charge no more
|
||||
than the cost of performing this distribution.
|
||||
|
||||
c) If distribution of the work is made by offering access to copy
|
||||
from a designated place, offer equivalent access to copy the above
|
||||
specified materials from the same place.
|
||||
|
||||
d) Verify that the user has already received a copy of these
|
||||
materials or that you have already sent this user a copy.
|
||||
|
||||
For an executable, the required form of the "work that uses the
|
||||
Library" must include any data and utility programs needed for
|
||||
reproducing the executable from it. However, as a special exception,
|
||||
the source code distributed need not include anything that is normally
|
||||
distributed (in either source or binary form) with the major
|
||||
components (compiler, kernel, and so on) of the operating system on
|
||||
which the executable runs, unless that component itself accompanies
|
||||
the executable.
|
||||
|
||||
It may happen that this requirement contradicts the license
|
||||
restrictions of other proprietary libraries that do not normally
|
||||
accompany the operating system. Such a contradiction means you cannot
|
||||
use both them and the Library together in an executable that you
|
||||
distribute.
|
||||
|
||||
7. You may place library facilities that are a work based on the
|
||||
Library side-by-side in a single library together with other library
|
||||
facilities not covered by this License, and distribute such a combined
|
||||
library, provided that the separate distribution of the work based on
|
||||
the Library and of the other library facilities is otherwise
|
||||
permitted, and provided that you do these two things:
|
||||
|
||||
a) Accompany the combined library with a copy of the same work
|
||||
based on the Library, uncombined with any other library
|
||||
facilities. This must be distributed under the terms of the
|
||||
Sections above.
|
||||
|
||||
b) Give prominent notice with the combined library of the fact
|
||||
that part of it is a work based on the Library, and explaining
|
||||
where to find the accompanying uncombined form of the same work.
|
||||
|
||||
8. You may not copy, modify, sublicense, link with, or distribute
|
||||
the Library except as expressly provided under this License. Any
|
||||
attempt otherwise to copy, modify, sublicense, link with, or
|
||||
distribute the Library is void, and will automatically terminate your
|
||||
rights under this License. However, parties who have received copies,
|
||||
or rights, from you under this License will not have their licenses
|
||||
terminated so long as such parties remain in full compliance.
|
||||
|
||||
9. You are not required to accept this License, since you have not
|
||||
signed it. However, nothing else grants you permission to modify or
|
||||
distribute the Library or its derivative works. These actions are
|
||||
prohibited by law if you do not accept this License. Therefore, by
|
||||
modifying or distributing the Library (or any work based on the
|
||||
Library), you indicate your acceptance of this License to do so, and
|
||||
all its terms and conditions for copying, distributing or modifying
|
||||
the Library or works based on it.
|
||||
|
||||
10. Each time you redistribute the Library (or any work based on the
|
||||
Library), the recipient automatically receives a license from the
|
||||
original licensor to copy, distribute, link with or modify the Library
|
||||
subject to these terms and conditions. You may not impose any further
|
||||
restrictions on the recipients' exercise of the rights granted herein.
|
||||
You are not responsible for enforcing compliance by third parties to
|
||||
this License.
|
||||
|
||||
11. If, as a consequence of a court judgment or allegation of patent
|
||||
infringement or for any other reason (not limited to patent issues),
|
||||
conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot
|
||||
distribute so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you
|
||||
may not distribute the Library at all. For example, if a patent
|
||||
license would not permit royalty-free redistribution of the Library by
|
||||
all those who receive copies directly or indirectly through you, then
|
||||
the only way you could satisfy both it and this License would be to
|
||||
refrain entirely from distribution of the Library.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under any
|
||||
particular circumstance, the balance of the section is intended to apply,
|
||||
and the section as a whole is intended to apply in other circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any
|
||||
patents or other property right claims or to contest validity of any
|
||||
such claims; this section has the sole purpose of protecting the
|
||||
integrity of the free software distribution system which is
|
||||
implemented by public license practices. Many people have made
|
||||
generous contributions to the wide range of software distributed
|
||||
through that system in reliance on consistent application of that
|
||||
system; it is up to the author/donor to decide if he or she is willing
|
||||
to distribute software through any other system and a licensee cannot
|
||||
impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to
|
||||
be a consequence of the rest of this License.
|
||||
|
||||
12. If the distribution and/or use of the Library is restricted in
|
||||
certain countries either by patents or by copyrighted interfaces, the
|
||||
original copyright holder who places the Library under this License may add
|
||||
an explicit geographical distribution limitation excluding those countries,
|
||||
so that distribution is permitted only in or among countries not thus
|
||||
excluded. In such case, this License incorporates the limitation as if
|
||||
written in the body of this License.
|
||||
|
||||
13. The Free Software Foundation may publish revised and/or new
|
||||
versions of the Library General Public License from time to time.
|
||||
Such new versions will be similar in spirit to the present version,
|
||||
but may differ in detail to address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Library
|
||||
specifies a version number of this License which applies to it and
|
||||
"any later version", you have the option of following the terms and
|
||||
conditions either of that version or of any later version published by
|
||||
the Free Software Foundation. If the Library does not specify a
|
||||
license version number, you may choose any version ever published by
|
||||
the Free Software Foundation.
|
||||
|
||||
14. If you wish to incorporate parts of the Library into other free
|
||||
programs whose distribution conditions are incompatible with these,
|
||||
write to the author to ask for permission. For software which is
|
||||
copyrighted by the Free Software Foundation, write to the Free
|
||||
Software Foundation; we sometimes make exceptions for this. Our
|
||||
decision will be guided by the two goals of preserving the free status
|
||||
of all derivatives of our free software and of promoting the sharing
|
||||
and reuse of software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
|
||||
WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
|
||||
EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
|
||||
OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
|
||||
KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
|
||||
LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
|
||||
THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
|
||||
WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
|
||||
AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
|
||||
FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
|
||||
CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
|
||||
LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
|
||||
RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
|
||||
FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
|
||||
SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
|
||||
DAMAGES.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Libraries
|
||||
|
||||
If you develop a new library, and you want it to be of the greatest
|
||||
possible use to the public, we recommend making it free software that
|
||||
everyone can redistribute and change. You can do so by permitting
|
||||
redistribution under these terms (or, alternatively, under the terms of the
|
||||
ordinary General Public License).
|
||||
|
||||
To apply these terms, attach the following notices to the library. It is
|
||||
safest to attach them to the start of each source file to most effectively
|
||||
convey the exclusion of warranty; and each file should have at least the
|
||||
"copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the library's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of version 2 of the Lesser GNU General
|
||||
Public License as published by the Free Software Foundation.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or your
|
||||
school, if any, to sign a "copyright disclaimer" for the library, if
|
||||
necessary. Here is a sample; alter the names:
|
||||
|
||||
Yoyodyne, Inc., hereby disclaims all copyright interest in the
|
||||
library `Frob' (a library for tweaking knobs) written by James Random Hacker.
|
||||
|
||||
<signature of Ty Coon>, 1 April 1990
|
||||
Ty Coon, President of Vice
|
||||
|
||||
That's all there is to it!
|
13
linux/TweetDuck/Resources/build.sh
Executable file
13
linux/TweetDuck/Resources/build.sh
Executable file
@ -0,0 +1,13 @@
|
||||
#!/bin/bash
|
||||
|
||||
APPVERSION="$("$1TweetDuck" -appversion)"
|
||||
LIBVERSION="$("$1TweetDuck" -pluginversion)"
|
||||
INTRO="TweetDuck version $APPVERSION"
|
||||
|
||||
DASHES=$(seq 1 ${#INTRO})
|
||||
printf "%0.s-" $DASHES
|
||||
printf "\n$INTRO\nLibrary version $LIBVERSION\n"
|
||||
printf "%0.s-" $DASHES
|
||||
printf "\n"
|
||||
|
||||
find "$1plugins/" -type f -name ".meta" -exec echo "Processed {}" \; -exec sed -i "s/{version}/$LIBVERSION/" {} \;
|
74
linux/TweetDuck/TweetDuck.csproj
Normal file
74
linux/TweetDuck/TweetDuck.csproj
Normal file
@ -0,0 +1,74 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net5.0</TargetFramework>
|
||||
<Configurations>Debug;Release</Configurations>
|
||||
<Platforms>x64</Platforms>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<Nullable>enable</Nullable>
|
||||
<CheckForOverflowUnderflow>true</CheckForOverflowUnderflow>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<RootDir>$(ProjectDir)..\..\</RootDir>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<PackageId>TweetDuck</PackageId>
|
||||
<Product>TweetDuck</Product>
|
||||
<Authors>chylex</Authors>
|
||||
<Version>0.0.1.0</Version>
|
||||
<AssemblyVersion>$(Version)</AssemblyVersion>
|
||||
<FileVersion>$(Version)</FileVersion>
|
||||
<PackageVersion>$(Version)</PackageVersion>
|
||||
<ApplicationIcon>$(RootDir)windows\TweetDuck\Resources\Images\icon.ico</ApplicationIcon>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ResourcesContent Include="$(RootDir)resources\Content\**\*.*" Visible="false" />
|
||||
<ResourcesGuide Include="$(RootDir)resources\Guide\**\*.*" Visible="false" />
|
||||
<ResourcesPlugins Include="$(RootDir)resources\Plugins\**\*.*" Visible="false" />
|
||||
<ResourcesPlugins Remove="$(RootDir)resources\Plugins\.debug\**\*.*" />
|
||||
<ResourcesPlugins Remove="$(RootDir)resources\Plugins\emoji-keyboard\emoji-instructions.txt" />
|
||||
<ResourcesPluginsDebug Include="$(RootDir)resources\Plugins\.debug\**\*.*" Visible="false" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\lib\TweetLib.Browser.CEF\TweetLib.Browser.CEF.csproj" />
|
||||
<ProjectReference Include="..\..\lib\TweetLib.Core\TweetLib.Core.csproj" />
|
||||
<ProjectReference Include="..\TweetImpl.CefGlue\TweetImpl.CefGlue.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<!-- <Target Name="CopyLibraries" AfterTargets="Build">-->
|
||||
<!-- <Copy SourceFiles="@(Redist)" DestinationFiles="@(Redist->'$(TargetDir)\%(RecursiveDir)%(Filename)%(Extension)')" />-->
|
||||
<!-- </Target>-->
|
||||
|
||||
<Target Name="CopyResources" AfterTargets="Build">
|
||||
<ItemGroup>
|
||||
<UpToDateCheckInput Include="$(ProjectDir)Resources\build.sh" />
|
||||
</ItemGroup>
|
||||
<Move SourceFiles="$(TargetDir)cefsimple" DestinationFiles="$(TargetDir)TweetDuck.Browser" />
|
||||
<RemoveDir Directories="$(TargetDir)resources" />
|
||||
<RemoveDir Directories="$(TargetDir)guide" />
|
||||
<RemoveDir Directories="$(TargetDir)plugins" />
|
||||
<MakeDir Directories="$(TargetDir)plugins\official" />
|
||||
<MakeDir Directories="$(TargetDir)plugins\user" />
|
||||
<Copy SourceFiles="@(ResourcesContent)" DestinationFiles="@(ResourcesContent->'$(TargetDir)\resources\%(RecursiveDir)%(Filename)%(Extension)')" />
|
||||
<Copy SourceFiles="@(ResourcesGuide)" DestinationFiles="@(ResourcesGuide->'$(TargetDir)\guide\%(RecursiveDir)%(Filename)%(Extension)')" />
|
||||
<Copy SourceFiles="@(ResourcesPlugins)" DestinationFiles="@(ResourcesPlugins->'$(TargetDir)\plugins\official\%(RecursiveDir)%(Filename)%(Extension)')" />
|
||||
<Copy SourceFiles="$(RootDir)windows\TweetDuck\Resources\Images\icon.ico" DestinationFolder="$(TargetDir)" />
|
||||
<Exec Command="$(ProjectDir)Resources\build.sh "$(TargetDir)"" IgnoreExitCode="false" />
|
||||
</Target>
|
||||
|
||||
<Target Name="FinalizeDebug" AfterTargets="CopyResources" Condition="$(ConfigurationName) == Debug">
|
||||
<Copy SourceFiles="@(ResourcesPluginsDebug)" DestinationFiles="@(ResourcesPluginsDebug->'$(TargetDir)\plugins\user\.debug\%(RecursiveDir)%(Filename)%(Extension)')" />
|
||||
</Target>
|
||||
|
||||
<Target Name="FinalizeRelease" AfterTargets="CopyResources" Condition="$(ConfigurationName) == Release">
|
||||
<ItemGroup>
|
||||
<UpToDateCheckInput Include="$(ProjectDir)Resources\LICENSES.txt" />
|
||||
</ItemGroup>
|
||||
<Copy SourceFiles="$(ProjectDir)Resources\LICENSES.txt" DestinationFolder="$(TargetDir)" />
|
||||
</Target>
|
||||
|
||||
</Project>
|
23
linux/TweetDuck/Utils/WindowManager.cs
Normal file
23
linux/TweetDuck/Utils/WindowManager.cs
Normal file
@ -0,0 +1,23 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using Gtk;
|
||||
using Lunixo.ChromiumGtk.Interop;
|
||||
|
||||
namespace TweetDuck.Utils {
|
||||
static class WindowManager {
|
||||
public static Window? MainWindow { get; private set; }
|
||||
|
||||
public static Window CreateWindow(string title) {
|
||||
Window window = new Window(title);
|
||||
window.SetIconFromFile(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "icon.ico"));
|
||||
InteropLinux.SetDefaultWindowVisual(window.Handle);
|
||||
return window;
|
||||
}
|
||||
|
||||
public static Window CreateMainWindow(string title) {
|
||||
Window window = CreateWindow(title);
|
||||
MainWindow = window;
|
||||
return window;
|
||||
}
|
||||
}
|
||||
}
|
16
linux/TweetImpl.CefGlue/Adapters/CefAdapter.cs
Normal file
16
linux/TweetImpl.CefGlue/Adapters/CefAdapter.cs
Normal file
@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using TweetImpl.CefGlue.Utils;
|
||||
using TweetLib.Browser.CEF.Interfaces;
|
||||
using Xilium.CefGlue;
|
||||
|
||||
namespace TweetImpl.CefGlue.Adapters {
|
||||
sealed class CefAdapter : ICefAdapter {
|
||||
public static CefAdapter Instance { get; } = new ();
|
||||
|
||||
private CefAdapter() {}
|
||||
|
||||
public void RunOnUiThread(Action action) {
|
||||
CefRuntime.PostTask(CefThreadId.UI, new CefActionTask(action));
|
||||
}
|
||||
}
|
||||
}
|
44
linux/TweetImpl.CefGlue/Adapters/CefBrowserAdapter.cs
Normal file
44
linux/TweetImpl.CefGlue/Adapters/CefBrowserAdapter.cs
Normal file
@ -0,0 +1,44 @@
|
||||
using Lunixo.ChromiumGtk.Core;
|
||||
using TweetImpl.CefGlue.Handlers;
|
||||
using TweetLib.Browser.CEF.Data;
|
||||
using TweetLib.Browser.CEF.Interfaces;
|
||||
using Xilium.CefGlue;
|
||||
|
||||
namespace TweetImpl.CefGlue.Adapters {
|
||||
sealed class CefBrowserAdapter : IBrowserWrapper<CefFrame, CefRequest> {
|
||||
public string Url { get; private set; } = "";
|
||||
public CefFrame MainFrame => browser.CefBrowser.GetMainFrame();
|
||||
|
||||
private readonly WebBrowser browser;
|
||||
|
||||
public CefBrowserAdapter(WebBrowser browser) {
|
||||
this.browser = browser;
|
||||
this.browser.Client.DisplayHandler = new DisplayHandler(this);
|
||||
}
|
||||
|
||||
public void AddWordToDictionary(string word) {
|
||||
using var host = browser.CefBrowser.GetHost();
|
||||
host.AddWordToDictionary(word);
|
||||
}
|
||||
|
||||
public CefRequest CreateGetRequest() {
|
||||
return CefRequest.Create();
|
||||
}
|
||||
|
||||
public void RequestDownload(CefFrame frame, CefRequest request, DownloadCallbacks callbacks) {
|
||||
frame.CreateUrlRequest(request, new DownloadRequestClient(callbacks));
|
||||
}
|
||||
|
||||
private sealed class DisplayHandler : CefDisplayHandler {
|
||||
private readonly CefBrowserAdapter browser;
|
||||
|
||||
public DisplayHandler(CefBrowserAdapter browser) {
|
||||
this.browser = browser;
|
||||
}
|
||||
|
||||
protected override void OnAddressChange(CefBrowser browser, CefFrame frame, string url) {
|
||||
this.browser.Url = url;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
26
linux/TweetImpl.CefGlue/Adapters/CefDragDataAdapter.cs
Normal file
26
linux/TweetImpl.CefGlue/Adapters/CefDragDataAdapter.cs
Normal file
@ -0,0 +1,26 @@
|
||||
using TweetLib.Browser.CEF.Interfaces;
|
||||
using Xilium.CefGlue;
|
||||
|
||||
namespace TweetImpl.CefGlue.Adapters {
|
||||
sealed class CefDragDataAdapter : IDragDataAdapter<CefDragData> {
|
||||
public static CefDragDataAdapter Instance { get; } = new ();
|
||||
|
||||
private CefDragDataAdapter() {}
|
||||
|
||||
public bool IsLink(CefDragData data) {
|
||||
return data.IsLink;
|
||||
}
|
||||
|
||||
public string GetLink(CefDragData data) {
|
||||
return data.LinkUrl;
|
||||
}
|
||||
|
||||
public bool IsFragment(CefDragData data) {
|
||||
return data.IsFragment;
|
||||
}
|
||||
|
||||
public string GetFragmentAsText(CefDragData data) {
|
||||
return data.FragmentText;
|
||||
}
|
||||
}
|
||||
}
|
19
linux/TweetImpl.CefGlue/Adapters/CefErrorCodeAdapter.cs
Normal file
19
linux/TweetImpl.CefGlue/Adapters/CefErrorCodeAdapter.cs
Normal file
@ -0,0 +1,19 @@
|
||||
using System;
|
||||
using TweetLib.Browser.CEF.Interfaces;
|
||||
using Xilium.CefGlue;
|
||||
|
||||
namespace TweetImpl.CefGlue.Adapters {
|
||||
sealed class CefErrorCodeAdapter : IErrorCodeAdapter<CefErrorCode> {
|
||||
public static CefErrorCodeAdapter Instance { get; } = new ();
|
||||
|
||||
private CefErrorCodeAdapter() {}
|
||||
|
||||
public bool IsAborted(CefErrorCode errorCode) {
|
||||
return errorCode == CefErrorCode.Aborted;
|
||||
}
|
||||
|
||||
public string GetName(CefErrorCode errorCode) {
|
||||
return Enum.GetName(typeof(CefErrorCode), errorCode) ?? string.Empty;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
using TweetLib.Browser.CEF.Interfaces;
|
||||
using Xilium.CefGlue;
|
||||
|
||||
namespace TweetImpl.CefGlue.Adapters {
|
||||
sealed class CefFileDialogCallbackAdapter : IFileDialogCallbackAdapter<CefFileDialogCallback> {
|
||||
public static CefFileDialogCallbackAdapter Instance { get; } = new ();
|
||||
|
||||
private CefFileDialogCallbackAdapter() {}
|
||||
|
||||
public void Continue(CefFileDialogCallback callback, int selectedAcceptFilter, string[] filePaths) {
|
||||
callback.Continue(selectedAcceptFilter, filePaths);
|
||||
}
|
||||
|
||||
public void Cancel(CefFileDialogCallback callback) {
|
||||
callback.Cancel();
|
||||
}
|
||||
|
||||
public void Dispose(CefFileDialogCallback callback) {
|
||||
callback.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
26
linux/TweetImpl.CefGlue/Adapters/CefFrameAdapter.cs
Normal file
26
linux/TweetImpl.CefGlue/Adapters/CefFrameAdapter.cs
Normal file
@ -0,0 +1,26 @@
|
||||
using TweetLib.Browser.CEF.Interfaces;
|
||||
using Xilium.CefGlue;
|
||||
|
||||
namespace TweetImpl.CefGlue.Adapters {
|
||||
sealed class CefFrameAdapter : IFrameAdapter<CefFrame> {
|
||||
public static CefFrameAdapter Instance { get; } = new ();
|
||||
|
||||
private CefFrameAdapter() {}
|
||||
|
||||
public bool IsValid(CefFrame frame) {
|
||||
return frame.IsValid;
|
||||
}
|
||||
|
||||
public bool IsMain(CefFrame frame) {
|
||||
return frame.IsMain;
|
||||
}
|
||||
|
||||
public void LoadUrl(CefFrame frame, string url) {
|
||||
frame.LoadUrl(url);
|
||||
}
|
||||
|
||||
public void ExecuteJavaScriptAsync(CefFrame frame, string script, string identifier, int startLine = 1) {
|
||||
frame.ExecuteJavaScript(script, identifier, startLine);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
using TweetLib.Browser.CEF.Interfaces;
|
||||
using Xilium.CefGlue;
|
||||
|
||||
namespace TweetImpl.CefGlue.Adapters {
|
||||
sealed class CefJsDialogCallbackAdapter : IJsDialogCallbackAdapter<CefJSDialogCallback> {
|
||||
public static CefJsDialogCallbackAdapter Instance { get; } = new ();
|
||||
|
||||
private CefJsDialogCallbackAdapter() {}
|
||||
|
||||
public void Continue(CefJSDialogCallback callback, bool success, string? userInput = null) {
|
||||
callback.Continue(success, userInput);
|
||||
}
|
||||
|
||||
public void Dispose(CefJSDialogCallback callback) {
|
||||
callback.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
40
linux/TweetImpl.CefGlue/Adapters/CefMenuModelAdapter.cs
Normal file
40
linux/TweetImpl.CefGlue/Adapters/CefMenuModelAdapter.cs
Normal file
@ -0,0 +1,40 @@
|
||||
using TweetLib.Browser.CEF.Interfaces;
|
||||
using Xilium.CefGlue;
|
||||
|
||||
namespace TweetImpl.CefGlue.Adapters {
|
||||
sealed class CefMenuModelAdapter : IMenuModelAdapter<CefMenuModel> {
|
||||
public static CefMenuModelAdapter Instance { get; } = new ();
|
||||
|
||||
public int GetItemCount(CefMenuModel model) {
|
||||
return model.Count;
|
||||
}
|
||||
|
||||
public void AddCommand(CefMenuModel model, int command, string name) {
|
||||
model.AddItem(command, name);
|
||||
}
|
||||
|
||||
public int GetCommandAt(CefMenuModel model, int index) {
|
||||
return model.GetCommandIdAt(index);
|
||||
}
|
||||
|
||||
public void AddCheckCommand(CefMenuModel model, int command, string name) {
|
||||
model.AddCheckItem(command, name);
|
||||
}
|
||||
|
||||
public void SetChecked(CefMenuModel model, int command, bool isChecked) {
|
||||
model.SetChecked(command, isChecked);
|
||||
}
|
||||
|
||||
public void AddSeparator(CefMenuModel model) {
|
||||
model.AddSeparator();
|
||||
}
|
||||
|
||||
public bool IsSeparatorAt(CefMenuModel model, int index) {
|
||||
return model.GetItemTypeAt(index) == CefMenuItemType.Separator;
|
||||
}
|
||||
|
||||
public void RemoveAt(CefMenuModel model, int index) {
|
||||
model.RemoveAt(index);
|
||||
}
|
||||
}
|
||||
}
|
58
linux/TweetImpl.CefGlue/Adapters/CefRequestAdapter.cs
Normal file
58
linux/TweetImpl.CefGlue/Adapters/CefRequestAdapter.cs
Normal file
@ -0,0 +1,58 @@
|
||||
using TweetLib.Browser.CEF.Interfaces;
|
||||
using TweetLib.Browser.Request;
|
||||
using Xilium.CefGlue;
|
||||
|
||||
namespace TweetImpl.CefGlue.Adapters {
|
||||
sealed class CefRequestAdapter : IRequestAdapter<CefRequest> {
|
||||
public static CefRequestAdapter Instance { get; } = new ();
|
||||
|
||||
private CefRequestAdapter() {}
|
||||
|
||||
public ulong GetIdentifier(CefRequest request) {
|
||||
return request.Identifier;
|
||||
}
|
||||
|
||||
public string GetUrl(CefRequest request) {
|
||||
return request.Url;
|
||||
}
|
||||
|
||||
public void SetUrl(CefRequest request, string url) {
|
||||
request.Url = url;
|
||||
}
|
||||
|
||||
public void SetMethod(CefRequest request, string method) {
|
||||
request.Method = method;
|
||||
}
|
||||
|
||||
public bool IsTransitionForwardBack(CefRequest request) {
|
||||
return request.TransitionType.HasFlag(CefTransitionType.ForwardBackFlag);
|
||||
}
|
||||
|
||||
public bool IsCspReport(CefRequest request) {
|
||||
return request.ResourceType == CefResourceType.CspReport;
|
||||
}
|
||||
|
||||
public ResourceType GetResourceType(CefRequest request) {
|
||||
return request.ResourceType switch {
|
||||
CefResourceType.MainFrame => ResourceType.MainFrame,
|
||||
CefResourceType.Script => ResourceType.Script,
|
||||
CefResourceType.Stylesheet => ResourceType.Stylesheet,
|
||||
CefResourceType.Xhr => ResourceType.Xhr,
|
||||
CefResourceType.Image => ResourceType.Image,
|
||||
_ => ResourceType.Unknown
|
||||
};
|
||||
}
|
||||
|
||||
public void SetHeader(CefRequest request, string header, string value) {
|
||||
request.SetHeaderByName(header, value, overwrite: true);
|
||||
}
|
||||
|
||||
public void SetReferrer(CefRequest request, string referrer) {
|
||||
request.SetReferrer(referrer, CefReferrerPolicy.Default);
|
||||
}
|
||||
|
||||
public void SetAllowStoredCredentials(CefRequest request) {
|
||||
request.Options |= CefUrlRequestOptions.AllowStoredCredentials;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
using TweetImpl.CefGlue.Handlers.Resource;
|
||||
using TweetLib.Browser.CEF.Data;
|
||||
using TweetLib.Browser.CEF.Interfaces;
|
||||
using Xilium.CefGlue;
|
||||
|
||||
namespace TweetImpl.CefGlue.Adapters {
|
||||
sealed class CefResourceHandlerFactory : IResourceHandlerFactory<CefResourceHandler> {
|
||||
public static CefResourceHandlerFactory Instance { get; } = new ();
|
||||
|
||||
private CefResourceHandlerFactory() {}
|
||||
|
||||
public CefResourceHandler CreateResourceHandler(ByteArrayResource resource) {
|
||||
return new ByteArrayResourceHandler(resource);
|
||||
}
|
||||
|
||||
public string GetMimeTypeFromExtension(string extension) {
|
||||
return CefRuntime.GetMimeType(extension);
|
||||
}
|
||||
}
|
||||
}
|
31
linux/TweetImpl.CefGlue/Adapters/CefResponseAdapter.cs
Normal file
31
linux/TweetImpl.CefGlue/Adapters/CefResponseAdapter.cs
Normal file
@ -0,0 +1,31 @@
|
||||
using TweetLib.Browser.CEF.Interfaces;
|
||||
using Xilium.CefGlue;
|
||||
|
||||
namespace TweetImpl.CefGlue.Adapters {
|
||||
sealed class CefResponseAdapter : IResponseAdapter<CefResponse> {
|
||||
public static CefResponseAdapter Instance { get; } = new ();
|
||||
|
||||
private CefResponseAdapter() {}
|
||||
|
||||
public void SetCharset(CefResponse response, string charset) {
|
||||
response.Charset = charset;
|
||||
}
|
||||
|
||||
public void SetMimeType(CefResponse response, string mimeType) {
|
||||
response.MimeType = mimeType;
|
||||
}
|
||||
|
||||
public void SetStatus(CefResponse response, int statusCode, string statusText) {
|
||||
response.Status = statusCode;
|
||||
response.StatusText = statusText;
|
||||
}
|
||||
|
||||
public void SetHeader(CefResponse response, string header, string value) {
|
||||
response.SetHeaderByName(header, value, overwrite: true);
|
||||
}
|
||||
|
||||
public string GetHeader(CefResponse response, string header) {
|
||||
return response.GetHeaderMap()[header] ?? string.Empty;
|
||||
}
|
||||
}
|
||||
}
|
72
linux/TweetImpl.CefGlue/Component/BrowserComponentBase.cs
Normal file
72
linux/TweetImpl.CefGlue/Component/BrowserComponentBase.cs
Normal file
@ -0,0 +1,72 @@
|
||||
using Gtk;
|
||||
using Lunixo.ChromiumGtk.Core;
|
||||
using TweetImpl.CefGlue.Adapters;
|
||||
using TweetImpl.CefGlue.Handlers;
|
||||
using TweetImpl.CefGlue.Utils;
|
||||
using TweetLib.Browser.Base;
|
||||
using TweetLib.Browser.CEF.Component;
|
||||
using TweetLib.Browser.CEF.Data;
|
||||
using TweetLib.Browser.Interfaces;
|
||||
using Xilium.CefGlue;
|
||||
|
||||
namespace TweetImpl.CefGlue.Component {
|
||||
public abstract class BrowserComponentBase : BrowserComponent<CefFrame, CefRequest> {
|
||||
public delegate ContextMenuHandler CreateContextMenu(IContextMenuHandler? handler);
|
||||
|
||||
private ResourceHandlerRegistry<CefResourceHandler> ResourceHandlerRegistry { get; } = new (CefResourceHandlerFactory.Instance);
|
||||
private BridgeObjectRegistry BridgeObjectRegistry { get; } = new ();
|
||||
|
||||
private readonly Window window;
|
||||
private readonly CustomWebClient client;
|
||||
private readonly CreateContextMenu createContextMenu;
|
||||
private readonly bool autoReload;
|
||||
|
||||
protected BrowserComponentBase(Window window, WebBrowser wrapper, CreateContextMenu createContextMenu, bool autoReload) : base(new CefBrowserAdapter(wrapper), CefAdapter.Instance, CefFrameAdapter.Instance, CefRequestAdapter.Instance) {
|
||||
this.window = window;
|
||||
this.client = (CustomWebClient) wrapper.Client;
|
||||
this.client.LoadHandler = new LoadHandler(this);
|
||||
this.createContextMenu = createContextMenu;
|
||||
this.autoReload = autoReload;
|
||||
}
|
||||
|
||||
public override void Setup(BrowserSetup setup) {
|
||||
var resourceRequestHandlerFactory = new ResourceRequestHandlerFactory(setup.ResourceRequestHandler, ResourceHandlerRegistry, BridgeObjectRegistry);
|
||||
var requestHandler = new RequestHandler(client.LifeSpanHandler, resourceRequestHandlerFactory, autoReload);
|
||||
|
||||
client.ContextMenuHandler = createContextMenu(setup.ContextMenuHandler);
|
||||
client.DialogHandler = new DialogHandler(window);
|
||||
client.DragHandler = new DragHandler(requestHandler, this);
|
||||
client.JSDialogHandler = new JsDialogHandler(window);
|
||||
client.RequestHandler = requestHandler;
|
||||
}
|
||||
|
||||
public override void AttachBridgeObject(string name, object bridge) {
|
||||
BridgeObjectRegistry.Attach(name, bridge);
|
||||
}
|
||||
|
||||
private sealed class LoadHandler : CefLoadHandler {
|
||||
private readonly BrowserComponentBase component;
|
||||
|
||||
public LoadHandler(BrowserComponentBase component) {
|
||||
this.component = component;
|
||||
}
|
||||
|
||||
protected override void OnLoadingStateChange(CefBrowser browser, bool isLoading, bool canGoBack, bool canGoForward) {
|
||||
component.OnLoadingStateChanged(isLoading);
|
||||
}
|
||||
|
||||
protected override void OnLoadStart(CefBrowser browser, CefFrame frame, CefTransitionType transitionType) {
|
||||
component.OnFrameLoadStart(frame.Url, frame);
|
||||
}
|
||||
|
||||
protected override void OnLoadEnd(CefBrowser browser, CefFrame frame, int httpStatusCode) {
|
||||
component.BridgeObjectRegistry.RunScripts(component);
|
||||
component.OnFrameLoadEnd(frame.Url, frame);
|
||||
}
|
||||
|
||||
protected override void OnLoadError(CefBrowser browser, CefFrame frame, CefErrorCode errorCode, string errorText, string failedUrl) {
|
||||
component.OnLoadError(failedUrl, errorCode, CefErrorCodeAdapter.Instance);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
27
linux/TweetImpl.CefGlue/Component/CustomWebClient.cs
Normal file
27
linux/TweetImpl.CefGlue/Component/CustomWebClient.cs
Normal file
@ -0,0 +1,27 @@
|
||||
using System.Reflection;
|
||||
using Lunixo.ChromiumGtk;
|
||||
using Lunixo.ChromiumGtk.Core;
|
||||
using TweetImpl.CefGlue.Handlers;
|
||||
using TweetLib.Browser.CEF.Interfaces;
|
||||
using Xilium.CefGlue;
|
||||
|
||||
namespace TweetImpl.CefGlue.Component {
|
||||
public sealed class CustomWebClient : WebClient {
|
||||
public static WebView CreateWebView(IPopupHandler popupHandler) {
|
||||
WebView view = new WebView();
|
||||
WebBrowser browser = view.Browser;
|
||||
typeof(WebBrowser).GetField("<Client>k__BackingField", BindingFlags.Instance | BindingFlags.NonPublic)!.SetValue(browser, new CustomWebClient(browser, popupHandler));
|
||||
return view;
|
||||
}
|
||||
|
||||
internal LifeSpanHandler LifeSpanHandler { get; }
|
||||
|
||||
private CustomWebClient(WebBrowser core, IPopupHandler popupHandler) : base(core) {
|
||||
LifeSpanHandler = new LifeSpanHandler(core, popupHandler);
|
||||
}
|
||||
|
||||
protected override CefLifeSpanHandler GetLifeSpanHandler() {
|
||||
return LifeSpanHandler;
|
||||
}
|
||||
}
|
||||
}
|
37
linux/TweetImpl.CefGlue/Dialogs/FileDialogOpener.cs
Normal file
37
linux/TweetImpl.CefGlue/Dialogs/FileDialogOpener.cs
Normal file
@ -0,0 +1,37 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Gtk;
|
||||
using TweetImpl.CefGlue.Utils;
|
||||
using TweetLib.Browser.CEF.Interfaces;
|
||||
using TweetLib.Utils.Dialogs;
|
||||
using Action = System.Action;
|
||||
|
||||
namespace TweetImpl.CefGlue.Dialogs {
|
||||
sealed class FileDialogOpener : IFileDialogOpener {
|
||||
private readonly Window window;
|
||||
|
||||
public FileDialogOpener(Window window) {
|
||||
this.window = window;
|
||||
}
|
||||
|
||||
public void OpenFile(string title, bool multiple, List<FileDialogFilter> filters, Action<string[]> onAccepted, Action onCancelled) {
|
||||
Application.Invoke(delegate {
|
||||
using FileChooserDialog dialog = new FileChooserDialog(title, window, FileChooserAction.Open);
|
||||
dialog.SelectMultiple = multiple;
|
||||
dialog.AddButton(Stock.Cancel, ResponseType.Cancel);
|
||||
dialog.AddButton(Stock.Save, ResponseType.Accept);
|
||||
|
||||
foreach (var filter in filters) {
|
||||
dialog.AddFilter(GtkUtils.CreateFileFilter(filter));
|
||||
}
|
||||
|
||||
if (dialog.Run() == (int) ResponseType.Accept) {
|
||||
onAccepted(dialog.Filenames);
|
||||
}
|
||||
else {
|
||||
onCancelled();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
68
linux/TweetImpl.CefGlue/Dialogs/JsDialogOpener.cs
Normal file
68
linux/TweetImpl.CefGlue/Dialogs/JsDialogOpener.cs
Normal file
@ -0,0 +1,68 @@
|
||||
using System;
|
||||
using Gtk;
|
||||
using TweetImpl.CefGlue.Utils;
|
||||
using TweetLib.Browser.CEF.Dialogs;
|
||||
using TweetLib.Browser.CEF.Interfaces;
|
||||
|
||||
namespace TweetImpl.CefGlue.Dialogs {
|
||||
sealed class JsDialogOpener : IJsDialogOpener {
|
||||
private readonly Window window;
|
||||
|
||||
public JsDialogOpener(Window window) {
|
||||
this.window = window;
|
||||
}
|
||||
|
||||
private MessageDialog CreateMessageDialog(MessageDialogType type, string caption, string text, ButtonsType buttons) {
|
||||
var messageType = type switch {
|
||||
MessageDialogType.Error => MessageType.Error,
|
||||
MessageDialogType.Warning => MessageType.Warning,
|
||||
MessageDialogType.Information => MessageType.Info,
|
||||
MessageDialogType.Question => MessageType.Question,
|
||||
_ => MessageType.Other
|
||||
};
|
||||
|
||||
return GtkUtils.CreateMessageDialog(window, messageType, caption, text, buttons);
|
||||
}
|
||||
|
||||
private void Show(MessageDialogType type, string caption, string text, ButtonsType buttons, Action<ResponseType> callback) {
|
||||
Application.Invoke(delegate {
|
||||
using var dialog = CreateMessageDialog(type, caption, text, buttons);
|
||||
|
||||
ResponseType result = (ResponseType) dialog.Run();
|
||||
dialog.Hide();
|
||||
callback.Invoke(result);
|
||||
});
|
||||
}
|
||||
|
||||
public void Alert(MessageDialogType type, string title, string message, Action<bool> callback) {
|
||||
Show(type, title, message, ButtonsType.Ok, response => callback(response == ResponseType.Ok));
|
||||
}
|
||||
|
||||
public void Confirm(MessageDialogType type, string title, string message, Action<bool> callback) {
|
||||
Show(type, title, message, ButtonsType.YesNo, response => callback(response == ResponseType.Yes));
|
||||
}
|
||||
|
||||
public void Prompt(MessageDialogType type, string title, string message, Action<bool, string> callback) {
|
||||
Application.Invoke(delegate {
|
||||
using var dialog = CreateMessageDialog(type, title, message, ButtonsType.OkCancel);
|
||||
|
||||
Entry textField = new Entry();
|
||||
textField.Margin = 0;
|
||||
textField.MarginStart = 11;
|
||||
textField.MarginEnd = 11;
|
||||
textField.MarginTop = 0;
|
||||
textField.MarginBottom = 0;
|
||||
textField.ActivatesDefault = true;
|
||||
dialog.ContentArea.Add(textField);
|
||||
dialog.GetWidgetForResponse((int) ResponseType.Ok).GrabDefault();
|
||||
textField.Show();
|
||||
|
||||
ResponseType result = (ResponseType) dialog.Run();
|
||||
string inputText = textField.Text ?? string.Empty;
|
||||
|
||||
dialog.Hide();
|
||||
callback.Invoke(result == ResponseType.Ok, inputText);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
33
linux/TweetImpl.CefGlue/Handlers/ContextMenuHandler.cs
Normal file
33
linux/TweetImpl.CefGlue/Handlers/ContextMenuHandler.cs
Normal file
@ -0,0 +1,33 @@
|
||||
using TweetImpl.CefGlue.Adapters;
|
||||
using TweetLib.Browser.CEF.Logic;
|
||||
using TweetLib.Browser.Contexts;
|
||||
using TweetLib.Browser.Interfaces;
|
||||
using Xilium.CefGlue;
|
||||
|
||||
namespace TweetImpl.CefGlue.Handlers {
|
||||
public abstract class ContextMenuHandler : CefContextMenuHandler {
|
||||
private readonly ContextMenuLogic<CefMenuModel> logic;
|
||||
|
||||
protected ContextMenuHandler(IContextMenuHandler? handler) {
|
||||
this.logic = new ContextMenuLogic<CefMenuModel>(handler, CefMenuModelAdapter.Instance);
|
||||
}
|
||||
|
||||
protected abstract Context CreateContext(CefContextMenuParams parameters);
|
||||
|
||||
protected override void OnBeforeContextMenu(CefBrowser browser, CefFrame frame, CefContextMenuParams state, CefMenuModel model) {
|
||||
logic.OnBeforeContextMenu(model, CreateContext(state));
|
||||
}
|
||||
|
||||
protected override bool OnContextMenuCommand(CefBrowser browser, CefFrame frame, CefContextMenuParams state, int commandId, CefEventFlags eventFlags) {
|
||||
return logic.OnContextMenuCommand(commandId);
|
||||
}
|
||||
|
||||
protected override void OnContextMenuDismissed(CefBrowser browser, CefFrame frame) {
|
||||
logic.OnContextMenuDismissed();
|
||||
}
|
||||
|
||||
protected override bool RunContextMenu(CefBrowser browser, CefFrame frame, CefContextMenuParams parameters, CefMenuModel model, CefRunContextMenuCallback callback) {
|
||||
return logic.RunContextMenu();
|
||||
}
|
||||
}
|
||||
}
|
28
linux/TweetImpl.CefGlue/Handlers/DialogHandler.cs
Normal file
28
linux/TweetImpl.CefGlue/Handlers/DialogHandler.cs
Normal file
@ -0,0 +1,28 @@
|
||||
using Gtk;
|
||||
using TweetImpl.CefGlue.Adapters;
|
||||
using TweetImpl.CefGlue.Dialogs;
|
||||
using TweetLib.Browser.CEF.Dialogs;
|
||||
using TweetLib.Browser.CEF.Logic;
|
||||
using Xilium.CefGlue;
|
||||
|
||||
namespace TweetImpl.CefGlue.Handlers {
|
||||
sealed class DialogHandler : CefDialogHandler {
|
||||
private readonly DialogHandlerLogic<CefFileDialogCallback> logic;
|
||||
|
||||
public DialogHandler(Window window) {
|
||||
this.logic = new DialogHandlerLogic<CefFileDialogCallback>(new FileDialogOpener(window), CefFileDialogCallbackAdapter.Instance);
|
||||
}
|
||||
|
||||
protected override bool OnFileDialog(CefBrowser browser, CefFileDialogMode mode, string title, string defaultFilePath, string[] acceptFilters, int selectedAcceptFilter, CefFileDialogCallback callback) {
|
||||
return logic.OnFileDialog(ConvertDialogType(mode & CefFileDialogMode.TypeMask), acceptFilters, callback);
|
||||
}
|
||||
|
||||
private static FileDialogType ConvertDialogType(CefFileDialogMode mode) {
|
||||
return mode switch {
|
||||
CefFileDialogMode.Open => FileDialogType.Open,
|
||||
CefFileDialogMode.OpenMultiple => FileDialogType.OpenMultiple,
|
||||
_ => FileDialogType.Other
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
34
linux/TweetImpl.CefGlue/Handlers/DownloadRequestClient.cs
Normal file
34
linux/TweetImpl.CefGlue/Handlers/DownloadRequestClient.cs
Normal file
@ -0,0 +1,34 @@
|
||||
using System.IO;
|
||||
using TweetLib.Browser.CEF.Data;
|
||||
using TweetLib.Browser.CEF.Logic;
|
||||
using Xilium.CefGlue;
|
||||
using static TweetLib.Browser.CEF.Logic.DownloadRequestClientLogic.RequestStatus;
|
||||
|
||||
namespace TweetImpl.CefGlue.Handlers {
|
||||
sealed class DownloadRequestClient : CefUrlRequestClient {
|
||||
private readonly DownloadRequestClientLogic logic;
|
||||
|
||||
public DownloadRequestClient(DownloadCallbacks callbacks) {
|
||||
this.logic = new DownloadRequestClientLogic(callbacks);
|
||||
}
|
||||
|
||||
protected override bool GetAuthCredentials(bool isProxy, string host, int port, string realm, string scheme, CefAuthCallback callback) {
|
||||
return logic.GetAuthCredentials(callback);
|
||||
}
|
||||
|
||||
protected override void OnDownloadData(CefUrlRequest request, Stream data) {
|
||||
logic.OnDownloadData(data);
|
||||
}
|
||||
|
||||
protected override void OnRequestComplete(CefUrlRequest request) {
|
||||
logic.OnRequestComplete(request.RequestStatus switch {
|
||||
CefUrlRequestStatus.Success => Success,
|
||||
CefUrlRequestStatus.Failed => Failed,
|
||||
_ => Unknown
|
||||
});
|
||||
}
|
||||
|
||||
protected override void OnDownloadProgress(CefUrlRequest request, long current, long total) {}
|
||||
protected override void OnUploadProgress(CefUrlRequest request, long current, long total) {}
|
||||
}
|
||||
}
|
20
linux/TweetImpl.CefGlue/Handlers/DragHandler.cs
Normal file
20
linux/TweetImpl.CefGlue/Handlers/DragHandler.cs
Normal file
@ -0,0 +1,20 @@
|
||||
using TweetImpl.CefGlue.Adapters;
|
||||
using TweetLib.Browser.CEF.Logic;
|
||||
using TweetLib.Browser.Interfaces;
|
||||
using Xilium.CefGlue;
|
||||
|
||||
namespace TweetImpl.CefGlue.Handlers {
|
||||
sealed class DragHandler : CefDragHandler {
|
||||
private readonly DragHandlerLogic<CefDragData, CefRequest> logic;
|
||||
|
||||
public DragHandler(RequestHandler requestHandler, IScriptExecutor executor) {
|
||||
this.logic = new DragHandlerLogic<CefDragData, CefRequest>(executor, requestHandler.Logic, CefDragDataAdapter.Instance);
|
||||
}
|
||||
|
||||
protected override bool OnDragEnter(CefBrowser browser, CefDragData dragData, CefDragOperationsMask mask) {
|
||||
return logic.OnDragEnter(dragData);
|
||||
}
|
||||
|
||||
protected override void OnDraggableRegionsChanged(CefBrowser browser, CefFrame frame, CefDraggableRegion[] regions) {}
|
||||
}
|
||||
}
|
36
linux/TweetImpl.CefGlue/Handlers/JsDialogHandler.cs
Normal file
36
linux/TweetImpl.CefGlue/Handlers/JsDialogHandler.cs
Normal file
@ -0,0 +1,36 @@
|
||||
using Gtk;
|
||||
using TweetImpl.CefGlue.Adapters;
|
||||
using TweetImpl.CefGlue.Dialogs;
|
||||
using TweetLib.Browser.CEF.Dialogs;
|
||||
using TweetLib.Browser.CEF.Logic;
|
||||
using Xilium.CefGlue;
|
||||
|
||||
namespace TweetImpl.CefGlue.Handlers {
|
||||
sealed class JsDialogHandler : CefJSDialogHandler {
|
||||
private readonly JsDialogHandlerLogic<CefJSDialogCallback> logic;
|
||||
|
||||
public JsDialogHandler(Window window) {
|
||||
this.logic = new JsDialogHandlerLogic<CefJSDialogCallback>(new JsDialogOpener(window), CefJsDialogCallbackAdapter.Instance);
|
||||
}
|
||||
|
||||
protected override bool OnJSDialog(CefBrowser browser, string originUrl, CefJSDialogType dialogType, string messageText, string defaultPromptText, CefJSDialogCallback callback, out bool suppressMessage) {
|
||||
return logic.OnJSDialog(ConvertDialogType(dialogType), messageText, callback, out suppressMessage);
|
||||
}
|
||||
|
||||
protected override bool OnBeforeUnloadDialog(CefBrowser browser, string messageText, bool isReload, CefJSDialogCallback callback) {
|
||||
return logic.OnBeforeUnloadDialog(callback);
|
||||
}
|
||||
|
||||
protected override void OnResetDialogState(CefBrowser browser) {}
|
||||
protected override void OnDialogClosed(CefBrowser browser) {}
|
||||
|
||||
private static JsDialogType ConvertDialogType(CefJSDialogType type) {
|
||||
return type switch {
|
||||
CefJSDialogType.Alert => JsDialogType.Alert,
|
||||
CefJSDialogType.Confirm => JsDialogType.Confirm,
|
||||
CefJSDialogType.Prompt => JsDialogType.Prompt,
|
||||
_ => JsDialogType.Unknown
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
41
linux/TweetImpl.CefGlue/Handlers/LifeSpanHandler.cs
Normal file
41
linux/TweetImpl.CefGlue/Handlers/LifeSpanHandler.cs
Normal file
@ -0,0 +1,41 @@
|
||||
using System.Reflection;
|
||||
using Lunixo.ChromiumGtk.Core;
|
||||
using TweetLib.Browser.CEF.Interfaces;
|
||||
using TweetLib.Browser.CEF.Logic;
|
||||
using Xilium.CefGlue;
|
||||
using static TweetLib.Browser.CEF.Logic.LifeSpanHandlerLogic.TargetDisposition;
|
||||
|
||||
namespace TweetImpl.CefGlue.Handlers {
|
||||
sealed class LifeSpanHandler : CefLifeSpanHandler {
|
||||
public LifeSpanHandlerLogic Logic { get; }
|
||||
|
||||
private readonly WebBrowser core;
|
||||
|
||||
public LifeSpanHandler(WebBrowser core, IPopupHandler popupHandler) {
|
||||
this.core = core;
|
||||
this.Logic = new LifeSpanHandlerLogic(popupHandler);
|
||||
}
|
||||
|
||||
protected override void OnAfterCreated(CefBrowser browser) {
|
||||
core.GetType().GetMethod("OnCreated", BindingFlags.Instance | BindingFlags.NonPublic)!.Invoke(core, new object[] { browser });
|
||||
}
|
||||
|
||||
protected override bool OnBeforePopup(CefBrowser browser, CefFrame frame, string targetUrl, string targetFrameName, CefWindowOpenDisposition targetDisposition, bool userGesture, CefPopupFeatures popupFeatures, CefWindowInfo windowInfo, ref CefClient client, CefBrowserSettings browserSettings, ref CefDictionaryValue extraInfo, ref bool noJavascriptAccess) {
|
||||
return Logic.OnBeforePopup(targetUrl, ConvertTargetDisposition(targetDisposition));
|
||||
}
|
||||
|
||||
protected override bool DoClose(CefBrowser browser) {
|
||||
return Logic.DoClose();
|
||||
}
|
||||
|
||||
public static LifeSpanHandlerLogic.TargetDisposition ConvertTargetDisposition(CefWindowOpenDisposition targetDisposition) {
|
||||
return targetDisposition switch {
|
||||
CefWindowOpenDisposition.NewBackgroundTab => NewBackgroundTab,
|
||||
CefWindowOpenDisposition.NewForegroundTab => NewForegroundTab,
|
||||
CefWindowOpenDisposition.NewPopup => NewPopup,
|
||||
CefWindowOpenDisposition.NewWindow => NewWindow,
|
||||
_ => Other
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
36
linux/TweetImpl.CefGlue/Handlers/RequestHandler.cs
Normal file
36
linux/TweetImpl.CefGlue/Handlers/RequestHandler.cs
Normal file
@ -0,0 +1,36 @@
|
||||
using TweetImpl.CefGlue.Adapters;
|
||||
using TweetLib.Browser.CEF.Logic;
|
||||
using Xilium.CefGlue;
|
||||
|
||||
namespace TweetImpl.CefGlue.Handlers {
|
||||
sealed class RequestHandler : CefRequestHandler {
|
||||
public RequestHandlerLogic<CefRequest> Logic { get; }
|
||||
|
||||
private readonly ResourceRequestHandlerFactory resourceRequestHandlerFactory;
|
||||
private readonly bool autoReload;
|
||||
|
||||
public RequestHandler(LifeSpanHandler lifeSpanHandler, ResourceRequestHandlerFactory resourceRequestHandlerFactory, bool autoReload) {
|
||||
this.Logic = new RequestHandlerLogic<CefRequest>(CefRequestAdapter.Instance, lifeSpanHandler.Logic);
|
||||
this.resourceRequestHandlerFactory = resourceRequestHandlerFactory;
|
||||
this.autoReload = autoReload;
|
||||
}
|
||||
|
||||
protected override bool OnBeforeBrowse(CefBrowser browser, CefFrame frame, CefRequest request, bool userGesture, bool isRedirect) {
|
||||
return Logic.OnBeforeBrowse(request, userGesture);
|
||||
}
|
||||
|
||||
protected override bool OnOpenUrlFromTab(CefBrowser browser, CefFrame frame, string targetUrl, CefWindowOpenDisposition targetDisposition, bool userGesture) {
|
||||
return Logic.OnOpenUrlFromTab(targetUrl, userGesture, LifeSpanHandler.ConvertTargetDisposition(targetDisposition));
|
||||
}
|
||||
|
||||
protected override CefResourceRequestHandler GetResourceRequestHandler(CefBrowser browser, CefFrame frame, CefRequest request, bool isNavigation, bool isDownload, string requestInitiator, ref bool disableDefaultHandling) {
|
||||
return resourceRequestHandlerFactory.GetResourceRequestHandler(request, ref disableDefaultHandling);
|
||||
}
|
||||
|
||||
protected override void OnRenderProcessTerminated(CefBrowser browser, CefTerminationStatus status) {
|
||||
if (autoReload) {
|
||||
browser.Reload();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using TweetImpl.CefGlue.Adapters;
|
||||
using TweetLib.Browser.CEF.Data;
|
||||
using TweetLib.Browser.CEF.Logic;
|
||||
using Xilium.CefGlue;
|
||||
|
||||
namespace TweetImpl.CefGlue.Handlers.Resource {
|
||||
sealed class ByteArrayResourceHandler : CefResourceHandler {
|
||||
private static readonly ByteArrayResourceHandlerLogic.WriteToOut<IntPtr> WriteToOut = static delegate (IntPtr dataOut, byte[] dataIn, int position, int length) {
|
||||
Marshal.Copy(dataIn, position, dataOut, length);
|
||||
};
|
||||
|
||||
private ByteArrayResourceHandlerLogic<CefResponse>? logic;
|
||||
|
||||
public ByteArrayResourceHandler() {
|
||||
SetResource(new ByteArrayResource(Array.Empty<byte>()));
|
||||
}
|
||||
|
||||
public ByteArrayResourceHandler(ByteArrayResource resource) {
|
||||
SetResource(resource);
|
||||
}
|
||||
|
||||
private void SetResource(ByteArrayResource resource) {
|
||||
this.logic = new ByteArrayResourceHandlerLogic<CefResponse>(resource, CefResponseAdapter.Instance);
|
||||
}
|
||||
|
||||
protected override bool Open(CefRequest request, out bool handleRequest, CefCallback callback) {
|
||||
return logic!.Open(out handleRequest);
|
||||
}
|
||||
|
||||
protected override void GetResponseHeaders(CefResponse response, out long responseLength, out string? redirectUrl) {
|
||||
logic!.GetResponseHeaders(response, out responseLength, out redirectUrl);
|
||||
}
|
||||
|
||||
protected override bool Skip(long bytesToSkip, out long bytesSkipped, CefResourceSkipCallback callback) {
|
||||
return logic!.Skip(bytesToSkip, out bytesSkipped, callback);
|
||||
}
|
||||
|
||||
protected override bool Read(IntPtr dataOut, int bytesToRead, out int bytesRead, CefResourceReadCallback callback) {
|
||||
return logic!.Read(WriteToOut, dataOut, Math.Min(bytesToRead, logic.RemainingBytes), out bytesRead, callback);
|
||||
}
|
||||
|
||||
protected override void Cancel() {}
|
||||
}
|
||||
}
|
@ -0,0 +1,120 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
using TweetImpl.CefGlue.Utils;
|
||||
using Xilium.CefGlue;
|
||||
|
||||
namespace TweetImpl.CefGlue.Handlers.Resource {
|
||||
sealed class DisableCspResourceHandler : CefResourceHandler {
|
||||
private readonly CefFrame frame;
|
||||
|
||||
private Client? client;
|
||||
private int position;
|
||||
|
||||
public DisableCspResourceHandler(CefFrame frame) {
|
||||
this.frame = frame;
|
||||
}
|
||||
|
||||
protected override bool Open(CefRequest request, out bool handleRequest, CefCallback callback) {
|
||||
if (client != null) {
|
||||
throw new InvalidOperationException("DisableCspResourceHandler is not reusable!");
|
||||
}
|
||||
|
||||
client = new Client(callback);
|
||||
CefRuntime.PostTask(CefThreadId.IO, new CefActionTask(() => frame.CreateUrlRequest(request, client)));
|
||||
handleRequest = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
protected override void GetResponseHeaders(CefResponse response, out long responseLength, out string? redirectUrl) {
|
||||
redirectUrl = null;
|
||||
|
||||
if (client is not { Response: {} result }) {
|
||||
responseLength = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
response.Url = result.Url;
|
||||
response.Charset = result.Charset;
|
||||
response.MimeType = result.MimeType;
|
||||
response.Status = result.Status;
|
||||
response.StatusText = result.StatusText;
|
||||
response.Error = result.Error;
|
||||
|
||||
var headers = result.GetHeaderMap();
|
||||
headers.Remove("Content-Security-Policy");
|
||||
response.SetHeaderMap(headers);
|
||||
|
||||
responseLength = client.Stream.Length;
|
||||
}
|
||||
|
||||
protected override bool Skip(long bytesToSkip, out long bytesSkipped, CefResourceSkipCallback callback) {
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
protected override bool Read(IntPtr dataOut, int bytesToRead, out int bytesRead, CefResourceReadCallback callback) {
|
||||
callback.Dispose();
|
||||
|
||||
if (client == null) {
|
||||
bytesRead = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (bytesToRead > 0) {
|
||||
int maxLength = (int) (client.Stream.Length - position);
|
||||
if (bytesToRead > maxLength) {
|
||||
bytesToRead = maxLength;
|
||||
}
|
||||
|
||||
Marshal.Copy(client.Stream.GetBuffer(), position, dataOut, bytesToRead);
|
||||
position += bytesToRead;
|
||||
}
|
||||
|
||||
bytesRead = bytesToRead;
|
||||
return bytesRead > 0;
|
||||
}
|
||||
|
||||
protected override void Cancel() {}
|
||||
|
||||
protected override void Dispose(bool disposing) {
|
||||
base.Dispose(disposing);
|
||||
frame.Dispose();
|
||||
client?.Dispose();
|
||||
}
|
||||
|
||||
private sealed class Client : CefUrlRequestClient, IDisposable {
|
||||
public MemoryStream Stream { get; }
|
||||
public CefResponse? Response { get; private set; }
|
||||
|
||||
private readonly CefCallback openCallback;
|
||||
|
||||
public Client(CefCallback openCallback) {
|
||||
this.openCallback = openCallback;
|
||||
this.Stream = new MemoryStream();
|
||||
}
|
||||
|
||||
protected override void OnDownloadData(CefUrlRequest request, Stream data) {
|
||||
data.CopyTo(Stream);
|
||||
}
|
||||
|
||||
protected override void OnRequestComplete(CefUrlRequest request) {
|
||||
if (request.RequestStatus == CefUrlRequestStatus.Success) {
|
||||
Response = request.GetResponse();
|
||||
openCallback.Continue();
|
||||
}
|
||||
else {
|
||||
openCallback.Cancel();
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnDownloadProgress(CefUrlRequest request, long current, long total) {}
|
||||
protected override void OnUploadProgress(CefUrlRequest request, long current, long total) {}
|
||||
|
||||
public void Dispose() {
|
||||
Stream.Dispose();
|
||||
Response?.Dispose();
|
||||
openCallback.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
52
linux/TweetImpl.CefGlue/Handlers/ResourceRequestHandler.cs
Normal file
52
linux/TweetImpl.CefGlue/Handlers/ResourceRequestHandler.cs
Normal file
@ -0,0 +1,52 @@
|
||||
using TweetImpl.CefGlue.Adapters;
|
||||
using TweetImpl.CefGlue.Handlers.Resource;
|
||||
using TweetImpl.CefGlue.Utils;
|
||||
using TweetLib.Browser.CEF.Data;
|
||||
using TweetLib.Browser.CEF.Logic;
|
||||
using TweetLib.Browser.Interfaces;
|
||||
using Xilium.CefGlue;
|
||||
|
||||
namespace TweetImpl.CefGlue.Handlers {
|
||||
sealed class ResourceRequestHandler : CefResourceRequestHandler {
|
||||
private readonly ResourceRequestHandlerLogic<CefRequest, CefResponse, CefResourceHandler> logic;
|
||||
private readonly BridgeObjectRegistry bridgeObjectRegistry;
|
||||
|
||||
public ResourceRequestHandler(ResourceHandlerRegistry<CefResourceHandler> resourceHandlerRegistry, BridgeObjectRegistry bridgeObjectRegistry, IResourceRequestHandler? resourceRequestHandler) {
|
||||
this.logic = new ResourceRequestHandlerLogic<CefRequest, CefResponse, CefResourceHandler>(CefRequestAdapter.Instance, CefResponseAdapter.Instance, resourceHandlerRegistry, resourceRequestHandler);
|
||||
this.bridgeObjectRegistry = bridgeObjectRegistry;
|
||||
}
|
||||
|
||||
protected override CefCookieAccessFilter? GetCookieAccessFilter(CefBrowser browser, CefFrame frame, CefRequest request) {
|
||||
return null;
|
||||
}
|
||||
|
||||
protected override CefReturnValue OnBeforeResourceLoad(CefBrowser browser, CefFrame frame, CefRequest request, CefCallback callback) {
|
||||
return logic.OnBeforeResourceLoad(request, callback) ? CefReturnValue.Continue : CefReturnValue.Cancel;
|
||||
}
|
||||
|
||||
protected override CefResourceHandler? GetResourceHandler(CefBrowser browser, CefFrame frame, CefRequest request) {
|
||||
if (request.ResourceType == CefResourceType.MainFrame) {
|
||||
return new DisableCspResourceHandler(frame);
|
||||
}
|
||||
|
||||
if (SchemeHandlerFactory.TryGetHandler(request) is {} schemeHandler) {
|
||||
return schemeHandler;
|
||||
}
|
||||
|
||||
if (bridgeObjectRegistry.TryGetHandler(request) is {} bridgeHandler) {
|
||||
return bridgeHandler;
|
||||
}
|
||||
|
||||
return logic.GetResourceHandler(request);
|
||||
}
|
||||
|
||||
protected override ResponseFilter? GetResourceResponseFilter(CefBrowser browser, CefFrame frame, CefRequest request, CefResponse response) {
|
||||
var filter = logic.GetResourceResponseFilter(request, response);
|
||||
return filter == null ? null : new ResponseFilter(filter);
|
||||
}
|
||||
|
||||
protected override void OnResourceLoadComplete(CefBrowser browser, CefFrame frame, CefRequest request, CefResponse response, CefUrlRequestStatus status, long receivedContentLength) {
|
||||
logic.OnResourceLoadComplete(request);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
using TweetImpl.CefGlue.Adapters;
|
||||
using TweetImpl.CefGlue.Utils;
|
||||
using TweetLib.Browser.CEF.Data;
|
||||
using TweetLib.Browser.CEF.Logic;
|
||||
using TweetLib.Browser.Interfaces;
|
||||
using Xilium.CefGlue;
|
||||
|
||||
namespace TweetImpl.CefGlue.Handlers {
|
||||
sealed class ResourceRequestHandlerFactory {
|
||||
private readonly ResourceRequestHandlerFactoryLogic<ResourceRequestHandler, CefResourceHandler, CefRequest> logic;
|
||||
|
||||
public ResourceRequestHandlerFactory(IResourceRequestHandler? resourceRequestHandler, ResourceHandlerRegistry<CefResourceHandler> resourceHandlerRegistry, BridgeObjectRegistry bridgeObjectRegistry) {
|
||||
this.logic = new ResourceRequestHandlerFactoryLogic<ResourceRequestHandler, CefResourceHandler, CefRequest>(CefRequestAdapter.Instance, new ResourceRequestHandler(resourceHandlerRegistry, bridgeObjectRegistry, resourceRequestHandler), resourceHandlerRegistry);
|
||||
}
|
||||
|
||||
public CefResourceRequestHandler GetResourceRequestHandler(CefRequest request, ref bool disableDefaultHandling) {
|
||||
return logic.GetResourceRequestHandler(request, ref disableDefaultHandling);
|
||||
}
|
||||
}
|
||||
}
|
25
linux/TweetImpl.CefGlue/Handlers/ResponseFilter.cs
Normal file
25
linux/TweetImpl.CefGlue/Handlers/ResponseFilter.cs
Normal file
@ -0,0 +1,25 @@
|
||||
using System.IO;
|
||||
using TweetLib.Browser.CEF.Logic;
|
||||
using Xilium.CefGlue;
|
||||
|
||||
namespace TweetImpl.CefGlue.Handlers {
|
||||
sealed class ResponseFilter : CefResponseFilter {
|
||||
private readonly ResponseFilterLogic logic;
|
||||
|
||||
public ResponseFilter(ResponseFilterLogic logic) {
|
||||
this.logic = logic;
|
||||
}
|
||||
|
||||
protected override bool InitFilter() {
|
||||
return true;
|
||||
}
|
||||
|
||||
protected override CefResponseFilterStatus Filter(UnmanagedMemoryStream dataIn, long dataInSize, out long dataInRead, UnmanagedMemoryStream dataOut, long dataOutSize, out long dataOutWritten) {
|
||||
return logic.Filter(dataIn, out dataInRead, dataOut, dataOutSize, out dataOutWritten) switch {
|
||||
ResponseFilterLogic.FilterStatus.NeedMoreData => CefResponseFilterStatus.NeedMoreData,
|
||||
ResponseFilterLogic.FilterStatus.Done => CefResponseFilterStatus.Done,
|
||||
_ => CefResponseFilterStatus.Error
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
5
linux/TweetImpl.CefGlue/Lib.cs
Normal file
5
linux/TweetImpl.CefGlue/Lib.cs
Normal file
@ -0,0 +1,5 @@
|
||||
using System.Reflection;
|
||||
|
||||
[assembly: AssemblyTitle("TweetDuck CefGlue Implementation")]
|
||||
[assembly: AssemblyDescription("TweetDuck CefGlue Implementation")]
|
||||
[assembly: AssemblyProduct("TweetImpl.CefGlue")]
|
39
linux/TweetImpl.CefGlue/Resources/bridge.skeleton.js
Normal file
39
linux/TweetImpl.CefGlue/Resources/bridge.skeleton.js
Normal file
@ -0,0 +1,39 @@
|
||||
window["{{bridgename}}"] = (function() {
|
||||
const bridge = {};
|
||||
const methods = "{{methods}}".split("|");
|
||||
|
||||
async function callBridgeMethod(name, args) {
|
||||
const jsonArgs = JSON.stringify(args);
|
||||
const response = await fetch("https://tweetduck.local/bridge/{{bridgename}}/" + name, {
|
||||
method: "POST",
|
||||
cache: "no-cache",
|
||||
credentials: "omit",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: jsonArgs
|
||||
});
|
||||
|
||||
const body = await response.text();
|
||||
|
||||
if (response.status !== 200) {
|
||||
console.error("Error calling {{bridgename}}." + name + " with arguments: " + jsonArgs + "\n" + body);
|
||||
throw new Error(body);
|
||||
}
|
||||
|
||||
return body ? JSON.parse(body) : null;
|
||||
}
|
||||
|
||||
for (const method of methods) {
|
||||
const jsName = method[0].toLowerCase() + method.substring(1);
|
||||
|
||||
Object.defineProperty(bridge, jsName, {
|
||||
enumerable: true,
|
||||
configurable: false,
|
||||
writable: false,
|
||||
value() {
|
||||
return callBridgeMethod(method, Array.from(arguments));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return bridge;
|
||||
})();
|
33
linux/TweetImpl.CefGlue/TweetImpl.CefGlue.csproj
Normal file
33
linux/TweetImpl.CefGlue/TweetImpl.CefGlue.csproj
Normal file
@ -0,0 +1,33 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net5.0</TargetFramework>
|
||||
<Configurations>Debug;Release</Configurations>
|
||||
<Platforms>x64</Platforms>
|
||||
<Nullable>enable</Nullable>
|
||||
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<PackageId>TweetImpl.CefGlue</PackageId>
|
||||
<Product>TweetImpl.CefGlue</Product>
|
||||
<Authors>chylex</Authors>
|
||||
<Version>0.0.1.0</Version>
|
||||
<AssemblyVersion>$(Version)</AssemblyVersion>
|
||||
<FileVersion>$(Version)</FileVersion>
|
||||
<PackageVersion>$(Version)</PackageVersion>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Lunixo.ChromiumGtk.Linux64" Version="2.0.4638.1" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\lib\TweetLib.Browser.CEF\TweetLib.Browser.CEF.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="Resources\bridge.skeleton.js" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
167
linux/TweetImpl.CefGlue/Utils/BridgeObjectRegistry.cs
Normal file
167
linux/TweetImpl.CefGlue/Utils/BridgeObjectRegistry.cs
Normal file
@ -0,0 +1,167 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using TweetImpl.CefGlue.Handlers.Resource;
|
||||
using TweetLib.Browser.CEF.Data;
|
||||
using TweetLib.Browser.Interfaces;
|
||||
using TweetLib.Utils.Static;
|
||||
using Xilium.CefGlue;
|
||||
|
||||
namespace TweetImpl.CefGlue.Utils {
|
||||
sealed class BridgeObjectRegistry {
|
||||
private const string UrlPrefix = "https://tweetduck.local/bridge/";
|
||||
private const string BridgeJsFile = "bridge.skeleton.js";
|
||||
|
||||
private static readonly string BridgeJs;
|
||||
|
||||
private static readonly JsonSerializerOptions JsonOptions = new () {
|
||||
NumberHandling = JsonNumberHandling.Strict,
|
||||
MaxDepth = 1
|
||||
};
|
||||
|
||||
static BridgeObjectRegistry() {
|
||||
using var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("TweetImpl.CefGlue.Resources." + BridgeJsFile) ?? throw new IOException("Missing embedded resource: " + BridgeJsFile);
|
||||
using var reader = new StreamReader(stream, Encoding.UTF8);
|
||||
BridgeJs = reader.ReadToEnd();
|
||||
}
|
||||
|
||||
private readonly Dictionary<string, object> objects = new ();
|
||||
|
||||
public void Attach(string name, object obj) {
|
||||
objects.Add(name, obj);
|
||||
}
|
||||
|
||||
public void RunScripts(IScriptExecutor executor) {
|
||||
foreach (var (name, obj) in objects) {
|
||||
var methods = obj.GetType().GetMethods(BindingFlags.Instance | BindingFlags.Public).Select(static methodInfo => methodInfo.Name);
|
||||
var script = BridgeJs;
|
||||
script = script.Replace("{{bridgename}}", name);
|
||||
script = script.Replace("{{methods}}", string.Join('|', methods));
|
||||
executor.RunScript("gen:bridge:" + name, script);
|
||||
}
|
||||
}
|
||||
|
||||
public CefResourceHandler? TryGetHandler(CefRequest request) {
|
||||
string url = request.Url;
|
||||
if (!url.StartsWithOrdinal(UrlPrefix)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
var parts = StringUtils.SplitInTwo(url[UrlPrefix.Length..], '/');
|
||||
if (parts == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
var (objectName, methodName) = parts.Value;
|
||||
if (!objects.TryGetValue(objectName, out var obj)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
var methodInfo = obj.GetType().GetMethod(methodName, BindingFlags.Instance | BindingFlags.Public);
|
||||
if (methodInfo == null) {
|
||||
return Error("Unknown method.", HttpStatusCode.NotFound);
|
||||
}
|
||||
|
||||
var post = request.PostData.GetElements();
|
||||
JsonElement[]? values;
|
||||
|
||||
try {
|
||||
values = post.Length == 1 ? JsonSerializer.Deserialize<JsonElement[]>(post[0].GetBytes(), JsonOptions) : null;
|
||||
if (values == null) {
|
||||
throw new JsonException();
|
||||
}
|
||||
} catch (JsonException) {
|
||||
return Error("Body must contain a single JSON array.", HttpStatusCode.BadRequest);
|
||||
}
|
||||
|
||||
try {
|
||||
return TryCall(obj, methodInfo, values);
|
||||
} catch (Exception e) {
|
||||
return Error("Unexpected error occurred: " + e, HttpStatusCode.InternalServerError);
|
||||
}
|
||||
}
|
||||
|
||||
private CefResourceHandler TryCall(object obj, MethodInfo methodInfo, JsonElement[] values) {
|
||||
var parameters = methodInfo.GetParameters();
|
||||
var convertedValues = new object?[parameters.Length];
|
||||
|
||||
for (var i = 0; i < parameters.Length; i++) {
|
||||
var parameter = parameters[i];
|
||||
|
||||
if (i < values.Length) {
|
||||
JsonElement value = values[i];
|
||||
Type parameterType = parameter.ParameterType;
|
||||
|
||||
if (value.ValueKind == JsonValueKind.Null) {
|
||||
bool canAssignNull = !parameterType.IsValueType || (parameterType.IsGenericType && parameterType.GetGenericTypeDefinition() == typeof(Nullable<>));
|
||||
if (canAssignNull) {
|
||||
convertedValues[i] = null;
|
||||
continue;
|
||||
}
|
||||
else {
|
||||
return Error("Null provided for non-nullable parameter '" + parameter.Name + "'.", HttpStatusCode.BadRequest);
|
||||
}
|
||||
}
|
||||
|
||||
var convertedValue = TryConvertValue(value, parameterType);
|
||||
if (convertedValue == null) {
|
||||
return Error("Invalid value provided for parameter '" + parameter.Name + "' of type '" + parameterType + "'.", HttpStatusCode.BadRequest);
|
||||
}
|
||||
else {
|
||||
convertedValues[i] = convertedValue;
|
||||
}
|
||||
}
|
||||
else if (parameter.HasDefaultValue) {
|
||||
convertedValues[i] = parameter.RawDefaultValue;
|
||||
}
|
||||
else {
|
||||
return Error("No value provided for parameter '" + parameter.Name + "' which has no default value.", HttpStatusCode.BadRequest);
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
var resultObj = methodInfo.Invoke(obj, convertedValues);
|
||||
var resultBody = resultObj == null ? Array.Empty<byte>() : Encoding.UTF8.GetBytes(JsonSerializer.Serialize(resultObj, JsonOptions));
|
||||
return new ByteArrayResourceHandler(new ByteArrayResource(resultBody));
|
||||
} catch (TargetInvocationException e) {
|
||||
return Error("Method threw an exception: " + e.InnerException!, HttpStatusCode.InternalServerError);
|
||||
} catch (Exception e) {
|
||||
return Error("An exception occurred: " + e, HttpStatusCode.InternalServerError);
|
||||
}
|
||||
}
|
||||
|
||||
[SuppressMessage("ReSharper", "HeapView.BoxingAllocation")]
|
||||
private static object? TryConvertValue(JsonElement ele, Type target) {
|
||||
if (target == typeof(string)) {
|
||||
return ele.GetString();
|
||||
}
|
||||
else if (target == typeof(int)) {
|
||||
return ele.TryGetInt32(out int value) ? value : null;
|
||||
}
|
||||
else if (target == typeof(bool)) {
|
||||
return ele.ValueKind switch {
|
||||
JsonValueKind.True => true,
|
||||
JsonValueKind.False => false,
|
||||
_ => null
|
||||
};
|
||||
}
|
||||
else if (target == typeof(IDisposable)) {
|
||||
return null; // TODO callbacks
|
||||
}
|
||||
else {
|
||||
throw new NotSupportedException("Unsupported parameter type: " + target);
|
||||
}
|
||||
}
|
||||
|
||||
private static ByteArrayResourceHandler Error(string message, HttpStatusCode code) {
|
||||
return new ByteArrayResourceHandler(new ByteArrayResource(message, Encoding.UTF8, statusCode: code, statusText: "Error"));
|
||||
}
|
||||
}
|
||||
}
|
16
linux/TweetImpl.CefGlue/Utils/CefActionTask.cs
Normal file
16
linux/TweetImpl.CefGlue/Utils/CefActionTask.cs
Normal file
@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using Xilium.CefGlue;
|
||||
|
||||
namespace TweetImpl.CefGlue.Utils {
|
||||
sealed class CefActionTask : CefTask {
|
||||
private readonly Action action;
|
||||
|
||||
public CefActionTask(Action action) {
|
||||
this.action = action;
|
||||
}
|
||||
|
||||
protected override void Execute() {
|
||||
action();
|
||||
}
|
||||
}
|
||||
}
|
37
linux/TweetImpl.CefGlue/Utils/GtkUtils.cs
Normal file
37
linux/TweetImpl.CefGlue/Utils/GtkUtils.cs
Normal file
@ -0,0 +1,37 @@
|
||||
using Gtk;
|
||||
using TweetLib.Utils.Dialogs;
|
||||
|
||||
namespace TweetImpl.CefGlue.Utils {
|
||||
public static class GtkUtils {
|
||||
public static MessageDialog CreateMessageDialog(Window window, MessageType type, string title, string message, ButtonsType buttons) {
|
||||
static string PrefixTitle(MessageType type, string title) {
|
||||
return type switch {
|
||||
MessageType.Error => "Error | " + title,
|
||||
MessageType.Warning => "Warning | " + title,
|
||||
_ => title
|
||||
};
|
||||
}
|
||||
|
||||
var dialog = new MessageDialog(window, DialogFlags.Modal | DialogFlags.DestroyWithParent, type, buttons, message) {
|
||||
Title = PrefixTitle(type, title),
|
||||
WidthRequest = 350
|
||||
};
|
||||
|
||||
dialog.ContentArea.MarginTop = 8;
|
||||
dialog.ContentArea.Spacing = 4;
|
||||
return dialog;
|
||||
}
|
||||
|
||||
public static FileFilter CreateFileFilter(FileDialogFilter filter) {
|
||||
var fileFilter = new FileFilter {
|
||||
Name = filter.FullName
|
||||
};
|
||||
|
||||
foreach (var extension in filter.Extensions) {
|
||||
fileFilter.AddPattern("*" + extension);
|
||||
}
|
||||
|
||||
return fileFilter;
|
||||
}
|
||||
}
|
||||
}
|
39
linux/TweetImpl.CefGlue/Utils/SchemeHandlerFactory.cs
Normal file
39
linux/TweetImpl.CefGlue/Utils/SchemeHandlerFactory.cs
Normal file
@ -0,0 +1,39 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using TweetImpl.CefGlue.Adapters;
|
||||
using TweetLib.Browser.CEF.Logic;
|
||||
using TweetLib.Browser.Interfaces;
|
||||
using Xilium.CefGlue;
|
||||
|
||||
namespace TweetImpl.CefGlue.Utils {
|
||||
public sealed class SchemeHandlerFactory {
|
||||
private static readonly Dictionary<string, SchemeHandlerFactory> Factories = new ();
|
||||
|
||||
internal static CefResourceHandler? TryGetHandler(CefRequest request) {
|
||||
if (Uri.TryCreate(request.Url, UriKind.Absolute, out Uri? uri) && Factories.TryGetValue(uri.Scheme, out var factory)) {
|
||||
return factory.Create(request);
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
[SuppressMessage("ReSharper", "BitwiseOperatorOnEnumWithoutFlags")]
|
||||
public static void Register(CefSchemeRegistrar registrar, ICustomSchemeHandler handler) {
|
||||
string protocol = handler.Protocol;
|
||||
Factories.Add(protocol, new SchemeHandlerFactory(handler));
|
||||
registrar.AddCustomScheme(protocol, CefSchemeOptions.Secure | CefSchemeOptions.CorsEnabled | CefSchemeOptions.CspBypassing);
|
||||
}
|
||||
|
||||
private readonly SchemeHandlerFactoryLogic<CefRequest, CefResourceHandler> logic;
|
||||
|
||||
private SchemeHandlerFactory(ICustomSchemeHandler handler) {
|
||||
this.logic = new SchemeHandlerFactoryLogic<CefRequest, CefResourceHandler>(handler, CefRequestAdapter.Instance, CefResourceHandlerFactory.Instance);
|
||||
}
|
||||
|
||||
private CefResourceHandler? Create(CefRequest request) {
|
||||
return logic.Create(request);
|
||||
}
|
||||
}
|
||||
}
|
7
linux/global.json
Executable file
7
linux/global.json
Executable file
@ -0,0 +1,7 @@
|
||||
{
|
||||
"sdk": {
|
||||
"version": "5.0.0",
|
||||
"rollForward": "latestMinor",
|
||||
"allowPrerelease": false
|
||||
}
|
||||
}
|
20
linux/publish.sh
Executable file
20
linux/publish.sh
Executable file
@ -0,0 +1,20 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
if [ ! -f "TweetDuck.Linux.sln" ]; then
|
||||
echo "Missing solution file in working directory!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
mkdir -p bld/tmp/
|
||||
|
||||
dotnet build TweetDuck -c Release -r linux-x64 -o bld/tmp/
|
||||
rm bld/tmp/ref/*
|
||||
rm -r bld/tmp/ref/
|
||||
|
||||
echo "Packaging build..."
|
||||
tar czvf bld/TweetDuck.$("bld/tmp/TweetDuck" -appversion).tar.gz -C bld/tmp/ --owner=0 --group=0 --format=v7 .
|
||||
|
||||
rm -rf bld/tmp/
|
||||
|
||||
echo "Done!"
|
Loading…
Reference in New Issue
Block a user