示例#1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MainWindow" /> class.
 /// </summary>
 public MainWindow()
 {
     InitializeComponent();
     ListBox.Items    = this.Examples = this.GetExamples(this.GetType().Assembly).OrderBy(e => e.Title).ToArray();
     this.DataContext = this;
     DevToolsExtensions.AttachDevTools(this);
 }
示例#2
0
        public async void ClearCache()
        {
            try
            {
                if (_browser == null)
                {
                    return;
                }

                // Find the first / after https://
                var slashAfterHost = lastUrl.IndexOf("/", 9);

                // If we can't build an origin, there's nothing we can do.
                if (slashAfterHost < 0)
                {
                    return;
                }

                var origin = lastUrl.Substring(0, slashAfterHost);
                var dtc    = DevToolsExtensions.GetDevToolsClient(_browser);
                var result = await dtc.Storage.ClearDataForOriginAsync(origin, "appcache,cookies,file_systems,cache_storage");

                BrowserConsoleLog?.Invoke(null, new BrowserConsoleLogEventArgs(result.Success ? result.ResponseAsJsonString : "fail", "", 0));

                // Reload the overlay to refill the cache and replace that potentially corrupted resources.
                Reload();
            }
            catch (Exception ex)
            {
                BrowserConsoleLog?.Invoke(null, new BrowserConsoleLogEventArgs($"Failed to clear cache: {ex}", "", 0));
            }
        }
示例#3
0
        private void Browser_IsBrowserInitializedChanged(object sender, EventArgs e)
        {
            Trace.WriteLine(browser.GetDevToolsClient().ToString());
            // browser.GetDevToolsClient().ExecuteDevToolsMethodAsync("Capture screenshot");
            if (browser.IsBrowserInitialized)
            {
                Cef.UIThreadTaskFactory.StartNew(() =>
                {
                    string error       = "";
                    var requestContext = browser.GetBrowser().GetHost().RequestContext;
                    requestContext.SetPreference("profile.default_content_setting_values.plugins", 1, out error);
                });


                Task.Run(async() =>
                         await DevToolsExtensions.ExecuteDevToolsMethodAsync(browser.GetBrowser(), 0, "Network.setCacheDisabled", new Dictionary <string, object>
                {
                    {
                        "cacheDisabled", true
                    }
                })
                         );


                // browser.ShowDevTools();
            }
        }
示例#4
0
        public ToolCommands(CommandIconService commandIconService, AvaloniaGlobalComponent global)
        {
            Global = global.Global;
            var walletManagerCommand = ReactiveCommand.Create(OnWalletManager);

            var settingsCommand = ReactiveCommand.Create(() =>
                                                         IoC.Get <IShell>().AddOrSelectDocument(() => new SettingsViewModel(Global)));

            var transactionBroadcasterCommand = ReactiveCommand.Create(() =>
                                                                       IoC.Get <IShell>().AddOrSelectDocument(() => new TransactionBroadcasterViewModel(Global)));

#if DEBUG
            var devToolsCommand = ReactiveCommand.Create(() =>
                                                         DevToolsExtensions.OpenDevTools((Application.Current.ApplicationLifetime as IClassicDesktopStyleApplicationLifetime).MainWindow));
#endif
            Observable
            .Merge(walletManagerCommand.ThrownExceptions)
            .Merge(settingsCommand.ThrownExceptions)
            .Merge(transactionBroadcasterCommand.ThrownExceptions)
#if DEBUG
            .Merge(devToolsCommand.ThrownExceptions)
#endif
            .ObserveOn(RxApp.TaskpoolScheduler)
            .Subscribe(ex => Logger.LogError(ex));

            WalletManagerCommand = new CommandDefinition(
                "Wallet Manager",
                commandIconService.GetCompletionKindImage("WalletManager"),
                walletManagerCommand);

            SettingsCommand = new CommandDefinition(
                "Settings",
                commandIconService.GetCompletionKindImage("Settings"),
                settingsCommand);

            TransactionBroadcasterCommand = new CommandDefinition(
                "Transaction Broadcaster",
                commandIconService.GetCompletionKindImage("BroadcastTransaction"),
                transactionBroadcasterCommand);

#if DEBUG
            DevToolsCommand = new CommandDefinition(
                "Dev Tools",
                commandIconService.GetCompletionKindImage("DevTools"),
                devToolsCommand);
#endif
        }
        /// <summary>
        /// Called just before a browser is destroyed. This callback will be the last notification that references
        /// <paramref name="browser"/> on the UI thread.
        /// </summary>
        /// <param name="browser"></param>
        /// <remarks>
        /// Release all references to the browser object and do not attempt to execute any methods on the browser
        /// object (other than <see cref="CefBrowser.Identifier"/> or <see cref="CefBrowser.IsSame"/>) after this
        /// callback returns. Any in-progress network requests associated with <paramref name="browser"/> will be
        /// aborted when the browser is destroyed, and <see cref="CefResourceRequestHandler"/> callbacks related
        /// to those requests may still arrive on the IO thread after this method is called.
        ///</remarks>
        internal protected virtual void OnBeforeClose(CefBrowser browser)
        {
#if DEBUG
            if (!BrowserObject.IsSame(browser))
            {
                throw new InvalidOperationException();
            }
#endif
            try
            {
                WebView.RaiseClosed();
            }
            finally
            {
                this.BrowserObject = null;
                DevToolsExtensions.ReleaseProtocolClient(browser.Identifier);
                CefNetApplication.Instance.OnBrowserDestroyed(browser);
            }
        }
示例#6
0
        public async void ClearCache()
        {
            try
            {
                if (_browser == null || !_isRendering)
                {
                    return;
                }

                var dtc    = DevToolsExtensions.GetDevToolsClient(_browser);
                var result = await dtc.Network.ClearBrowserCacheAsync();

                BrowserConsoleLog?.Invoke(null, new BrowserConsoleLogEventArgs(result.Success ? result.ResponseAsJsonString : "fail", "", 0));
                // Restart the broswer to avoid memory cache, and refill the cache and replace that potentially corrupted resources.
                BeginRender();
            }
            catch (Exception ex)
            {
                BrowserConsoleLog?.Invoke(null, new BrowserConsoleLogEventArgs($"Failed to clear cache: {ex}", "", 0));
            }
        }
示例#7
0
        public ToolCommands(CommandIconService commandIconService, AvaloniaGlobalComponent global)
        {
            Global = global.Global;
            var walletManagerCommand = ReactiveCommand.Create(OnWalletManager);

            var settingsCommand = ReactiveCommand.Create(() => IoC.Get <IShell>().AddOrSelectDocument(() => new SettingsViewModel(Global)));

#if DEBUG
            var devToolsCommand = ReactiveCommand.Create(() =>
            {
                DevToolsExtensions.OpenDevTools((Application.Current.ApplicationLifetime as IClassicDesktopStyleApplicationLifetime).MainWindow);
            });
#endif

            Observable
            .Merge(walletManagerCommand.ThrownExceptions)
            .Merge(settingsCommand.ThrownExceptions)
#if DEBUG
            .Merge(devToolsCommand.ThrownExceptions)
#endif
            .Subscribe(OnException);

            WalletManagerCommand = new CommandDefinition(
                "Wallet Manager",
                commandIconService.GetCompletionKindImage("WalletManager"),
                walletManagerCommand);

            SettingsCommand = new CommandDefinition(
                "Settings",
                commandIconService.GetCompletionKindImage("Settings"),
                settingsCommand);

#if DEBUG
            DevToolsCommand = new CommandDefinition(
                "Dev Tools",
                commandIconService.GetCompletionKindImage("DevTools"),
                devToolsCommand);
#endif
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="MainWindow" /> class.
 /// </summary>
 public MainWindow()
 {
     InitializeComponent();
     DevToolsExtensions.AttachDevTools(this);
 }
示例#9
0
        public static void AttachDevTools(Window window)
        {
#if DEBUG
            DevToolsExtensions.AttachDevTools(window);
#endif
        }