Exemplo n.º 1
0
        /// <summary>
        /// Loads and shows a bar.
        /// </summary>
        /// <param name="path">JSON file containing the bar data.</param>
        /// <param name="content">The file content (if it's already loaded).</param>
        /// <param name="serviceProvider"></param>
        public BarData?LoadFromBarJson(string path, string?content = null, IServiceProvider?serviceProvider = null)
        {
            if (this.firstBar && AppOptions.Current.Launch.BarFile != null)
            {
                path = AppOptions.Current.Launch.BarFile;
            }

            BarData?bar = null;

            try
            {
                bar = BarData.Load(serviceProvider ?? App.Current.ServiceProvider, path, content);
            }
            catch (Exception e) when(!(e is OutOfMemoryException))
            {
                this.Logger.LogError(e, "Problem loading the bar.");
            }

            if (this.barWindow != null)
            {
                this.CloseBar();
            }

            if (bar != null)
            {
                this.CreateBarWindow(bar);
                bar.ReloadRequired += this.OnBarOnReloadRequired;
            }

            return(bar);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Loads and shows a bar.
        /// </summary>
        /// <param name="path">JSON file containing the bar data.</param>
        /// <param name="content">The file content (if it's already loaded).</param>
        /// <param name="serviceProvider"></param>
        public BarData?LoadFromBarJson(string path, string?content = null, IServiceProvider?serviceProvider = null)
        {
            if (this.firstBar && AppOptions.Current.Launch.BarFile is not null)
            {
                path = AppOptions.Current.Launch.BarFile;
            }

            BarData?bar = null;

            try
            {
                bar = BarData.Load(serviceProvider ?? App.Current.ServiceProvider, path, content);
            }
            catch (Exception e) when(!(e is OutOfMemoryException))
            {
                this.Logger.LogError(e, "Problem loading the bar.");
            }

            if (this.barWindow is not null)
            {
                this.CloseBar();
            }

            this.BarIsLoaded = true;

            if (bar is not null)
            {
                // if any of the items are application actions and the application isn't available, remove the button from the items collection
                var index = 0;
                while (index < bar.AllItems.Count)
                {
                    var actionAsApplicationAction = bar.AllItems[index].Action as Data.Actions.ApplicationAction;
                    if (actionAsApplicationAction is not null)
                    {
                        if (actionAsApplicationAction.IsAvailable == false)
                        {
                            bar.AllItems.RemoveAt(index);
                            continue;
                        }
                    }

                    index += 1;
                }

                this.CreateBarWindow(bar);
                bar.ReloadRequired += this.OnBarOnReloadRequired;
            }

            return(bar);
        }