Skip to content
This repository has been archived by the owner on Oct 23, 2022. It is now read-only.

Commit

Permalink
R10-ready (webpages n stuff)
Browse files Browse the repository at this point in the history
  • Loading branch information
torchgm committed Oct 6, 2020
1 parent 16ab03d commit 37687d5
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 37 deletions.
8 changes: 4 additions & 4 deletions ActiveDesktop/ADPWebWallpaper.xaml
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<Window
<Window x:Class="ActiveDesktop.ADPWebWallpaper"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:ActiveDesktop"
xmlns:Controls="clr-namespace:Microsoft.Toolkit.Wpf.UI.Controls;assembly=Microsoft.Toolkit.Wpf.UI.Controls.WebView" x:Class="ActiveDesktop.ADPWebWallpaper"
xmlns:wv2="clr-namespace:Microsoft.Web.WebView2.Wpf;assembly=Microsoft.Web.WebView2.Wpf"
mc:Ignorable="d"
ResizeMode="NoResize"
WindowStartupLocation="CenterScreen"
WindowState="Maximized" WindowStyle="None"
Title="ADPWebWallpaper" Height="800" Width="800">
<Grid>
<Controls:WebView x:Name="WebView" NavigationCompleted="WebView_NavigationCompleted"/>
<wv2:WebView2 x:Name="WebView2" NavigationCompleted="WebView2_NavigationCompleted" CoreWebView2Ready="WebView2_CoreWebView2Ready"/>
</Grid>
</Window>
</Window>
91 changes: 63 additions & 28 deletions ActiveDesktop/ADPWebWallpaper.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
using Microsoft.Toolkit.Win32.UI.Controls.Interop.WinRT;
using System;
using System.Windows;
using System.Windows.Threading;
using System.Threading.Tasks;
using System.Windows;

namespace ActiveDesktop
{
Expand All @@ -16,52 +12,91 @@ public ADPWebWallpaper(string url)
{
navto = url;
InitializeComponent();
WebView.Loaded += WebView_Loaded;
System.Diagnostics.Debug.WriteLine("Window created");
WebView2.EnsureCoreWebView2Async();
Show();
}

private void WebView_Loaded(object sender, RoutedEventArgs e)
{
Potato();
System.Diagnostics.Debug.WriteLine("Window created");
}

private void Potato()
{
if (navto.Contains("https://www.youtube.com/watch?v="))
{
navto = "https://www.youtube.com/embed/" + navto.Substring(32);
}
if (navto.Contains("https://youtube.com/watch?v="))
{
navto = "https://www.youtube.com/embed/" + navto.Substring(28);
}
if (navto.Contains("http://www.youtube.com/watch?v="))
{
navto = "https://www.youtube.com/embed/" + navto.Substring(31);
}
if (navto.Contains("http://youtube.com/watch?v="))
{
navto = "https://www.youtube.com/embed/" + navto.Substring(27);
}
if (navto.Contains("https://www.youtu.be/"))
{
navto = "https://www.youtube.com/embed/" + navto.Substring(21);
}
if (navto.Contains("https://youtu.be/"))
{
navto = "https://www.youtube.com/embed/" + navto.Substring(17);
}
if (navto.Contains("http://www.youtu.be/"))
{
navto = "https://www.youtube.com/embed/" + navto.Substring(20);
}
if (navto.Contains("http://youtu.be/"))
{
navto = "https://www.youtube.com/embed/" + navto.Substring(16);
}

System.Diagnostics.Debug.WriteLine("Potatoing to " + navto);
WebView.Navigate(navto);
WebView2.CoreWebView2.Navigate(navto);
System.Diagnostics.Debug.WriteLine("Potatoed");

}

private void WebView_NavigationCompleted(object sender, WebViewControlNavigationCompletedEventArgs e)
private void WebView2_NavigationCompleted(object sender, Microsoft.Web.WebView2.Core.CoreWebView2NavigationCompletedEventArgs e)
{
if (navto.Contains("youtube.com/watch?v=") || navto.Contains("youtu.be/"))
{
System.Diagnostics.Debug.WriteLine("Detected need to trigger fullscreen on YouTube");
YouTubeFullscreen();
}
if (navto.Contains("shadertoy.com/view/"))
{
System.Diagnostics.Debug.WriteLine("Detected need to trigger fullscreen on ShaderToy");
ShaderToyFullscreen();

if (navto.Contains("shadertoy.com/view/"))
{
System.Diagnostics.Debug.WriteLine("Detected need to trigger fullscreen on ShaderToy");
ShaderToyFullscreen();
}
if (navto.Contains("youtube.com/embed/"))
{
YouTubeFullscreen();
}
}
}

private async void YouTubeFullscreen()
{
await WebView.InvokeScriptAsync("eval", new string[] { @"document.getElementsByClassName('ytp-fullscreen-button')[0].click();" });
await WebView.InvokeScriptAsync("eval", new string[] { @"document.getElementsByClassName('html5-main-video')[0].loop = true;" });
await WebView2.ExecuteScriptAsync("document.getElementsByClassName('ytp-large-play-button')[0].click();");

await WebView2.ExecuteScriptAsync("document.getElementsByClassName('ytp-fullscreen-button')[0].click();");

await WebView2.ExecuteScriptAsync("document.getElementsByClassName('ytp-mute-button')[0].click();");

await WebView2.ExecuteScriptAsync("document.getElementsByClassName('html5-main-video')[0].loop = true;");


System.Diagnostics.Debug.WriteLine("Tried and probably failed to make YouTube fullscreen and looping");
}

private async void ShaderToyFullscreen()
{
await WebView.InvokeScriptAsync("eval", new string[] { "myFullScreen.click();" });
//await WebView.InvokeScriptAsync("eval", new string[] { "document.getElementsByClassName('uiButton')[5].click();" });
await WebView2.ExecuteScriptAsync("myFullScreen.click();");
System.Diagnostics.Debug.WriteLine("Tried and probably failed to make ShaderToy fullscreen");
}

private void WebView2_CoreWebView2Ready(object sender, System.EventArgs e)
{
System.Diagnostics.Debug.WriteLine("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA");
Potato();
}
}
}
4 changes: 2 additions & 2 deletions ActiveDesktop/ActiveDesktop.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,8 @@
<PackageReference Include="Hardcodet.NotifyIcon.Wpf">
<Version>1.0.8</Version>
</PackageReference>
<PackageReference Include="Microsoft.Toolkit.Wpf.UI.Controls.WebView">
<Version>6.1.2</Version>
<PackageReference Include="Microsoft.Web.WebView2">
<Version>0.9.579-prerelease</Version>
</PackageReference>
<PackageReference Include="Microsoft.Windows.SDK.Contracts">
<Version>10.0.18362.2005</Version>
Expand Down
6 changes: 3 additions & 3 deletions ActiveDesktop/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
using DesktopBridge;
using Windows.ApplicationModel;
using System.Threading.Tasks;
using Microsoft.Toolkit.Win32.UI.Controls.Interop.WinRT;

namespace ActiveDesktop
{
Expand Down Expand Up @@ -1267,7 +1266,7 @@ private void PinApp(string hwnd)
}

// Actually deals with window properties or smth idk
async void WindowFromListToDesktop(App i, int t)
private void WindowFromListToDesktop(App i, int t)
{
try
{
Expand Down Expand Up @@ -1314,7 +1313,8 @@ async void WindowFromListToDesktop(App i, int t)
{
try
{
IntPtr hweb = await StartWebWallpaper(i.Flags);
ADPWebWallpaper GeneratedWebWallpaper = new ADPWebWallpaper(i.Flags);
IntPtr hweb = new WindowInteropHelper(GeneratedWebWallpaper).Handle;
System.Diagnostics.Debug.WriteLine(hweb.ToString());
Thread.Sleep(Convert.ToInt32(t));
LogEntry("[ADP] Started web window");
Expand Down

0 comments on commit 37687d5

Please sign in to comment.