diff --git a/SLBr.sln b/SLBr.sln index a375325..5c2ecad 100644 --- a/SLBr.sln +++ b/SLBr.sln @@ -7,6 +7,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SLBr", "SLBr\SLBr.csproj", EndProject Project("{C7167F0D-BC9F-4E6E-AFE1-012C56B48DB5}") = "SLBr Packaging Project", "SLBr Packaging Project\SLBr Packaging Project.wapproj", "{D4FC58AC-26D9-41C6-8F97-D28A935C18F3}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Utility Service", "Utility Service\Utility Service.csproj", "{01B6FD23-3E66-40DA-A849-45513AEF573D}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -71,6 +73,26 @@ Global {D4FC58AC-26D9-41C6-8F97-D28A935C18F3}.Release|x86.ActiveCfg = Release|x86 {D4FC58AC-26D9-41C6-8F97-D28A935C18F3}.Release|x86.Build.0 = Release|x86 {D4FC58AC-26D9-41C6-8F97-D28A935C18F3}.Release|x86.Deploy.0 = Release|x86 + {01B6FD23-3E66-40DA-A849-45513AEF573D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {01B6FD23-3E66-40DA-A849-45513AEF573D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {01B6FD23-3E66-40DA-A849-45513AEF573D}.Debug|ARM.ActiveCfg = Debug|Any CPU + {01B6FD23-3E66-40DA-A849-45513AEF573D}.Debug|ARM.Build.0 = Debug|Any CPU + {01B6FD23-3E66-40DA-A849-45513AEF573D}.Debug|ARM64.ActiveCfg = Debug|Any CPU + {01B6FD23-3E66-40DA-A849-45513AEF573D}.Debug|ARM64.Build.0 = Debug|Any CPU + {01B6FD23-3E66-40DA-A849-45513AEF573D}.Debug|x64.ActiveCfg = Debug|Any CPU + {01B6FD23-3E66-40DA-A849-45513AEF573D}.Debug|x64.Build.0 = Debug|Any CPU + {01B6FD23-3E66-40DA-A849-45513AEF573D}.Debug|x86.ActiveCfg = Debug|Any CPU + {01B6FD23-3E66-40DA-A849-45513AEF573D}.Debug|x86.Build.0 = Debug|Any CPU + {01B6FD23-3E66-40DA-A849-45513AEF573D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {01B6FD23-3E66-40DA-A849-45513AEF573D}.Release|Any CPU.Build.0 = Release|Any CPU + {01B6FD23-3E66-40DA-A849-45513AEF573D}.Release|ARM.ActiveCfg = Release|Any CPU + {01B6FD23-3E66-40DA-A849-45513AEF573D}.Release|ARM.Build.0 = Release|Any CPU + {01B6FD23-3E66-40DA-A849-45513AEF573D}.Release|ARM64.ActiveCfg = Release|Any CPU + {01B6FD23-3E66-40DA-A849-45513AEF573D}.Release|ARM64.Build.0 = Release|Any CPU + {01B6FD23-3E66-40DA-A849-45513AEF573D}.Release|x64.ActiveCfg = Release|Any CPU + {01B6FD23-3E66-40DA-A849-45513AEF573D}.Release|x64.Build.0 = Release|Any CPU + {01B6FD23-3E66-40DA-A849-45513AEF573D}.Release|x86.ActiveCfg = Release|Any CPU + {01B6FD23-3E66-40DA-A849-45513AEF573D}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/SLBr/App.xaml b/SLBr/App.xaml index cdee871..0b9bf66 100644 --- a/SLBr/App.xaml +++ b/SLBr/App.xaml @@ -2,7 +2,7 @@ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:SLBr" - StartupUri="MainWindow.xaml" Startup="Application_Startup"> + StartupUri="SplashScreen.xaml" Startup="Application_Startup"> diff --git a/SLBr/Controls/CredentialsDialog.cs b/SLBr/Controls/CredentialsDialog.cs new file mode 100644 index 0000000..076802d --- /dev/null +++ b/SLBr/Controls/CredentialsDialog.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SLBr.Controls +{ + public class CredentialsDialogResult + { + public bool Accepted; + public string Username; + public string Password; + + public CredentialsDialogResult(bool? _Accepted, string _Username, string _Password) + { + Accepted = (bool)_Accepted; + Username = _Username; + Password = _Password; + } + } + public static class CredentialsDialog + { + public static CredentialsDialogResult Show(string Question) + { + CredentialsDialogWindow _CredentialsDialogWindow = new CredentialsDialogWindow(Question); + _CredentialsDialogWindow.Topmost = true; + return new CredentialsDialogResult(_CredentialsDialogWindow.ShowDialog(), _CredentialsDialogWindow.Username, _CredentialsDialogWindow.Password); + } + } +} diff --git a/SLBr/Controls/CredentialsDialogWindow.xaml b/SLBr/Controls/CredentialsDialogWindow.xaml new file mode 100644 index 0000000..3b907d2 --- /dev/null +++ b/SLBr/Controls/CredentialsDialogWindow.xaml @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + + Username + + + + Password + + + + + + + + + + diff --git a/SLBr/Controls/CredentialsDialogWindow.xaml.cs b/SLBr/Controls/CredentialsDialogWindow.xaml.cs new file mode 100644 index 0000000..beaa8cf --- /dev/null +++ b/SLBr/Controls/CredentialsDialogWindow.xaml.cs @@ -0,0 +1,70 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Animation; +using System.Windows.Media.Imaging; +using System.Windows.Shapes; + +namespace SLBr.Controls +{ + /// + /// Interaction logic for CredentialsDialog.xaml + /// + public partial class CredentialsDialogWindow : Window + { + public CredentialsDialogWindow(string Question) + { + InitializeComponent(); + + lblQuestion.Content = Question; + ApplyTheme(MainWindow.Instance.GetTheme()); + } + + public void ApplyTheme(Theme _Theme) + { + //Resources["PrimaryBrush"] = new SolidColorBrush(_Theme.PrimaryColor); + //Resources["FontBrush"] = new SolidColorBrush(_Theme.FontColor); + //Resources["BorderBrush"] = new SolidColorBrush(_Theme.BorderColor); + //Resources["UnselectedTabBrush"] = new SolidColorBrush(_Theme.UnselectedTabColor); + //Resources["ControlFontBrush"] = new SolidColorBrush(_Theme.ControlFontColor); + + Resources["PrimaryBrushColor"] = _Theme.PrimaryColor; + Resources["FontBrushColor"] = _Theme.FontColor; + Resources["BorderBrushColor"] = _Theme.BorderColor; + Resources["UnselectedTabBrushColor"] = _Theme.UnselectedTabColor; + Resources["ControlFontBrushColor"] = _Theme.ControlFontColor; + + //Storyboard s = (Storyboard)Resources["ToBorderBrushColor"]; + //s.SetValue(value) + + //Resources["ToBorderBrushColor"] = new Storyboard(new ColorAnimation()).Color; + } + private void DialogOk_Click(object sender, RoutedEventArgs e) + { + DialogResult = true; + } + + private void Window_ContentRendered(object sender, EventArgs e) + { + UsernameTextBox.SelectAll(); + UsernameTextBox.Focus(); + } + + public string Username + { + get { return UsernameTextBox.Text; } + } + public string Password + { + get { return PasswordTextBox.Text; } + } + } +} diff --git a/SLBr/Controls/PopupBrowser.xaml b/SLBr/Controls/PopupBrowser.xaml new file mode 100644 index 0000000..bbb89ec --- /dev/null +++ b/SLBr/Controls/PopupBrowser.xaml @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + diff --git a/SLBr/Controls/PopupBrowser.xaml.cs b/SLBr/Controls/PopupBrowser.xaml.cs new file mode 100644 index 0000000..f8287fc --- /dev/null +++ b/SLBr/Controls/PopupBrowser.xaml.cs @@ -0,0 +1,116 @@ +using CefSharp; +using CefSharp.DevTools; +using CefSharp.Wpf.HwndHost; +using System; +using System.Runtime.InteropServices; +using System.Security.Policy; +using System.Windows; +using System.Windows.Interop; +using System.Windows.Media; +using System.Windows.Media.Imaging; + +namespace SLBr.Controls +{ + /// + /// Interaction logic for PopupBrowser.xaml + /// + public partial class PopupBrowser : Window + { + [DllImport("dwmapi.dll", PreserveSig = true)] + public static extern int DwmSetWindowAttribute(IntPtr hwnd, int attr, ref int attrValue, int attrSize); + + ChromiumWebBrowser _Browser; + Theme CurrentTheme; + string InitialAddress; + public PopupBrowser(string _Address, int _Width, int _Height) + { + InitializeComponent(); + InitialAddress = _Address; + if (_Width != -1) + Width = _Width; + if (_Height != -1) + Height = _Height; + } + + private void Browser_StatusMessage(object? sender, StatusMessageEventArgs e) + { + Application.Current.Dispatcher.BeginInvoke(new Action(delegate + { + //StatusBar.Visibility = string.IsNullOrEmpty(e.Value) ? Visibility.Collapsed : Visibility.Visible; + StatusBarPopup.IsOpen = !string.IsNullOrEmpty(e.Value); + StatusMessage.Text = e.Value; + })); + } + + private void Browser_LoadingStateChanged(object? sender, LoadingStateChangedEventArgs e) + { + if (!_Browser.IsBrowserInitialized) + return; + Application.Current.Dispatcher.BeginInvoke(new Action(delegate + { + Icon = new BitmapImage(new Uri("https://www.google.com/s2/favicons?sz=24&domain=" + Utils.Host(_Browser.Address))); + DevToolsClient _DevToolsClient = _Browser.GetDevToolsClient(); + _DevToolsClient.Emulation.SetAutoDarkModeOverrideAsync(CurrentTheme.DarkWebPage ? bool.Parse(MainWindow.Instance.MainSave.Get("DarkWebPage")) : false); + })); + } + + public void ApplyTheme(Theme _Theme) + { + CurrentTheme = _Theme; + int SetDarkTitleBar = _Theme.DarkTitleBar ? 1 : 0; + DwmSetWindowAttribute(new WindowInteropHelper(this).Handle, (int)DWMWINDOWATTRIBUTE.DWMWA_USE_IMMERSIVE_DARK_MODE, ref SetDarkTitleBar, Marshal.SizeOf(true)); + + //Resources["PrimaryBrush"] = new SolidColorBrush(_Theme.PrimaryColor); + //Resources["FontBrush"] = new SolidColorBrush(_Theme.FontColor); + //Resources["BorderBrush"] = new SolidColorBrush(_Theme.BorderColor); + //Resources["UnselectedTabBrush"] = new SolidColorBrush(_Theme.UnselectedTabColor); + //Resources["ControlFontBrush"] = new SolidColorBrush(_Theme.ControlFontColor); + + Resources["PrimaryBrushColor"] = _Theme.PrimaryColor; + Resources["FontBrushColor"] = _Theme.FontColor; + Resources["BorderBrushColor"] = _Theme.BorderColor; + Resources["UnselectedTabBrushColor"] = _Theme.UnselectedTabColor; + Resources["ControlFontBrushColor"] = _Theme.ControlFontColor; + } + + private void Browser_TitleChanged(object sender, DependencyPropertyChangedEventArgs e) + { + Title = $"{e.NewValue} - SLBr"; + } + + private void Window_Loaded(object sender, RoutedEventArgs e) + { + ApplyTheme(MainWindow.Instance.GetTheme()); + _Browser = new ChromiumWebBrowser(); + _Browser.Address = InitialAddress; + + _Browser.LifeSpanHandler = MainWindow.Instance._LifeSpanHandler; + _Browser.DownloadHandler = MainWindow.Instance._DownloadHandler; + _Browser.RequestHandler = MainWindow.Instance._RequestHandler; + //_Browser.MenuHandler = MainWindow.Instance._ContextMenuHandler; + //_Browser.KeyboardHandler = MainWindow.Instance._KeyboardHandler; + //_Browser.JsDialogHandler = MainWindow.Instance._JsDialogHandler; + + _Browser.TitleChanged += Browser_TitleChanged; + _Browser.LoadingStateChanged += Browser_LoadingStateChanged; + _Browser.ZoomLevelIncrement = 0.5f; + _Browser.StatusMessage += Browser_StatusMessage; + _Browser.AllowDrop = true; + _Browser.IsManipulationEnabled = true; + + _Browser.BrowserSettings = new BrowserSettings + { + WindowlessFrameRate = MainWindow.Instance.Framerate, + Javascript = MainWindow.Instance.Javascript, + ImageLoading = MainWindow.Instance.LoadImages, + LocalStorage = MainWindow.Instance.LocalStorage, + Databases = MainWindow.Instance.Databases, + WebGl = MainWindow.Instance.WebGL, + BackgroundColor = System.Drawing.Color.Black.ToUInt() + }; + + WebContent.Children.Add(_Browser); + RenderOptions.SetBitmapScalingMode(_Browser, BitmapScalingMode.LowQuality); + } + } +} diff --git a/SLBr/Controls/ToastBox.xaml b/SLBr/Controls/ToastBox.xaml index bb92123..45ed9e9 100644 --- a/SLBr/Controls/ToastBox.xaml +++ b/SLBr/Controls/ToastBox.xaml @@ -5,12 +5,12 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:SLBr.Controls" mc:Ignorable="d" - Title="Notification Popup" Height="90" Width="300" SizeToContent="Height" WindowStyle="None" ResizeMode="NoResize" Topmost="True" AllowsTransparency="True" Background="Transparent" ShowInTaskbar="False"> + Title="Notification Popup" HorizontalAlignment="Right" VerticalAlignment="Bottom" Height="90" Width="300" SizeToContent="Height" WindowStyle="None" AllowsTransparency="True" ResizeMode="NoResize" Topmost="True" Background="Transparent" ShowInTaskbar="False"> - + diff --git a/SLBr/Controls/ToastBox.xaml.cs b/SLBr/Controls/ToastBox.xaml.cs index 706f47d..c45e915 100644 --- a/SLBr/Controls/ToastBox.xaml.cs +++ b/SLBr/Controls/ToastBox.xaml.cs @@ -1,4 +1,5 @@ -using System; +using Microsoft.VisualBasic; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -8,6 +9,7 @@ using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; +using System.Windows.Interop; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Shapes; @@ -41,20 +43,35 @@ public ToastBox(string _Title, string _Description, int Delay, Theme _Theme = nu Description.Text = _Description; timer.Interval = new TimeSpan(0, 0, Delay); timer.Start(); - var desktopWorkingArea = SystemParameters.WorkArea; - Left = desktopWorkingArea.Right - this.Width; - Top = desktopWorkingArea.Bottom - this.Height; + var Monitor = MonitorMethods.MonitorFromWindow(new WindowInteropHelper(MainWindow.Instance).EnsureHandle(), MonitorMethods.MONITOR_DEFAULTTONEAREST); + + if (Monitor != IntPtr.Zero) + { + var MonitorInfo = new MonitorMethods.NativeMonitorInfo(); + MonitorMethods.GetMonitorInfo(Monitor, MonitorInfo); + //var desktopWorkingArea = SystemParameters.WorkArea; + var desktopWorkingArea = MonitorInfo.Monitor; + Left = desktopWorkingArea.Right - this.Width - 2.5; + Top = desktopWorkingArea.Bottom - this.Height - 37.5;// + 10 + } + if (_Theme == null) _Theme = MainWindow.Instance.GetTheme(); ApplyTheme(_Theme); } public void ApplyTheme(Theme _Theme) { - Resources["PrimaryBrush"] = new SolidColorBrush(_Theme.PrimaryColor); - Resources["FontBrush"] = new SolidColorBrush(_Theme.FontColor); - Resources["BorderBrush"] = new SolidColorBrush(_Theme.BorderColor); - Resources["UnselectedTabBrush"] = new SolidColorBrush(_Theme.UnselectedTabColor); - Resources["ControlFontBrush"] = new SolidColorBrush(_Theme.ControlFontColor); + //Resources["PrimaryBrush"] = new SolidColorBrush(_Theme.PrimaryColor); + //Resources["FontBrush"] = new SolidColorBrush(_Theme.FontColor); + //Resources["BorderBrush"] = new SolidColorBrush(_Theme.BorderColor); + //Resources["UnselectedTabBrush"] = new SolidColorBrush(_Theme.UnselectedTabColor); + //Resources["ControlFontBrush"] = new SolidColorBrush(_Theme.ControlFontColor); + + Resources["PrimaryBrushColor"] = _Theme.PrimaryColor; + Resources["FontBrushColor"] = _Theme.FontColor; + Resources["BorderBrushColor"] = _Theme.BorderColor; + Resources["UnselectedTabBrushColor"] = _Theme.UnselectedTabColor; + Resources["ControlFontBrushColor"] = _Theme.ControlFontColor; } private void ToastClose_Click(object sender, RoutedEventArgs e) { diff --git a/SLBr/Converters/ColorToSolidConverter.cs b/SLBr/Converters/ColorToSolidConverter.cs new file mode 100644 index 0000000..115eca5 --- /dev/null +++ b/SLBr/Converters/ColorToSolidConverter.cs @@ -0,0 +1,32 @@ +using System; +using System.Windows.Data; +using System.Windows.Media; + +namespace SLBr.Converters +{ + public class ColorToSolidConverter : IValueConverter + { + public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) + { + if (value == null) + return null; + + if (value is Color) + return new SolidColorBrush((Color)value); + + throw new InvalidOperationException("Unsupported type [" + value.GetType().Name + "], ColorToSolidConverter.Convert()"); + } + + public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) + { + if (value == null) + return null; + + if (value is SolidColorBrush) + return ((SolidColorBrush)value).Color; + + throw new InvalidOperationException("Unsupported type [" + value.GetType().Name + "], ColorToSolidConverter.ConvertBack()"); + } + + } +} diff --git a/SLBr/Converters/SolidToColorConverter.cs b/SLBr/Converters/SolidToColorConverter.cs new file mode 100644 index 0000000..ae71d29 --- /dev/null +++ b/SLBr/Converters/SolidToColorConverter.cs @@ -0,0 +1,35 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Data; +using System.Windows.Media; + +namespace SLBr.Converters +{ + public class SolidToColorConverter : IValueConverter + { + public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) + { + if (value == null) + return null; + + if (value is SolidColorBrush) + return ((SolidColorBrush)value).Color; + + throw new InvalidOperationException("Unsupported type [" + value.GetType().Name + "], SolidToColorConverter.ConvertBack()"); + } + + public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) + { + if (value == null) + return null; + + if (value is Color) + return new SolidColorBrush((Color)value); + + throw new InvalidOperationException("Unsupported type [" + value.GetType().Name + "], SolidToColorConverter.Convert()"); + } + } +} diff --git a/SLBr/Handlers/AudioHandler.cs b/SLBr/Handlers/AudioHandler.cs new file mode 100644 index 0000000..9d690df --- /dev/null +++ b/SLBr/Handlers/AudioHandler.cs @@ -0,0 +1,85 @@ +using CefSharp; +using CefSharp.Enums; +using CefSharp.Structs; +using SLBr.Controls; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Shapes; + +namespace SLBr.Handlers +{ + public class AudioHandler : IAudioHandler + { + private bool isDisposed; + + public bool IsDisposed + { + get { return isDisposed; } + } + + bool IAudioHandler.GetAudioParameters(IWebBrowser chromiumWebBrowser, IBrowser browser, ref AudioParameters parameters) + { + return GetAudioParameters(chromiumWebBrowser, browser, ref parameters); + } + + protected virtual bool GetAudioParameters(IWebBrowser chromiumWebBrowser, IBrowser browser, ref AudioParameters parameters) + { + return false; + } + void IAudioHandler.OnAudioStreamStarted(IWebBrowser chromiumWebBrowser, IBrowser browser, AudioParameters parameters, int channels) + { + OnAudioStreamStarted(chromiumWebBrowser, browser, parameters, channels); + } + + protected virtual void OnAudioStreamStarted(IWebBrowser chromiumWebBrowser, IBrowser browser, AudioParameters parameters, int channels) + { + AudioPlaying = true; + MessageBox.Show(AudioPlaying.ToString()); + } + + void IAudioHandler.OnAudioStreamPacket(IWebBrowser chromiumWebBrowser, IBrowser browser, IntPtr data, int noOfFrames, long pts) + { + OnAudioStreamPacket(chromiumWebBrowser, browser, data, noOfFrames, pts); + } + + protected virtual void OnAudioStreamPacket(IWebBrowser chromiumWebBrowser, IBrowser browser, IntPtr data, int noOfFrames, long pts) + { + } + + void IAudioHandler.OnAudioStreamStopped(IWebBrowser chromiumWebBrowser, IBrowser browser) + { + OnAudioStreamStopped(chromiumWebBrowser, browser); + } + protected virtual void OnAudioStreamStopped(IWebBrowser chromiumWebBrowser, IBrowser browser) + { + AudioPlaying = false; + MessageBox.Show(AudioPlaying.ToString()); + } + + void IAudioHandler.OnAudioStreamError(IWebBrowser chromiumWebBrowser, IBrowser browser, string errorMessage) + { + OnAudioStreamError(chromiumWebBrowser, browser, errorMessage); + } + + protected virtual void OnAudioStreamError(IWebBrowser chromiumWebBrowser, IBrowser browser, string errorMessage) + { + + } + + protected virtual void Dispose(bool disposing) + { + isDisposed = true; + } + public void Dispose() + { + Dispose(disposing: true); + GC.SuppressFinalize(this); + } + public bool AudioPlaying; + } +} diff --git a/SLBr/Handlers/DisplayHandler.cs b/SLBr/Handlers/DisplayHandler.cs index 0491fa8..eaa4b49 100644 --- a/SLBr/Handlers/DisplayHandler.cs +++ b/SLBr/Handlers/DisplayHandler.cs @@ -4,10 +4,14 @@ using SLBr.Pages; using System; using System.Collections.Generic; +using System.Drawing; +using System.IO; using System.Linq; +using System.Net; using System.Text; using System.Threading.Tasks; using System.Windows; +using System.Windows.Media.Imaging; namespace SLBr.Handlers { @@ -19,7 +23,6 @@ public DisplayHandler(Browser BrowserView) _BrowserView = BrowserView; } - //Setter HideTabSetter = new Setter(UIElement.VisibilityProperty, Visibility.Collapsed); public void OnAddressChanged(IWebBrowser chromiumWebBrowser, AddressChangedEventArgs addressChangedArgs) { Application.Current.Dispatcher.BeginInvoke(new Action(delegate @@ -28,7 +31,10 @@ public void OnAddressChanged(IWebBrowser chromiumWebBrowser, AddressChangedEvent if (_BrowserView.AddressBox.Text != OutputUrl) { if (_BrowserView.CanChangeAddressBox()) + { _BrowserView.AddressBox.Text = OutputUrl; + _BrowserView.AddressBoxPlaceholder.Text = ""; + } _BrowserView.AddressBox.Tag = addressChangedArgs.Address; } })); @@ -51,6 +57,13 @@ public bool OnCursorChange(IWebBrowser chromiumWebBrowser, IBrowser browser, Int public void OnFaviconUrlChange(IWebBrowser chromiumWebBrowser, IBrowser browser, IList urls) { + /*Application.Current.Dispatcher.BeginInvoke(new Action(delegate + { + foreach (string x in urls) + { + _BrowserView.Tab.Icon = new BitmapImage(new Uri(x)); + } + }));*/ } public void OnFullscreenModeChange(IWebBrowser chromiumWebBrowser, IBrowser browser, bool fullscreen) diff --git a/SLBr/Handlers/DownloadHandler.cs b/SLBr/Handlers/DownloadHandler.cs index 96dbe14..b9e0190 100644 --- a/SLBr/Handlers/DownloadHandler.cs +++ b/SLBr/Handlers/DownloadHandler.cs @@ -38,8 +38,11 @@ public void OnDownloadUpdated(IWebBrowser chromiumWebBrowser, IBrowser browser, //OnDownloadUpdatedFired?.Invoke(this, downloadItem); MainWindow.Instance.UpdateDownloadItem(downloadItem); - if (downloadItem.IsInProgress && MainWindow.Instance.CanceledDownloads.Contains(downloadItem.Id)) - callback.Cancel(); + if (downloadItem.IsInProgress) + { + if (MainWindow.Instance.CanceledDownloads.Contains(downloadItem.Id)) + callback.Cancel(); + } } } } diff --git a/SLBr/Handlers/LifeSpanHandler.cs b/SLBr/Handlers/LifeSpanHandler.cs index 5ef0c2c..9c314de 100644 --- a/SLBr/Handlers/LifeSpanHandler.cs +++ b/SLBr/Handlers/LifeSpanHandler.cs @@ -1,4 +1,5 @@ using CefSharp; +using SLBr.Controls; using System; using System.Windows; @@ -10,11 +11,21 @@ public bool OnBeforePopup(IWebBrowser browserControl, IBrowser browser, IFrame f WindowOpenDisposition targetDisposition, bool userGesture, IPopupFeatures popupFeatures, IWindowInfo windowInfo, IBrowserSettings browserSettings, ref bool noJavascriptAccess, out IWebBrowser newBrowser) { + int _Width = popupFeatures.Width != null ? (int)popupFeatures.Width : 600; + int _Height = popupFeatures.Height != null ? (int)popupFeatures.Height : 650; newBrowser = null; - Application.Current.Dispatcher.BeginInvoke(new Action(delegate + if (targetDisposition == WindowOpenDisposition.CurrentTab) + browser.MainFrame.LoadUrl(targetUrl); + else { - MainWindow.Instance.NewBrowserTab(targetUrl, 0, true, MainWindow.Instance.BrowserTabs.SelectedIndex + 1); - })); + Application.Current.Dispatcher.BeginInvoke(new Action(delegate + { + if (targetDisposition == WindowOpenDisposition.NewPopup) + new PopupBrowser(targetUrl, _Width, _Height).Show(); + else + MainWindow.Instance.NewBrowserTab(targetUrl, 0, true, MainWindow.Instance.BrowserTabs.SelectedIndex + 1); + })); + } return true; } diff --git a/SLBr/Handlers/PrivateJsObjectHandler.cs b/SLBr/Handlers/PrivateJsObjectHandler.cs index 93caaf8..b2a0ef0 100644 --- a/SLBr/Handlers/PrivateJsObjectHandler.cs +++ b/SLBr/Handlers/PrivateJsObjectHandler.cs @@ -8,7 +8,7 @@ namespace SLBr.Handlers { public class PrivateJsObjectHandler { - List UnsplashAPI = new List { //"https://picsum.photos/1920/1080", + List UnsplashAPI = new List { //"https://source.unsplash.com/1920x1080/?space", "https://source.unsplash.com/1920x1080/?nasa", "https://source.unsplash.com/1920x1080/?mountain-range", @@ -40,6 +40,8 @@ public string GetBackground() doc.LoadXml(MainWindow.Instance.TinyDownloader.DownloadString("http://www.bing.com/hpimagearchive.aspx?format=xml&idx=0&n=1&mbl=1&mkt=en-US")); Url = @"http://www.bing.com/" + doc.SelectSingleNode(@"/images/image/url").InnerText; } + else if (BackgroundImage == "Lorem Picsum") + Url = "https://picsum.photos/1920/1080"; else if (BackgroundImage == "Custom") Url = MainWindow.Instance.MainSave.Get("CustomBackgroundImage"); } diff --git a/SLBr/Handlers/RequestHandler.cs b/SLBr/Handlers/RequestHandler.cs index 911e856..6e1463b 100644 --- a/SLBr/Handlers/RequestHandler.cs +++ b/SLBr/Handlers/RequestHandler.cs @@ -1,5 +1,6 @@ using CefSharp; using CefSharp.Wpf.HwndHost; +using SLBr.Controls; using SLBr.Pages; using System; using System.Security.Cryptography.X509Certificates; @@ -17,8 +18,31 @@ public class RequestHandler : IRequestHandler public bool GetAuthCredentials(IWebBrowser chromiumWebBrowser, IBrowser browser, string originUrl, bool isProxy, string host, int port, string realm, string scheme, IAuthCallback callback) { - //callback.Continue(Username, Password); - return false; + bool _Handled = false; + + //Application.Current.Dispatcher.BeginInvoke(new Action(delegate + //{ + CredentialsDialogResult _CredentialsDialogResult = CredentialsDialog.Show($@"Sign in to {host}"); + if (_CredentialsDialogResult.Accepted == true) + { + callback.Continue(_CredentialsDialogResult.Username, _CredentialsDialogResult.Password); + _Handled = true; + } + //CredentialsDialogResult _CredentialsDialogResult = CredentialsDialog.Show($"Sign in to {host}"); + //if (_CredentialsDialogResult.Accepted == true) + //{ + // callback.Continue(_CredentialsDialogResult.Username, _CredentialsDialogResult.Password); + // _Handled = true; + //} + //})); + //MessageBoxResult dlg = MessageBox.Show("test", "e", MessageBoxButton.OK); + + //if (dlg == MessageBoxResult.OK) + //{ + // _Handled = true; + //} + + return _Handled; } public bool OnBeforeBrowse(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, IRequest request, bool userGesture, bool isRedirect) @@ -43,6 +67,9 @@ public bool OnBeforeBrowse(IWebBrowser chromiumWebBrowser, IBrowser browser, IFr //if (request.Url.EndsWith(".pdf")) // frame.LoadUrl(request.Url + "#toolbar=0"); } + //MessageBox.Show(request.Url); + else if (request.Url.StartsWith("chrome://sandbox")) + return true; return false; } public bool OnCertificateError(IWebBrowser browserControl, IBrowser browser, CefErrorCode errorCode, string requestUrl, ISslInfo sslInfo, IRequestCallback callback) @@ -74,16 +101,20 @@ public bool OnQuotaRequest(IWebBrowser browserControl, IBrowser browser, string public void OnRenderProcessTerminated(IWebBrowser browserControl, IBrowser browser, CefTerminationStatus status) { - if (Utils.CheckForInternetConnection()) - browser.Reload(true); - else + try { - Application.Current.Dispatcher.BeginInvoke(new Action(delegate + if (Utils.CheckForInternetConnection()) + browser.Reload(true); + else { - ChromiumWebBrowser _ChromiumWebBrowser = (ChromiumWebBrowser)browserControl; - _ChromiumWebBrowser.Address = $"slbr://processcrashed?s={browserControl.Address}"; - })); + Application.Current.Dispatcher.BeginInvoke(new Action(delegate + { + ChromiumWebBrowser _ChromiumWebBrowser = (ChromiumWebBrowser)browserControl; + _ChromiumWebBrowser.Address = $"slbr://processcrashed?s={browserControl.Address}"; + })); + } } + catch { } } public void OnRenderViewReady(IWebBrowser browserControl, IBrowser browser) diff --git a/SLBr/Handlers/ResourceRequestHandler.cs b/SLBr/Handlers/ResourceRequestHandler.cs index 1ead543..63faee2 100644 --- a/SLBr/Handlers/ResourceRequestHandler.cs +++ b/SLBr/Handlers/ResourceRequestHandler.cs @@ -1,9 +1,11 @@ using CefSharp; using System; +using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using static System.Net.WebRequestMethods; namespace SLBr.Handlers { @@ -53,7 +55,7 @@ public IResponseFilter GetResourceResponseFilter(IWebBrowser chromiumWebBrowser, "coin-hive.com", "coin-have.com", "adminer.com", "ad-miner.com", "coinminerz.com", "coinhive-manager.com", "coinhive.com", "prometheus.phoenixcoin.org", "coinhiveproxy.com", "jsecoin.com", "crypto-loot.com", "cryptonight.wasm", "cloudflare.solutions" };//https://v.firebog.net/hosts/static/w3kbl.txt FastHashSet Ads = new FastHashSet { - "pagead2.googlesyndication.com", "tpc.googlesyndication.com", "googletagservices.com", "googletagmanager.com", "ade.googlesyndication.com", "pagead2.googleadservices.com", "adservice.google.com", "googleadservices.com", + "ads.google.com", "pagead2.googlesyndication.com", "tpc.googlesyndication.com", "googletagservices.com", "googletagmanager.com", "ade.googlesyndication.com", "pagead2.googleadservices.com", "adservice.google.com", "googleadservices.com", "googleads2.g.doubleclick.net", "googleads3.g.doubleclick.net", "googleads4.g.doubleclick.net", "googleads5.g.doubleclick.net", "googleads6.g.doubleclick.net", "googleads7.g.doubleclick.net", "googleads8.g.doubleclick.net", "googleads9.g.doubleclick.net", "doubleclick.net", "stats.g.doubleclick.net", "ad.doubleclick.net", "ads.doubleclick.net", "ad.mo.doubleclick.net", "ad-g.doubleclick.net", "cm.g.doubleclick.net", "static.doubleclick.net", "m.doubleclick.net", "mediavisor.doubleclick.net", "pubads.g.doubleclick.net", "securepubads.g.doubleclick.net", "www3.doubleclick.net", "secure-ds.serving-sys.com", "s.innovid.com", "innovid.com", "dts.innovid.com", @@ -61,7 +63,7 @@ public IResponseFilter GetResourceResponseFilter(IWebBrowser chromiumWebBrowser, "gads.pubmatic.com", "ads.pubmatic.com",// "image6.pubmatic.com", "ads.facebook.com", "an.facebook.com", "ad.youtube.com", "ads.youtube.com", "youtube.cleverads.vn"/*, "yt3.ggpht.com"*/, - "ads.tiktok.com", "ads-sg.tiktok.com", + "ads.tiktok.com", "ads-sg.tiktok.com", "ads.adthrive.com", "ads.reddit.com", "d.reddit.com", "rereddit.com", "events.redditmedia.com", "ads-twitter.com", "static.ads-twitter.com", "ads-api.twitter.com", "advertising.twitter.com", "ads.pinterest.com", "ads-dev.pinterest.com", @@ -69,7 +71,7 @@ public IResponseFilter GetResourceResponseFilter(IWebBrowser chromiumWebBrowser, "ads.linkedin.com", "static.media.net", "media.net", "adservetx.media.net", "media.fastclick.net", "cdn.fastclick.net", - "global.adserver.yahoo.com", "ads.yahoo.com", "ads.yap.yahoo.com", + "global.adserver.yahoo.com", "ads.yahoo.com", "ads.yap.yahoo.com", "adserver.yahoo.com", "yandexadexchange.net", "adsdk.yandex.ru", "files.adform.net", "static.adsafeprotected.com", "pixel.adsafeprotected.com", @@ -85,18 +87,20 @@ public IResponseFilter GetResourceResponseFilter(IWebBrowser chromiumWebBrowser, "scdn.cxense.com", "adserver.juicyads.com", "a.realsrv.com", "mc.yandex.ru", "a.vdo.ai", + "ads.msn.com", "adnxs.com", "adnexus.net", "bingads.microsoft.com", "dt.adsafeprotected.com", - "z-na.amazon-adsystem.com", "aax-us-east.amazon-adsystem.com", "fls-na.amazon-adsystem.com", "z-na.amazon-adsystem.com", + "amazonaax.com", "z-na.amazon-adsystem.com", "aax-us-east.amazon-adsystem.com", "fls-na.amazon-adsystem.com", "z-na.amazon-adsystem.com", "ads.betweendigital.com", "rtb.adpone.com", "ads.themoneytizer.com", "bidder.criteo.com", "bidder.criteo.com", "bidder.criteo.com", "secure-assets.rubiconproject.com", "eus.rubiconproject.com", "fastlane.rubiconproject.com", "pixel.rubiconproject.com", "prebid-server.rubiconproject.com", "ids.ad.gt", "powerad.ai", "hb.brainlyads.com", "pixel.quantserve.com", "ads.anura.io", "static.getclicky.com", "ad.turn.com", "rtb.mfadsrvr.com", "ad.mrtnsvr.com", "s.ad.smaato.net", "rtb-csync.smartadserver.com", "ssbsync.smartadserver.com", "adpush.technoratimedia.com", "pixel.tapad.com", "secure.adnxs.com", "data.adsrvr.org", "px.adhigh.net", - "epnt.ebay.com", "pixel.moatads.com", "mb.moatads.com", "ad.adsrvr.org", "a.ad.gt", "pixels.ad.gt", "z.moatads.com", "px.moatads.com", "s.pubmine.com", "px.ads.linkedin.com", "p.adsymptotic.com", + "epnt.ebay.com", "yt.moatads.com", "pixel.moatads.com", "mb.moatads.com", "ad.adsrvr.org", "a.ad.gt", "pixels.ad.gt", "z.moatads.com", "px.moatads.com", "s.pubmine.com", "px.ads.linkedin.com", "p.adsymptotic.com", "btloader.com", "ad-delivery.net", - "services.vlitag.com", "tag.vlitag.com", "assets.vlitag.com" + "services.vlitag.com", "tag.vlitag.com", "assets.vlitag.com", + "adserver.snapads.com", "euw.adserver.snapads.com", "euc.adserver.snapads.com", "usc.adserver.snapads.com", "ase.adserver.snapads.com" }; - FastHashSet Analytics = new FastHashSet { "www-google-analytics.l.google.com", "www-googletagmanager.l.google.com", "analytic-google.com", "google-analytics.com", "ssl.google-analytics.com", + FastHashSet Analytics = new FastHashSet { "ssl-google-analytics.l.google.com", "www-google-analytics.l.google.com", "www-googletagmanager.l.google.com", "analytic-google.com", "google-analytics.com", "ssl.google-analytics.com", "stats.wp.com", "analytics.facebook.com", "pixel.facebook.com", "analytics.tiktok.com", "analytics-sg.tiktok.com", @@ -111,6 +115,8 @@ public IResponseFilter GetResourceResponseFilter(IWebBrowser chromiumWebBrowser, "freshmarketer.com", "notify.bugsnag.com", "sessions.bugsnag.com", "api.bugsnag.com", "app.bugsnag.com", "browser.sentry-cdn.com", "app.getsentry.com", + "stats.gc.apple.com", "iadsdk.apple.com", "crashlogs.whatsapp.net", + "tr.snapchat.com", "sc-analytics.appspot.com", "app-analytics.snapchat.com", "luckyorange.com", "cdn.luckyorange.com", "w1.luckyorange.com", "upload.luckyorange.net", "cs.luckyorange.net", "settings.luckyorange.net", @@ -124,6 +130,7 @@ public IResponseFilter GetResourceResponseFilter(IWebBrowser chromiumWebBrowser, "tracking.india.miui.com", "tracking.rus.miui.com", + "metrics.data.hicloud.com", "metrics1.data.hicloud.com", "metrics5.data.hicloud.com", "logservice.hicloud.com", @@ -144,17 +151,10 @@ public IResponseFilter GetResourceResponseFilter(IWebBrowser chromiumWebBrowser, }; public CefReturnValue OnBeforeResourceLoad(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, IRequest request, IRequestCallback callback) { - var headers = request.Headers; - //Filter Lists + //request.SetHeaderByName("DNT", "1", true); + request.SetHeaderByName("Save-Data", "on", true); + //request.SetHeaderByName("Device-Memory", "0.25", true); bool Continue = true; - //if (bool.Parse(MainWindow.Instance.MainSave.Get("LiteMode"))) - //{ - //headers["Save-Data"] = "on"; - headers.Add("Save-Data", "on"); - headers.Add("Device-Memory", "0.25"); - //headers["Device-Memory"] = "0.25"; - //} - if (Utils.IsPossiblyAd(request.ResourceType)) { if (AdBlock || TrackerBlock) @@ -189,7 +189,6 @@ public CefReturnValue OnBeforeResourceLoad(IWebBrowser chromiumWebBrowser, IBrow } } } - request.Headers = headers; return Continue ? CefReturnValue.Continue : CefReturnValue.Cancel; } diff --git a/SLBr/MainWindow.xaml b/SLBr/MainWindow.xaml index 67da476..44856aa 100644 --- a/SLBr/MainWindow.xaml +++ b/SLBr/MainWindow.xaml @@ -5,12 +5,16 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:SLBr" xmlns:controls="clr-namespace:SLBr.Controls" mc:Ignorable="d" - Title="SLBr" Loaded="Window_Loaded" WindowStartupLocation="CenterScreen" WindowState="Maximized" Height="450" Width="800" Closing="Window_Closing"> + Title="SLBr" Loaded="Window_Loaded" StateChanged="Window_StateChanged" WindowStartupLocation="CenterScreen" WindowState="Maximized" Height="450" Width="800" Closing="Window_Closing"> + + + + - + diff --git a/SLBr/MainWindow.xaml.cs b/SLBr/MainWindow.xaml.cs index e97e871..6c02be3 100644 --- a/SLBr/MainWindow.xaml.cs +++ b/SLBr/MainWindow.xaml.cs @@ -24,6 +24,9 @@ using CefSharp.SchemeHandler; using Microsoft.Win32; using System.Collections.Specialized; +using System.Windows.Media.Animation; +using System.Threading; +using System.Threading.Tasks; namespace SLBr { @@ -50,7 +53,7 @@ public string Header RaisePropertyChanged("Header"); } } - public string _Header; + private string _Header; public BitmapImage Icon { get { return _Icon; } @@ -60,14 +63,34 @@ public BitmapImage Icon RaisePropertyChanged("Icon"); } } - public BitmapImage _Icon; + private BitmapImage _Icon; + public string Action + { + get { return _Action; } + set + { + _Action = value; + RaisePropertyChanged("Action"); + } + } + private string _Action; public UserControl Content { get; set; } + public int Id + { + get { return _Id; } + set + { + _Id = value; + RaisePropertyChanged("Id"); + } + } + private int _Id; } public partial class MainWindow : Window, INotifyPropertyChanged { [DllImport("dwmapi.dll", PreserveSig = true)] - public static extern int DwmSetWindowAttribute(IntPtr hwnd, int attr, ref bool attrValue, int attrSize); + public static extern int DwmSetWindowAttribute(IntPtr hwnd, int attr, ref int attrValue, int attrSize); [DllImport("shell32.dll", SetLastError = true)] static extern void SetCurrentProcessExplicitAppUserModelID([MarshalAs(UnmanagedType.LPWStr)] string AppID); @@ -86,7 +109,7 @@ public partial class MainWindow : Window, INotifyPropertyChanged "https://search.yahoo.com/search?p={0}", "https://yandex.com/search/?text={0}",*/ }; - public List SearchEngines; + public List SearchEngines = new List(); List Themes = new List(); public Saving GlobalSave; @@ -123,7 +146,7 @@ public partial class MainWindow : Window, INotifyPropertyChanged public int AdsBlocked; bool IsFullscreen; string[] Args; - public string ReleaseVersion = "2022.9.5.0"; + public string ReleaseVersion; public event PropertyChangedEventHandler PropertyChanged = delegate { }; private void RaisePropertyChanged(string Name) @@ -171,6 +194,13 @@ public Dictionary Downloads public void UpdateDownloadItem(DownloadItem item) { Downloads[item.Id] = item; + Application.Current.Dispatcher.BeginInvoke(new Action(delegate + { + if (item.IsComplete) + TaskbarProgress.ProgressValue = 0; + else + TaskbarProgress.ProgressValue = (double)item.PercentComplete / 100.0; + })); } HashSet HardwareUnavailableProcessors = new HashSet { @@ -185,17 +215,17 @@ public void SetRenderMode(string Mode, bool Notify) if (Mode == "Hardware") { RenderOptions.ProcessRenderMode = RenderMode.Default; - /*if (Notify) - { - var ProcessorID = Utils.GetProcessorID(); - foreach (string Processor in HardwareUnavailableProcessors) - { - if (ProcessorID.Contains(Processor)) - { - Prompt(false, NoHardwareAvailableMessage.Replace("{0}", Processor), false, "", "", "", true, "\xE7BA"); - } - } - }*/ + //if (Notify) + //{ + // var ProcessorID = Utils.GetProcessorID(); + // foreach (string Processor in HardwareUnavailableProcessors) + // { + // if (ProcessorID.Contains(Processor)) + // { + // Prompt(false, NoHardwareAvailableMessage.Replace("{0}", Processor), false, "", "", "", true, "\xE7BA"); + // } + // } + //} } else if (Mode == "Software") RenderOptions.ProcessRenderMode = RenderMode.SoftwareOnly; @@ -205,10 +235,18 @@ public void SetRenderMode(string Mode, bool Notify) #region Initialize private void SetIEEmulation(uint Value = 11001) { - using (var key = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION", true)) + SplashScreen.Instance.ReportProgress(16, "Modifying IE Emulation..."); + try { - if (key.GetValue("SLBr.exe") == null) - key.SetValue("SLBr.exe", Value, RegistryValueKind.DWord); + using (var key = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION", true)) + { + if (key.GetValue("SLBr.exe") == null) + key.SetValue("SLBr.exe", Value, RegistryValueKind.DWord); + } + } + catch + { + SplashScreen.Instance.ReportProgress(17, "Failed."); } } private void SetFeatureControlKey(string Feature, uint Value) @@ -220,6 +258,7 @@ private void SetFeatureControlKey(string Feature, uint Value) } private void InitializeIE() { + SplashScreen.Instance.ReportProgress(15, "Initializing Internet Explorer features..."); SetIEEmulation(); /*SetFeatureControlKey("FEATURE_BROWSER_EMULATION", 11001); // Webpages containing standards-based !DOCTYPE directives are displayed in IE10 Standards mode. SetFeatureControlKey("FEATURE_GPU_RENDERING", 1); @@ -252,6 +291,7 @@ private void InitializeIE() } private void InitializeSaves() { + SplashScreen.Instance.ReportProgress(29, "Fetching data..."); GlobalSave = new Saving("GlobalSave.bin", GlobalApplicationDataPath); MainSave = new Saving("Save.bin", UserApplicationDataPath); FavouritesSave = new Saving("Favourites.bin", UserApplicationDataPath); @@ -262,10 +302,12 @@ private void InitializeSaves() ExperimentsSave = new Saving("Experiments.bin", UserApplicationDataPath); IESave = new Saving("InternetExplorer.bin", UserApplicationDataPath); + SplashScreen.Instance.ReportProgress(30, "Processing data..."); if (SearchSave.Has("Search_Engine_Count")) { - SearchEngines = new List(); - Application.Current.Dispatcher.BeginInvoke(new Action(delegate + if (int.Parse(SearchSave.Get("Search_Engine_Count")) == 0) + SearchEngines = new List(DefaultSearchEngines); + else { for (int i = 0; i < int.Parse(SearchSave.Get("Search_Engine_Count")); i++) { @@ -273,7 +315,7 @@ private void InitializeSaves() if (!SearchEngines.Contains(Url)) SearchEngines.Add(Url); } - })); + } } else SearchEngines = new List(DefaultSearchEngines); @@ -317,6 +359,9 @@ private void InitializeSaves() if (!MainSave.Has("WebNotifications")) MainSave.Set("WebNotifications", true); + if (!MainSave.Has("ScreenshotFormat")) + MainSave.Set("ScreenshotFormat", "Jpeg"); + if (!IESave.Has("IESuppressErrors")) IESave.Set("IESuppressErrors", true); @@ -344,10 +389,15 @@ private void InitializeSaves() SandboxSave.Set("WebGL", true.ToString()); WebGL = bool.Parse(SandboxSave.Get("WebGL")).ToCefState(); + if (!ExperimentsSave.Has("DeveloperMode")) + ExperimentsSave.Set("DeveloperMode", false); + //int renderingTier = RenderCapability.Tier >> 16; if (!ExperimentsSave.Has("HardwareAcceleration")) - ExperimentsSave.Set("HardwareAcceleration", true); + ExperimentsSave.Set("HardwareAcceleration", true);//renderingTier == 0 + if (!ExperimentsSave.Has("ChromeRuntime")) + ExperimentsSave.Set("ChromeRuntime", false); if (!ExperimentsSave.Has("LowEndDeviceMode")) - ExperimentsSave.Set("LowEndDeviceMode", false); + ExperimentsSave.Set("LowEndDeviceMode", true); if (!ExperimentsSave.Has("PDFViewerExtension")) ExperimentsSave.Set("PDFViewerExtension", true); if (!ExperimentsSave.Has("AutoplayUserGestureRequired")) @@ -366,16 +416,21 @@ private void InitializeSaves() if (!MainSave.Has("DarkWebPage")) MainSave.Set("DarkWebPage", true); - if (!MainSave.Has("BackgroundImage")) - MainSave.Set("BackgroundImage", "Unsplash"); + MainSave.Set("BackgroundImage", "Lorem Picsum"); if (!MainSave.Has("CustomBackgroundImage")) MainSave.Set("CustomBackgroundImage", ""); + + if (bool.Parse(ExperimentsSave.Get("DeveloperMode"))) + DeveloperMode = true; + Themes.Add(new Theme("Light", Colors.White, Colors.Black, Colors.Gainsboro, Colors.WhiteSmoke, Colors.Gray)); Themes.Add(new Theme("Dark", (Color)ColorConverter.ConvertFromString("#202225"), Colors.White, (Color)ColorConverter.ConvertFromString("#36393F"), (Color)ColorConverter.ConvertFromString("#2F3136"), Colors.Gainsboro, true, true)); + SplashScreen.Instance.ReportProgress(31, "Done."); } private void InitializeUISaves() { + SplashScreen.Instance.ReportProgress(85, "Processing data..."); if (!MainSave.Has("AdBlock")) AdBlock(true); else @@ -394,11 +449,17 @@ private void InitializeUISaves() if (ProcessorID.Contains(Processor)) _RenderMode = "Software"; } + if (_RenderMode != "Software") + { + int renderingTier = RenderCapability.Tier >> 16; + _RenderMode = renderingTier == 0 ? "Software" : _RenderMode; + } SetRenderMode(_RenderMode, false); } else SetRenderMode(MainSave.Get("RenderMode"), true); + SplashScreen.Instance.ReportProgress(81, "Initializing UI..."); if (FavouritesSave.Has("Favourite_Count")) { Application.Current.Dispatcher.BeginInvoke(new Action(delegate @@ -410,68 +471,97 @@ private void InitializeUISaves() } })); } - if (bool.Parse(MainSave.Get("RestoreTabs")) && TabsSave.Has("Tab_Count") && int.Parse(TabsSave.Get("Tab_Count")) > 0) + Application.Current.Dispatcher.BeginInvoke(new Action(delegate { - Application.Current.Dispatcher.BeginInvoke(new Action(delegate + if (bool.Parse(MainSave.Get("RestoreTabs")) && TabsSave.Has("Tab_Count") && int.Parse(TabsSave.Get("Tab_Count")) > 0) { int SelectedIndex = int.Parse(MainSave.Get("SelectedTabIndex")); for (int i = 0; i < int.Parse(TabsSave.Get("Tab_Count")); i++) { string Url = TabsSave.Get($"Tab_{i}").Replace("slbr://processcrashed/?s=", ""); if (Url != "NOTFOUND") - NewBrowserTab(Url, 0); + { + if (Url == "slbr://settings") + OpenSettings(false); + else + NewBrowserTab(Url, 0); + } } BrowserTabs.SelectedIndex = SelectedIndex; - })); - } - else - { - NewTabUrl = MainSave.Get("Homepage"); - CreateTabForCommandLineUrl = true; - } - if (!MainSave.Has("UsedBefore")) - { - if (string.IsNullOrEmpty(NewTabUrl) || NewTabUrl == MainSave.Get("Homepage")) + } + else { - NewTabUrl = "https://github.com/SLT-World/SLBr"; + if (string.IsNullOrEmpty(NewTabUrl)) + NewTabUrl = MainSave.Get("Homepage"); CreateTabForCommandLineUrl = true; } - MainSave.Set("UsedBefore", true.ToString()); - } - if (CreateTabForCommandLineUrl) - NewBrowserTab(NewTabUrl, 0); + if (!MainSave.Has("UsedBefore")) + { + if (string.IsNullOrEmpty(NewTabUrl) || NewTabUrl == MainSave.Get("Homepage")) + { + NewTabUrl = "https://github.com/SLT-World/SLBr"; + CreateTabForCommandLineUrl = true; + } + MainSave.Set("UsedBefore", true.ToString()); + } + if (CreateTabForCommandLineUrl) + NewBrowserTab(NewTabUrl, 0, true); + })); + SplashScreen.Instance.ReportProgress(86, "Done."); } private void InitializeCEF() { + SplashScreen.Instance.ReportProgress(43, "Initializing LifeSpan Handler..."); _LifeSpanHandler = new LifeSpanHandler(); + SplashScreen.Instance.ReportProgress(44, "Initializing Download Handler..."); _DownloadHandler = new DownloadHandler(); + SplashScreen.Instance.ReportProgress(45, "Initializing Request Handler..."); _RequestHandler = new RequestHandler(); + SplashScreen.Instance.ReportProgress(46, "Initializing Menu Handler..."); _ContextMenuHandler = new ContextMenuHandler(); + SplashScreen.Instance.ReportProgress(47, "Initializing Keyboard Handler..."); _KeyboardHandler = new KeyboardHandler(); + SplashScreen.Instance.ReportProgress(48, "Initializing Javascript Dialog Handler..."); _JsDialogHandler = new JsDialogHandler(); + SplashScreen.Instance.ReportProgress(49, "Initializing private Javascript Handler..."); _PrivateJsObjectHandler = new PrivateJsObjectHandler(); + SplashScreen.Instance.ReportProgress(50, "Initializing public Javascript Handler..."); _PublicJsObjectHandler = new PublicJsObjectHandler(); + SplashScreen.Instance.ReportProgress(51, "Initializing QR Code Handler."); _QRCodeHandler = new QRCodeHandler(); + SplashScreen.Instance.ReportProgress(52, "Done."); + SplashScreen.Instance.ReportProgress(54, "Applying keyboard shortcuts..."); _KeyboardHandler.AddKey(Screenshot, (int)Key.S, true); _KeyboardHandler.AddKey(Refresh, (int)Key.F5); _KeyboardHandler.AddKey(delegate () { Fullscreen(!IsFullscreen); }, (int)Key.F11); _KeyboardHandler.AddKey(Inspect, (int)Key.F12); _KeyboardHandler.AddKey(FindUI, (int)Key.F, true); + SplashScreen.Instance.ReportProgress(55, "Done."); + SplashScreen.Instance.ReportProgress(66, "Initializing SafeBrowsing API..."); _SafeBrowsing = new SafeBrowsing(Environment.GetEnvironmentVariable("GOOGLE_API_KEY"), Environment.GetEnvironmentVariable("GOOGLE_DEFAULT_CLIENT_ID")); + SplashScreen.Instance.ReportProgress(67, "Done."); + SplashScreen.Instance.ReportProgress(68, "Processing..."); CefSharpSettings.SubprocessExitIfParentProcessClosed = true; CefSharpSettings.ShutdownOnExit = true; CefSettings settings = new CefSettings(); + //settings.EnablePrintPreview(); SetCEFFlags(settings); - using (var currentProcess = Process.GetCurrentProcess()) - settings.BrowserSubprocessPath = currentProcess.MainModule.FileName; + if (File.Exists(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Utility Service.exe"))) + settings.BrowserSubprocessPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Utility Service.exe"); + //settings.BrowserSubprocessPath = "E:\\Visual Studio\\SLBr\\Utility Service\\bin\\Debug\\net6.0-windows\\Utility Service.exe"; + else + settings.BrowserSubprocessPath = Process.GetCurrentProcess().MainModule.FileName; + //using (var currentProcess = Process.GetCurrentProcess()) + //settings.BrowserSubprocessPath = currentProcess.MainModule.FileName; //settings.BrowserSubprocessPath = Args[0]; - //settings.ChromeRuntime = true; + if (bool.Parse(ExperimentsSave.Get("ChromeRuntime"))) + settings.ChromeRuntime = true; - Cef.EnableHighDPISupport(); + Cef.EnableHighDPISupport(); settings.Locale = "en-US"; settings.MultiThreadedMessageLoop = true; @@ -483,6 +573,7 @@ private void InitializeCEF() settings.RemoteDebuggingPort = 8089; settings.UserDataPath = UserDataPath; + SplashScreen.Instance.ReportProgress(81, "Registering network protocols..."); settings.RegisterScheme(new CefCustomScheme { SchemeName = "gemini", @@ -525,6 +616,7 @@ private void InitializeCEF() new UrlScheme.Scheme { PageName = "Malware", FileName = "Malware.html" }, new UrlScheme.Scheme { PageName = "Deception", FileName = "Deception.html" }, new UrlScheme.Scheme { PageName = "ProcessCrashed", FileName = "ProcessCrashed.html" }, + new UrlScheme.Scheme { PageName = "Tetris", FileName = "Tetris.html" }, } }; string SLBrSchemeRootFolder = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), SLBrScheme.RootFolder); @@ -545,11 +637,15 @@ private void InitializeCEF() IsCorsEnabled = SLBrScheme.IsCorsEnabled }); } + SplashScreen.Instance.ReportProgress(82, "Done."); + SplashScreen.Instance.ReportProgress(83, "Initializing Chromium..."); Cef.Initialize(settings); + SplashScreen.Instance.ReportProgress(84, "Chromium initialized."); } private void SetCEFFlags(CefSettings settings) { + SplashScreen.Instance.ReportProgress(69, "Applying Chromium optimization features..."); SetDefaultFlags(settings); SetBackgroundFlags(settings); SetUIFlags(settings); @@ -559,14 +655,13 @@ private void SetCEFFlags(CefSettings settings) SetMediaFlags(settings); SetFrameworkFlags(settings); if (DeveloperMode) - { SetDeveloperFlags(settings); - } SetStreamingFlags(settings); SetExtensionFlags(settings); SetListedFlags(settings); SetChromiumFlags(settings); + SplashScreen.Instance.ReportProgress(80, "Done."); } private void SetChromiumFlags(CefSettings settings) { @@ -600,7 +695,7 @@ private void SetDefaultFlags(CefSettings settings) settings.CefCommandLineArgs.Add("enable-low-end-device-mode"); settings.CefCommandLineArgs.Add("media-cache-size", "262144000"); - settings.CefCommandLineArgs.Add("disk-cache-size", "104857600"); + settings.CefCommandLineArgs.Add("disk-cache-size", "104857600");//104857600 if (bool.Parse(ExperimentsSave.Get("AutoplayUserGestureRequired"))) settings.CefCommandLineArgs.Add("autoplay-policy", "user-gesture-required"); @@ -609,6 +704,11 @@ private void SetDefaultFlags(CefSettings settings) } private void SetBackgroundFlags(CefSettings settings) { + settings.CefCommandLineArgs.Add("enable-finch-seed-delta-compression"); + + settings.CefCommandLineArgs.Add("battery-saver-mode-available"); + settings.CefCommandLineArgs.Add("high-efficiency-mode-available"); + settings.CefCommandLineArgs.Add("enable-ipc-flooding-protection"); settings.CefCommandLineArgs.Add("disable-background-mode"); @@ -618,6 +718,7 @@ private void SetBackgroundFlags(CefSettings settings) //https://bugs.chromium.org/p/chromium/issues/detail?id=153139 settings.CefCommandLineArgs.Add("disable-best-effort-tasks"); + settings.CefCommandLineArgs.Add("aggressive-cache-discard"); settings.CefCommandLineArgs.Add("enable-simple-cache-backend"); settings.CefCommandLineArgs.Add("v8-cache-options"); settings.CefCommandLineArgs.Add("enable-font-cache-scaling"); @@ -632,9 +733,11 @@ private void SetBackgroundFlags(CefSettings settings) settings.CefCommandLineArgs.Add("multi-threaded-message-loop"); settings.CefCommandLineArgs.Add("renderer-process-limit", "2"); + //Failed to identify BrowserWrapper in OnContextCreated BrowserId:1 settings.CefCommandLineArgs.Remove("process-per-tab"); settings.CefCommandLineArgs.Add("process-per-site"); + settings.CefCommandLineArgs.Add("enable-process-per-site"); settings.CefCommandLineArgs.Add("enable-tile-compression"); @@ -645,6 +748,7 @@ private void SetBackgroundFlags(CefSettings settings) settings.CefCommandLineArgs.Add("quick-intensive-throttling-after-loading"); settings.CefCommandLineArgs.Add("expensive-background-timer-throttling"); settings.CefCommandLineArgs.Add("intensive-wake-up-throttling"); + settings.CefCommandLineArgs.Add("align-wakeups"); settings.CefCommandLineArgs.Add("max-tiles-for-interest-area", "64"); settings.CefCommandLineArgs.Add("default-tile-width", "64"); @@ -655,10 +759,18 @@ private void SetBackgroundFlags(CefSettings settings) settings.CefCommandLineArgs.Add("calculate-native-win-occlusion"); settings.CefCommandLineArgs.Add("enable-winrt-geolocation-implementation"); + + settings.CefCommandLineArgs.Add("disable-v8-idle-tasks"); + settings.CefCommandLineArgs.Add("disable-mipmap-generation"); + } private void SetUIFlags(CefSettings settings) { - //settings.CefCommandLineArgs.Add("enable-print-preview"); + settings.CefCommandLineArgs.Add("disable-pinch"); + + settings.CefCommandLineArgs.Add("deferred-font-shaping"); + settings.CefCommandLineArgs.Add("enable-auto-disable-accessibility"); + settings.CefCommandLineArgs.Add("enable-print-preview"); //settings.CefCommandLineArgs.Add("enable-pixel-canvas-recording"); settings.CefCommandLineArgs.Add("enable-draw-occlusion"); @@ -696,6 +808,7 @@ private void SetGPUFlags(CefSettings settings) settings.CefCommandLineArgs.Add("ignore-gpu-blocklist"); settings.CefCommandLineArgs.Add("enable-gpu"); settings.CefCommandLineArgs.Add("enable-zero-copy"); + //settings.CefCommandLineArgs.Add("disable-software-rasterizer"); settings.CefCommandLineArgs.Add("enable-gpu-rasterization"); //settings.CefCommandLineArgs.Add("gpu-rasterization-msaa-sample-count", "0"); settings.CefCommandLineArgs.Add("enable-native-gpu-memory-buffers"); @@ -708,6 +821,7 @@ private void SetGPUFlags(CefSettings settings) settings.CefCommandLineArgs.Add("disable-direct-composition"); settings.CefCommandLineArgs.Add("disable-gpu-vsync"); settings.CefCommandLineArgs.Add("disable-gpu-shader-disk-cache"); + settings.CefCommandLineArgs.Add("reduce-gpu-priority-on-background"); } settings.CefCommandLineArgs.Add("enable-begin-frame-scheduling"); @@ -722,6 +836,8 @@ private void SetNetworkFlags(CefSettings settings) settings.CefCommandLineArgs.Add("enable-brotli"); settings.CefCommandLineArgs.Add("no-proxy-server"); + settings.CefCommandLineArgs.Add("no-proxy"); + //settings.CefCommandLineArgs.Add("winhttp-proxy-resolver"); settings.CefCommandLineArgs.Add("no-pings"); settings.CefCommandLineArgs.Add("dns-over-https"); @@ -741,7 +857,7 @@ private void SetSecurityFlags(CefSettings settings) settings.CefCommandLineArgs.Add("ignore-certificate-errors"); - settings.CefCommandLineArgs.Add("allow-universal-access-from-files"); + //settings.CefCommandLineArgs.Add("allow-universal-access-from-files"); //settings.CefCommandLineArgs.Add("allow-file-access-from-files"); settings.CefCommandLineArgs.Add("enable-heavy-ad-intervention"); @@ -753,6 +869,8 @@ private void SetSecurityFlags(CefSettings settings) } private void SetMediaFlags(CefSettings settings) { + settings.CefCommandLineArgs.Add("allow-file-access-from-files"); + settings.CefCommandLineArgs.Add("allow-universal-access-from-files"); settings.CefCommandLineArgs.Add("enable-parallel-downloading"); settings.CefCommandLineArgs.Add("enable-jxl"); @@ -761,7 +879,6 @@ private void SetMediaFlags(CefSettings settings) settings.CefCommandLineArgs.Add("disable-low-res-tiling"); settings.CefCommandLineArgs.Add("disable-background-video-track"); - settings.CefCommandLineArgs.Add("zero-copy-video-capture"); settings.CefCommandLineArgs.Add("enable-lite-video"); settings.CefCommandLineArgs.Add("lite-video-force-override-decision"); settings.CefCommandLineArgs.Add("enable-av1-decoder"); @@ -772,6 +889,13 @@ private void SetMediaFlags(CefSettings settings) settings.CefCommandLineArgs.Add("d3d11-video-decoder"); settings.CefCommandLineArgs.Add("enable-accelerated-video-decode"); settings.CefCommandLineArgs.Add("enable-accelerated-mjpeg-decode"); + settings.CefCommandLineArgs.Add("enable-vp9-kSVC-decode-acceleration"); + settings.CefCommandLineArgs.Add("enable-vaapi-av1-decode-acceleration"); + settings.CefCommandLineArgs.Add("enable-vaapi-jpeg-image-decode-acceleration"); + settings.CefCommandLineArgs.Add("enable-vaapi-webp-image-decode-accelerationn"); + settings.CefCommandLineArgs.Add("enable-vbr-encode-acceleration"); + settings.CefCommandLineArgs.Add("zero-copy-tab-capture"); + settings.CefCommandLineArgs.Add("zero-copy-video-capture"); } else { @@ -784,9 +908,15 @@ private void SetMediaFlags(CefSettings settings) settings.CefCommandLineArgs.Add("enable-lazy-frame-loading"); settings.CefCommandLineArgs.Add("subframe-shutdown-delay"); + + //settings.CefCommandLineArgs.Add("optimization-target-prediction"); + //settings.CefCommandLineArgs.Add("optimization-guide-model-downloading"); + + settings.CefCommandLineArgs.Add("turn-off-streaming-media-caching-on-battery"); } private void SetFrameworkFlags(CefSettings settings) { + settings.CefCommandLineArgs.Add("use-angle", "opengl"); //settings.CefCommandLineArgs.Add("use-angle", "gl"); //settings.CefCommandLineArgs.Add("use-gl", "desktop"); @@ -812,15 +942,16 @@ private void SetFrameworkFlags(CefSettings settings) } private void SetDeveloperFlags(CefSettings settings) { + settings.CefCommandLineArgs.Add("enable-experimental-extension-apis"); settings.CefCommandLineArgs.Add("enable-experimental-webassembly-features"); settings.CefCommandLineArgs.Add("enable-experimental-webassembly-stack-switching"); settings.CefCommandLineArgs.Add("enable-experimental-web-platform-features"); settings.CefCommandLineArgs.Add("enable-experimental-canvas-features"); settings.CefCommandLineArgs.Add("enable-javascript-harmony"); + settings.CefCommandLineArgs.Add("enable-javascript-experimental-shared-memory"); settings.CefCommandLineArgs.Add("enable-future-v8-vm-features"); settings.CefCommandLineArgs.Add("enable-devtools-experiments"); //settings.CefCommandLineArgs.Add("web-share"); - settings.CefCommandLineArgs.Add("webui-branding-update"); //settings.CefCommandLineArgs.Add("enable-portals"); settings.CefCommandLineArgs.Add("enable-webgl-developer-extensions"); settings.CefCommandLineArgs.Add("webxr-incubations"); @@ -834,8 +965,8 @@ private void SetStreamingFlags(CefSettings settings) settings.CefCommandLineArgs.Add("enable-media-stream"); settings.CefCommandLineArgs.Add("enable-media-session-service"); - settings.CefCommandLineArgs.Add("use-fake-device-for-media-stream"); - settings.CefCommandLineArgs.Add("use-fake-ui-for-media-stream"); + //settings.CefCommandLineArgs.Add("use-fake-device-for-media-stream"); + //settings.CefCommandLineArgs.Add("use-fake-ui-for-media-stream"); settings.CefCommandLineArgs.Add("enable-usermedia-screen-capturing"); settings.CefCommandLineArgs.Add("disable-rtc-smoothness-algorithm"); settings.CefCommandLineArgs.Add("enable-speech-input"); @@ -898,28 +1029,81 @@ private void SetListedFlags(CefSettings settings) } #endregion + bool Initialized; + int WPFFrameRate = 30; string NewTabUrl = ""; bool CreateTabForCommandLineUrl; - bool DeveloperMode; - public MainWindow() + public bool DeveloperMode; + public string AppUserModelID = "{ab11da56-fbdf-4678-916e-67e165b21f30}"; + + private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled) { - Instance = this; - if (Username != "Default-User") - SetCurrentProcessExplicitAppUserModelID("{ab11da56-fbdf-4678-916e-67e165b21f30_" + Username + "}"); + if (msg == MessageHelper.WM_COPYDATA) + { + COPYDATASTRUCT _dataStruct = Marshal.PtrToStructure(lParam); + string _strMsg = Marshal.PtrToStringUni(_dataStruct.lpData, _dataStruct.cbData / 2); + NewBrowserTab(_strMsg, 0, true); + } + return IntPtr.Zero; + } - string RegPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Resources", "SLBr.reg"); - /*if (Utils.IsAdministrator()) + public BitmapImage GetIcon(string Url) + { + if (Utils.IsHttpScheme(Url)) + { + string Host = Utils.CleanUrl(Url, true, true, true, false); + return new BitmapImage(new Uri("https://www.google.com/s2/favicons?sz=24&domain=" + Host)); + } + /*else if (Url.StartsWith("slbr:")) { - string SLBrExecutablePath = Assembly.GetEntryAssembly().Location.Replace(".dll", ".exe"); - File.WriteAllText(RegPath, SLBrRegTemplate.Replace("{SLBr}", SLBrExecutablePath)); + if (Url.Contains("tetris")) + { + return Utils.Utf32ToDrawingImage(0xE705).ToBitmapSource().ToBitmapImage(); + } }*/ + return new BitmapImage(new Uri(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Resources", (CurrentTheme.DarkTitleBar ? "White Tab Icon.png" : "Black Tab Icon.png")))); + } + + public MainWindow() + { + InitializeWindow(); + } + private async void InitializeWindow() + { + Instance = this; + //ReleaseVersion = FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location).ToString(); + ReleaseVersion = Assembly.GetExecutingAssembly().GetName().Version.ToString(); + SplashScreen.Instance.ReportProgress(0, "Processing..."); + HwndSource source = HwndSource.FromHwnd(new WindowInteropHelper(this).EnsureHandle()); + source.AddHook(new HwndSourceHook(WndProc)); Args = Environment.GetCommandLineArgs(); + Timeline.DesiredFrameRateProperty.OverrideMetadata(typeof(Timeline), new FrameworkPropertyMetadata { DefaultValue = WPFFrameRate }); + + if (Username != "Default-User") + { + AppUserModelID = "{ab11da56-fbdf-4678-916e-67e165b21f30_" + Username + "}"; + SetCurrentProcessExplicitAppUserModelID(AppUserModelID); + } + if (Args.Length > 1) + { + Process _otherInstance = Utils.GetAlreadyRunningInstance(); + if (_otherInstance != null) + { + MessageHelper.SendDataMessage(_otherInstance, Args[1]); + Application.Current.Shutdown(); + return; + } + } + + //string RegPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Resources", "SLBr.reg"); + if (Args.Length > 1) { foreach (string Flag in Args) { + SplashScreen.Instance.ReportProgress(1, "Processing command line arguments..."); if (Args.ToList().IndexOf(Flag) == 0) continue; if (Flag == "--dev") @@ -932,18 +1116,18 @@ public MainWindow() { if (Flag.StartsWith("--")) continue; - if (Directory.Exists(Flag) || File.Exists(Flag)) - NewTabUrl = "file:\\\\\\" + Args[1]; - else - NewTabUrl = Flag; + //if (Directory.Exists(Flag) || File.Exists(Flag)) + // NewTabUrl = "file:\\\\\\" + Args[1]; + //else + NewTabUrl = Flag; CreateTabForCommandLineUrl = true; } } } if (!DeveloperMode) DeveloperMode = Debugger.IsAttached; - if (!DeveloperMode) - Application.Current.DispatcherUnhandledException += Window_DispatcherUnhandledException; + //if (!DeveloperMode) + Application.Current.DispatcherUnhandledException += Window_DispatcherUnhandledException; GlobalApplicationDataPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "SLBr"); UserApplicationDataPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "SLBr", Username); CachePath = Path.Combine(UserApplicationDataPath, "Cache"); @@ -951,7 +1135,8 @@ public MainWindow() LogPath = Path.Combine(UserApplicationDataPath, "Errors.log"); ExecutablePath = Assembly.GetExecutingAssembly().Location.Replace(".dll", ".exe"); - // Set Google API keys, used for Geolocation requests sans GPS. See http://www.chromium.org/developers/how-tos/api-keys + SplashScreen.Instance.ReportProgress(2, "Registering client API keys..."); + // Set Google API keys, used for Geolocation requests sans GPS. See http://www.chromium.org/developers/how-tos/api-keys Environment.SetEnvironmentVariable("GOOGLE_API_KEY", SECRETS.GOOGLE_API_KEY); //create cs file named SECRETS, add string variable GOOGLE_API_KEY with value of google api key Environment.SetEnvironmentVariable("GOOGLE_DEFAULT_CLIENT_ID", SECRETS.GOOGLE_DEFAULT_CLIENT_ID); @@ -961,89 +1146,107 @@ public MainWindow() if (Utils.IsAdministrator()) { - using (var key = Registry.ClassesRoot.CreateSubKey("SLBr", true)) - { - key.SetValue(null, "SLBr"); - key.SetValue("AppUserModelId", "SLBr"); - - RegistryKey ApplicationRegistry = key.CreateSubKey("Application", true); - ApplicationRegistry.SetValue("AppUserModelId", "SLBr"); - ApplicationRegistry.SetValue("ApplicationIcon", $"{ExecutablePath},0"); - ApplicationRegistry.SetValue("ApplicationName", "SLBr"); - ApplicationRegistry.SetValue("ApplicationCompany", "SLT World"); - ApplicationRegistry.SetValue("ApplicationDescription", "Browse the web with a fast, lightweight web browser."); - ApplicationRegistry.Close(); - - RegistryKey IconRegistry = key.CreateSubKey("DefaultIcon", true); - IconRegistry.SetValue(null, $"{ExecutablePath},0"); - ApplicationRegistry.Close(); - - RegistryKey CommandRegistry = key.CreateSubKey("shell\\open\\command", true); - CommandRegistry.SetValue(null, $"\"{ExecutablePath}\" \"%1\""); - CommandRegistry.Close(); - } - using (var key = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Clients\\StartMenuInternet", true).CreateSubKey("SLBr", true)) + SplashScreen.Instance.ReportProgress(3, "Registering application into registry..."); + try { - if (key.GetValue(null) as string != "SLBr") - key.SetValue(null, "SLBr"); - - RegistryKey CapabilitiesRegistry = key.CreateSubKey("Capabilities", true); - CapabilitiesRegistry.SetValue("ApplicationDescription", "SLBr is a open source browser that prioritizes a faster web"); - CapabilitiesRegistry.SetValue("ApplicationIcon", $"{ExecutablePath},0"); - CapabilitiesRegistry.SetValue("ApplicationName", $"SLBr"); - RegistryKey StartMenuRegistry = CapabilitiesRegistry.CreateSubKey("StartMenu", true); - StartMenuRegistry.SetValue("StartMenuInternet", "SLBr"); - StartMenuRegistry.Close(); - - RegistryKey FileAssociationsRegistry = CapabilitiesRegistry.CreateSubKey("FileAssociations", true); - FileAssociationsRegistry.SetValue(".xhtml", "SLBr"); - FileAssociationsRegistry.SetValue(".xht", "SLBr"); - FileAssociationsRegistry.SetValue(".shtml", "SLBr"); - FileAssociationsRegistry.SetValue(".html", "SLBr"); - FileAssociationsRegistry.SetValue(".htm", "SLBr"); - FileAssociationsRegistry.SetValue(".pdf", "SLBr"); - FileAssociationsRegistry.SetValue(".svg", "SLBr"); - FileAssociationsRegistry.SetValue(".webp", "SLBr"); - FileAssociationsRegistry.Close(); - - RegistryKey URLAssociationsRegistry = CapabilitiesRegistry.CreateSubKey("URLAssociations", true); - URLAssociationsRegistry.SetValue("http", "SLBr"); - URLAssociationsRegistry.SetValue("https", "SLBr"); - URLAssociationsRegistry.Close(); - - CapabilitiesRegistry.Close(); - - RegistryKey DefaultIconRegistry = key.CreateSubKey("DefaultIcon", true); - DefaultIconRegistry.SetValue(null, $"{ExecutablePath},0"); - DefaultIconRegistry.Close(); - - RegistryKey CommandRegistry = key.CreateSubKey("shell\\open\\command", true); - CommandRegistry.SetValue(null, $"\"{ExecutablePath}\" \"%1\""); - CommandRegistry.Close(); + using (var key = Registry.ClassesRoot.CreateSubKey("SLBr", true)) + { + key.SetValue(null, "SLBr Document"); + key.SetValue("AppUserModelId", "SLBr"); + + RegistryKey ApplicationRegistry = key.CreateSubKey("Application", true); + ApplicationRegistry.SetValue("AppUserModelId", "SLBr"); + ApplicationRegistry.SetValue("ApplicationIcon", $"{ExecutablePath},0"); + ApplicationRegistry.SetValue("ApplicationName", "SLBr"); + ApplicationRegistry.SetValue("ApplicationCompany", "SLT World"); + ApplicationRegistry.SetValue("ApplicationDescription", "Browse the web with a fast, lightweight web browser."); + ApplicationRegistry.Close(); + + RegistryKey IconRegistry = key.CreateSubKey("DefaultIcon", true); + IconRegistry.SetValue(null, $"{ExecutablePath},0"); + ApplicationRegistry.Close(); + + RegistryKey CommandRegistry = key.CreateSubKey("shell\\open\\command", true); + CommandRegistry.SetValue(null, $"\"{ExecutablePath}\" \"%1\""); + CommandRegistry.Close(); + } + using (var key = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Clients\\StartMenuInternet", true).CreateSubKey("SLBr", true)) + { + if (key.GetValue(null) as string != "SLBr") + key.SetValue(null, "SLBr"); + + RegistryKey CapabilitiesRegistry = key.CreateSubKey("Capabilities", true); + CapabilitiesRegistry.SetValue("ApplicationDescription", "SLBr is a open source browser that prioritizes a faster web"); + CapabilitiesRegistry.SetValue("ApplicationIcon", $"{ExecutablePath},0"); + CapabilitiesRegistry.SetValue("ApplicationName", $"SLBr"); + RegistryKey StartMenuRegistry = CapabilitiesRegistry.CreateSubKey("StartMenu", true); + StartMenuRegistry.SetValue("StartMenuInternet", "SLBr"); + StartMenuRegistry.Close(); + + RegistryKey FileAssociationsRegistry = CapabilitiesRegistry.CreateSubKey("FileAssociations", true); + FileAssociationsRegistry.SetValue(".xhtml", "SLBr"); + FileAssociationsRegistry.SetValue(".xht", "SLBr"); + FileAssociationsRegistry.SetValue(".shtml", "SLBr"); + FileAssociationsRegistry.SetValue(".html", "SLBr"); + FileAssociationsRegistry.SetValue(".htm", "SLBr"); + FileAssociationsRegistry.SetValue(".pdf", "SLBr"); + FileAssociationsRegistry.SetValue(".svg", "SLBr"); + FileAssociationsRegistry.SetValue(".webp", "SLBr"); + FileAssociationsRegistry.Close(); + + RegistryKey URLAssociationsRegistry = CapabilitiesRegistry.CreateSubKey("URLAssociations", true); + URLAssociationsRegistry.SetValue("http", "SLBr"); + URLAssociationsRegistry.SetValue("https", "SLBr"); + URLAssociationsRegistry.Close(); + + CapabilitiesRegistry.Close(); + + RegistryKey DefaultIconRegistry = key.CreateSubKey("DefaultIcon", true); + DefaultIconRegistry.SetValue(null, $"{ExecutablePath},0"); + DefaultIconRegistry.Close(); + + RegistryKey CommandRegistry = key.CreateSubKey("shell\\open\\command", true); + CommandRegistry.SetValue(null, $"\"{ExecutablePath}\" \"%1\""); + CommandRegistry.Close(); + } + using (var key = Registry.LocalMachine.OpenSubKey("SOFTWARE\\RegisteredApplications", true)) + { + key.SetValue("SLBr", "Software\\Clients\\StartMenuInternet\\SLBr\\Capabilities"); + } } - using (var key = Registry.LocalMachine.OpenSubKey("SOFTWARE\\RegisteredApplications", true)) + catch { - key.SetValue("SLBr", "Software\\Clients\\StartMenuInternet\\SLBr\\Capabilities"); + SplashScreen.Instance.ReportProgress(4, "Failed."); } //Process regeditProcess = Process.Start("regedit.exe", "/s \"" + RegPath + "\""); //regeditProcess.WaitForExit(); } + //await Task.Delay(500); InitializeIE(); + //await Task.Delay(500); TinyRandom = new Random(); TinyDownloader = new WebClient(); InitializeSaves(); + //await Task.Delay(500); InitializeCEF(); - InitializeUISaves(); - + //await Task.Delay(500); InitializeComponent(); + //await Task.Delay(500); + InitializeUISaves(); + //await Task.Delay(500); + SplashScreen.Instance.ReportProgress(87, "Initializing components..."); BrowserTabs.ItemsSource = Tabs; GCTimer.Tick += GCCollect_Tick; GCTimer.Start(); + //await Task.Delay(500); + SplashScreen.Instance.ReportProgress(99, "Complete."); + //await Task.Delay(1000); + SplashScreen.Instance.ReportProgress(100, "Showing window..."); } public void DiscordWebhookSendInfo(string Content) @@ -1081,14 +1284,14 @@ private void GCCollect_Tick(object sender, EventArgs e) if (bool.Parse(MainSave.Get("TabUnloading"))) { if (UnloadTabsTime >= 150) - UnloadTabs(); + UnloadTabs(true); else UnloadTabsTime += 30; } //GC.WaitForPendingFinalizers(); GC.Collect(); } - public void UnloadTabs() + public void UnloadTabs(bool ChangeIcon) { BrowserTabItem SelectedTab = Tabs[BrowserTabs.SelectedIndex]; foreach (BrowserTabItem Tab in Tabs) @@ -1097,29 +1300,19 @@ public void UnloadTabs() { Browser BrowserView = GetBrowserView(Tab); if (BrowserView != null) - UnloadTab(BrowserView, true); + UnloadTab(ChangeIcon, BrowserView); } } UnloadTabsTime = 0; } - private void UnloadTab(Browser BrowserView, bool IgnoreIfSound = true) + private void UnloadTab(bool ChangeIcon, Browser BrowserView) { - if (IgnoreIfSound)//PROBLEM: This checks if the address is a known music website. I need help on detecting sound. - { - string CleanedAddress = Utils.CleanUrl(BrowserView.Address, true, true, true, true); - if ((CleanedAddress.StartsWith("youtube.com/watch") - || CleanedAddress.StartsWith("meet.google.com/") - || CleanedAddress.StartsWith("spotify.com/track/") - || CleanedAddress.StartsWith("soundcloud.com") - || CleanedAddress.StartsWith("dailymotion.com/video/") - || CleanedAddress.StartsWith("vimeo.com") - || CleanedAddress.StartsWith("twitch.tv/") - || CleanedAddress.StartsWith("bitchute.com/video/") - || CleanedAddress.StartsWith("ted.com/talks/") - ) && !BrowserView.IsAudioMuted) - return; - } - BrowserView.Unload(Framerate, Javascript, LoadImages, LocalStorage, Databases, WebGL); + string CleanedAddress = BrowserView.Address; + bool IsBlacklistedSite = CleanedAddress.Contains("youtube.com/watch") || CleanedAddress.Contains("meet.google.com/") || CleanedAddress.Contains("spotify.com/track/") + || CleanedAddress.Contains("soundcloud.com") || CleanedAddress.Contains("dailymotion.com/video/") || CleanedAddress.Contains("vimeo.com") + || CleanedAddress.Contains("twitch.tv/") || CleanedAddress.Contains("bitchute.com/video/") || CleanedAddress.Contains("ted.com/talks/"); + if (BrowserView.IsAudioMuted || !Utils.IsAudioPlayingInDevice() || !IsBlacklistedSite) + BrowserView.Unload(ChangeIcon, Framerate, Javascript, LoadImages, LocalStorage, Databases, WebGL); } public void ButtonAction(object sender, RoutedEventArgs e) @@ -1166,17 +1359,11 @@ private void Action(Actions _Action, object sender = null, string V1 = "", strin NewBrowserTab(V1, 0, true); break; case Actions.CloseTab: - CloseCurrentBrowserTab(); + CloseBrowserTab(int.Parse(V1)); break; case Actions.Inspect: Inspect(); break; - /*case Actions.Create_Tab: - CreateBrowserTab("Empty00000"); - break; - case Actions.CloseTab: - CloseTab(); - break;*/ } } public void Undo() @@ -1257,38 +1444,117 @@ public void FindUI() if (_Browser == null) return; Keyboard.Focus(_Browser.FindTextBox); + _Browser.FindTextBox.SelectAll(); } - public void NewBrowserTab(string Url, int BrowserType = 0, bool IsSelected = false, int Index = -1) + /*public void NewTab(UserControl Content, string Header, bool IsSelected = false, int Index = -1) { - Url = Url.Replace("{Homepage}", MainSave.Get("Homepage")); - BrowserTabItem _Tab = new BrowserTabItem { Header = Utils.CleanUrl(Url, true, true, true, true) }; - _Tab.Content = new Browser(Url, BrowserType, _Tab); + BrowserTabItem _Tab = new BrowserTabItem { Header = Header }; + _Tab.Content = Content; + _Tab.Id = Utils.GenerateRandomId(); + _Tab.Action = $"5<,>{_Tab.Id}"; if (Index != -1) Tabs.Insert(Index, _Tab); else Tabs.Add(_Tab); if (IsSelected) BrowserTabs.SelectedIndex = Tabs.IndexOf(_Tab); - } - public void Settings(bool IsSelected = false, int Index = -1) + }*/ + public void NewBrowserTab(string Url, int BrowserType = 0, bool IsSelected = false, int Index = -1) { - BrowserTabItem _Tab = new BrowserTabItem { Header = "Settings" }; - _Tab.Content = new Settings(); + if (WindowState == WindowState.Minimized) + WindowState = WindowState.Normal; + Url = Url.Replace("{Homepage}", MainSave.Get("Homepage")); + BrowserTabItem _Tab = new BrowserTabItem { Header = Utils.CleanUrl(Url, true, true, true, true) }; + _Tab.Content = new Browser(Url, BrowserType, _Tab); + _Tab.Id = Utils.GenerateRandomId(); + _Tab.Action = $"5<,>{_Tab.Id}"; if (Index != -1) Tabs.Insert(Index, _Tab); else Tabs.Add(_Tab); if (IsSelected) BrowserTabs.SelectedIndex = Tabs.IndexOf(_Tab); + //TextOptions.SetTextFormattingMode(_Tab.Content, TextFormattingMode.Display); + } + public void OpenSettings(bool IsSelected = false, int Index = -1) + { + if (WindowState == WindowState.Minimized) + WindowState = WindowState.Normal; + if (Settings.Instance != null && Settings.Instance.Tab != null) + SwitchToTab(Settings.Instance.Tab); + else + { + BrowserTabItem _Tab = new BrowserTabItem { Header = "Settings" }; + if (Settings.Instance == null) + _Tab.Content = new Settings(_Tab); + else + { + Settings.Instance.Tab = _Tab; + _Tab.Content = Settings.Instance; + } + _Tab.Id = Utils.GenerateRandomId(); + _Tab.Action = $"5<,>{_Tab.Id}"; + if (Index != -1) + Tabs.Insert(Index, _Tab); + else + Tabs.Add(_Tab); + if (IsSelected) + SwitchToTab(_Tab); + + //TextOptions.SetTextFormattingMode(_Tab.Content, TextFormattingMode.Display); + //TextOptions.TextHintingModeProperty.OverrideMetadata(typeof(TextHintingMode), new FrameworkPropertyMetadata { DefaultValue = TextHintingMode.Fixed }); + //TextOptions.TextFormattingModeProperty.OverrideMetadata(typeof(TextFormattingMode), new FrameworkPropertyMetadata { DefaultValue = TextFormattingMode.Display }); + } + } + public void SwitchToTab(BrowserTabItem _Tab) + { + BrowserTabs.SelectedIndex = Tabs.IndexOf(_Tab); + } + public BrowserTabItem GetBrowserTabWithId(int Id) + { + foreach (BrowserTabItem _Tab in Tabs) + { + if (_Tab.Id == Id) + return _Tab; + } + return null; } - public void CloseCurrentBrowserTab() + public void CloseBrowserTab(int Id) { + //if (Id == -1) + // Id = Tabs[BrowserTabs.SelectedIndex].Id; + BrowserTabItem _Tab = null; + if (Id == -1) + _Tab = Tabs[BrowserTabs.SelectedIndex]; + else + _Tab = GetBrowserTabWithId(Id); if (Tabs.Count > 1) { - Browser BrowserView = GetBrowserView(Tabs[BrowserTabs.SelectedIndex]); + bool IsSelected = Id != -1 ? _Tab == Tabs[BrowserTabs.SelectedIndex] : true; + //MessageBox.Show(Id.ToString()); + Browser BrowserView = GetBrowserView(_Tab); if (BrowserView != null) BrowserView.DisposeCore(); - Tabs.RemoveAt(BrowserTabs.SelectedIndex); + else + { + if (Settings.Instance.Tab == _Tab) + Settings.Instance.DisposeCore(); + } + if (IsSelected) + { + if (BrowserTabs.SelectedIndex > 0) + BrowserTabs.SelectedIndex = BrowserTabs.SelectedIndex - 1; + else + BrowserTabs.SelectedIndex = BrowserTabs.SelectedIndex + 1; + } + Tabs.Remove(_Tab); + if (IsSelected) + { + if (BrowserTabs.SelectedIndex > Tabs.Count - 1) + BrowserTabs.SelectedIndex = Tabs.Count - 1; + } + + //Tabs.RemoveAt(Tabs.IndexOf(_Tab)); } else { @@ -1337,14 +1603,24 @@ public Browser GetBrowserView(BrowserTabItem Tab = null) } public void ApplyTheme(Theme _Theme) { - bool SetDarkTitleBar = _Theme.DarkTitleBar; - DwmSetWindowAttribute(new WindowInteropHelper(this).Handle, 20, ref SetDarkTitleBar, Marshal.SizeOf(true)); + int SetDarkTitleBar = _Theme.DarkTitleBar ? 1 : 0; + DwmSetWindowAttribute(new WindowInteropHelper(this).Handle, (int)DWMWINDOWATTRIBUTE.DWMWA_USE_IMMERSIVE_DARK_MODE, ref SetDarkTitleBar, Marshal.SizeOf(true)); + + //int trueValue = 2; + //DwmSetWindowAttribute(new WindowInteropHelper(this).Handle, (int)DWMWINDOWATTRIBUTE.DWMWA_SYSTEMBACKDROP_TYPE, ref trueValue, Marshal.SizeOf(typeof(int))); + //DwmSetWindowAttribute(new WindowInteropHelper(this).Handle, (int)DWMWINDOWATTRIBUTE.DWMWA_MICA_EFFECT, ref trueValue, Marshal.SizeOf(typeof(int))); - Resources["PrimaryBrush"] = new SolidColorBrush(_Theme.PrimaryColor); - Resources["FontBrush"] = new SolidColorBrush(_Theme.FontColor); - Resources["BorderBrush"] = new SolidColorBrush(_Theme.BorderColor); - Resources["UnselectedTabBrush"] = new SolidColorBrush(_Theme.UnselectedTabColor); - Resources["ControlFontBrush"] = new SolidColorBrush(_Theme.ControlFontColor); + //Resources["PrimaryBrush"] = new SolidColorBrush(_Theme.PrimaryColor); + //Resources["FontBrush"] = new SolidColorBrush(_Theme.FontColor); + //Resources["BorderBrush"] = new SolidColorBrush(_Theme.BorderColor); + //Resources["UnselectedTabBrush"] = new SolidColorBrush(_Theme.UnselectedTabColor); + //Resources["ControlFontBrush"] = new SolidColorBrush(_Theme.ControlFontColor); + + Resources["PrimaryBrushColor"] = _Theme.PrimaryColor; + Resources["FontBrushColor"] = _Theme.FontColor; + Resources["BorderBrushColor"] = _Theme.BorderColor; + Resources["UnselectedTabBrushColor"] = _Theme.UnselectedTabColor; + Resources["ControlFontBrushColor"] = _Theme.ControlFontColor; //WindowState = WindowState.Normal; foreach (BrowserTabItem Tab in Tabs) @@ -1355,11 +1631,18 @@ public void ApplyTheme(Theme _Theme) //WindowState = WindowState.Maximized; WindowStyle = WindowStyle.ThreeDBorderWindow; WindowStyle = WindowStyle.SingleBorderWindow; + + CurrentTheme = _Theme; } public Theme GetTheme(string Name = "") { if (string.IsNullOrEmpty(Name)) - Name = MainSave.Get("Theme"); + { + if (CurrentTheme != null) + return CurrentTheme; + else + Name = MainSave.Get("Theme"); + } foreach (Theme _Theme in Themes) { if (_Theme.Name == Name) @@ -1367,6 +1650,7 @@ public Theme GetTheme(string Name = "") } return Themes[0]; } + Theme CurrentTheme; public void AdBlock(bool Boolean) { MainSave.Set("AdBlock", Boolean.ToString()); @@ -1403,7 +1687,7 @@ public void SetSandbox(int _Framerate, CefState JSState, CefState LIState, CefSt { Browser BrowserView = GetBrowserView(Tab); if (BrowserView != null) - BrowserView.Unload(Framerate, JSState, LIState, LSState, DBState, WebGLState); + BrowserView.Unload(false, Framerate, JSState, LIState, LSState, DBState, WebGLState); } UnloadTabsTime = 0; } @@ -1418,39 +1702,52 @@ public void CloseSLBr() if (GCTimer != null) GCTimer.Stop(); - StatisticsSave.Set("BlockedTrackers", TrackersBlocked.ToString()); - StatisticsSave.Set("BlockedAds", AdsBlocked.ToString()); - - FavouritesSave.Clear(); - FavouritesSave.Set("Favourite_Count", Favourites.Count.ToString(), false); - for (int i = 0; i < Favourites.Count; i++) - FavouritesSave.Set($"Favourite_{i}", Favourites[i].Tooltip, Favourites[i].Name, false); - FavouritesSave.Save(); - - SearchSave.Set("Search_Engine_Count", SearchEngines.Count.ToString(), false); - for (int i = 0; i < SearchEngines.Count; i++) - SearchSave.Set($"Search_Engine_{i}", SearchEngines[i], false); - SearchSave.Save(); - - TabsSave.Clear(); - if (bool.Parse(MainSave.Get("RestoreTabs"))) + if (Initialized) { - int Count = 0; - int SelectedIndex = 0; - for (int i = 0; i < Tabs.Count; i++) + StatisticsSave.Set("BlockedTrackers", TrackersBlocked.ToString()); + StatisticsSave.Set("BlockedAds", AdsBlocked.ToString()); + + FavouritesSave.Clear(); + FavouritesSave.Set("Favourite_Count", Favourites.Count.ToString(), false); + for (int i = 0; i < Favourites.Count; i++) + FavouritesSave.Set($"Favourite_{i}", Favourites[i].Tooltip, Favourites[i].Name, false); + FavouritesSave.Save(); + + SearchSave.Set("Search_Engine_Count", SearchEngines.Count.ToString(), false); + for (int i = 0; i < SearchEngines.Count; i++) + SearchSave.Set($"Search_Engine_{i}", SearchEngines[i], false); + SearchSave.Save(); + + TabsSave.Clear(); + if (bool.Parse(MainSave.Get("RestoreTabs"))) { - BrowserTabItem Tab = Tabs[i]; - Browser BrowserView = GetBrowserView(Tab); - if (BrowserView != null) + int Count = 0; + int SelectedIndex = 0; + for (int i = 0; i < Tabs.Count; i++) { - TabsSave.Set($"Tab_{Count}", ((Browser)Tab.Content).Address, false); - if (i == BrowserTabs.SelectedIndex) - SelectedIndex = Count; - Count++; + BrowserTabItem Tab = Tabs[i]; + Browser BrowserView = GetBrowserView(Tab); + if (BrowserView != null) + { + TabsSave.Set($"Tab_{Count}", BrowserView.Address, false); + if (i == BrowserTabs.SelectedIndex) + SelectedIndex = Count; + Count++; + } + else + { + if (Settings.Instance.Tab == Tab) + { + TabsSave.Set($"Tab_{Count}", "slbr://settings", false); + if (i == BrowserTabs.SelectedIndex) + SelectedIndex = Count; + Count++; + } + } } + TabsSave.Set("Tab_Count", Count.ToString()); + MainSave.Set("SelectedTabIndex", SelectedIndex.ToString()); } - TabsSave.Set("Tab_Count", Count.ToString()); - MainSave.Set("SelectedTabIndex", SelectedIndex.ToString()); } Cef.Shutdown(); } @@ -1458,6 +1755,61 @@ public void CloseSLBr() private void Window_Loaded(object sender, RoutedEventArgs e) { ApplyTheme(GetTheme()); + + if (!DeveloperMode) + { + if (Utils.CheckForInternetConnection()) + { + try + { + string VersionInfo = TinyDownloader.DownloadString("https://raw.githubusercontent.com/SLT-World/SLBr/main/Version.txt").Replace("\n", ""); + if (!VersionInfo.StartsWith(ReleaseVersion)) + ToastBox.Show(VersionInfo, $"SLBr {VersionInfo} is now available, please update SLBr to keep up with the progress.", 10); + //Prompt(false, string.Format(NewUpdateString, VersionInfo), true, "Download", $"24<,>https://github.com/SLT-World/SLBr/releases/tag/{VersionInfo}", $"https://github.com/SLT-World/SLBr/releases/tag/{VersionInfo}", true, "\xE896");//SLBr is up to date + } + catch { } + } + } + + SplashScreen.Instance.Close(); + Initialized = true; + } + private void Window_StateChanged(object sender, EventArgs e) + { + //Timeline.SetDesiredFrameRate(, 1); + /*Dispatcher.Invoke(new Action(() => + { + switch (WindowState) + { + case WindowState.Maximized: + ChangeWPFFrameRate(WPFFrameRate); + break; + case WindowState.Minimized: + ChangeWPFFrameRate(1); + break; + case WindowState.Normal: + ChangeWPFFrameRate(WPFFrameRate); + break; + } + }));*/ } + + private void BrowserTabs_SelectionChanged(object sender, SelectionChangedEventArgs e) + { + //Icon = new BitmapImage(new Uri(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Resources", (CurrentTheme.DarkTitleBar ? "White Tab Icon.png" : "Black Tab Icon.png")))); + BrowserTabItem _CurrentTab = Tabs[BrowserTabs.SelectedIndex]; + Title = _CurrentTab.Header + " - SLBr"; + /*Browser _Browser = GetBrowserView(_CurrentTab); + if (_Browser != null) + Title = _Browser.Title + " - SLBr"; + else if (_CurrentTab.Content is Settings) + Title = "Settings - SLBr";*/ + } + + /*static void ChangeWPFFrameRate(int FrameRate) + { + //Timeline.DesiredFrameRateProperty.DefaultMetadata.DefaultValue = FrameRate; + Timeline.DesiredFrameRateProperty.OverrideMetadata(typeof(Timeline), new FrameworkPropertyMetadata { DefaultValue = FrameRate }); + }*/ } } diff --git a/SLBr/Pages/Browser.xaml b/SLBr/Pages/Browser.xaml index 2c2d41f..136e7a2 100644 --- a/SLBr/Pages/Browser.xaml +++ b/SLBr/Pages/Browser.xaml @@ -5,6 +5,7 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:controls="clr-namespace:SLBr.Controls" mc:Ignorable="d" d:DesignHeight="450" d:DesignWidth="800" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" FontFamily="Segoe MDL2 Assets"> + @@ -25,7 +26,7 @@ - + @@ -63,6 +64,8 @@ + + @@ -161,33 +164,113 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +