-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathForm1.cs
More file actions
104 lines (77 loc) · 3.19 KB
/
Copy pathForm1.cs
File metadata and controls
104 lines (77 loc) · 3.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Microsoft.Web.WebView2.Core;
using Microsoft.Web.WebView2.WinForms;
namespace YouTube_desktop
{
public partial class Form1 : Form
{
public WebView2 browser;
// Store original window state to restore it later
private FormBorderStyle _previousBorderStyle;
private FormWindowState _previousWindowState;
public Form1()
{
InitializeComponent();
this.Text = "YouTube";
this.Icon = Properties.Resources.YouTube_Icon; // Ensure this exists or comment out
InitBrowser();
}
public async void InitBrowser()
{
browser = new WebView2();
browser.Dock = DockStyle.Fill;
this.Controls.Add(browser);
string userDataFolder = Path.Combine(Path.GetTempPath(), "YouTube");
var options = new CoreWebView2EnvironmentOptions();
options.AreBrowserExtensionsEnabled = true;
var env = await CoreWebView2Environment.CreateAsync(null, userDataFolder, options);
await browser.EnsureCoreWebView2Async(env);
// --- FULLSCREEN LOGIC START ---
browser.CoreWebView2.ContainsFullScreenElementChanged += (sender, args) =>
{
if (browser.CoreWebView2.ContainsFullScreenElement)
{
// 1. Save current state
_previousBorderStyle = this.FormBorderStyle;
_previousWindowState = this.WindowState;
// 2. The "Jolt": Switch to Normal first if already Maximized
// This forces Windows to recognize the change in FormBorderStyle
this.WindowState = FormWindowState.Normal;
this.FormBorderStyle = FormBorderStyle.None;
this.WindowState = FormWindowState.Maximized;
this.TopMost = true;
}
else
{
// Exiting Fullscreen
this.TopMost = false;
this.FormBorderStyle = _previousBorderStyle;
this.WindowState = _previousWindowState;
}
};
// --- FULLSCREEN LOGIC END ---
// Get the directory where your .exe is located
string baseDirectory = AppDomain.CurrentDomain.BaseDirectory;
// Combine it with your extension folder name
// Assuming the "uBlock0.chromium" folder is sitting right next to your .exe
string extensionPath = Path.Combine(baseDirectory, "Bloker");
try
{
await browser.CoreWebView2.Profile.AddBrowserExtensionAsync(extensionPath);
}
catch (Exception ex)
{
}
browser.CoreWebView2.Navigate("https://www.youtube.com/");
}
}
}