<commit_before>﻿using System.Threading.Tasks;
using WebSharpJs.NodeJS;
using WebSharpJs.Script;

namespace WebSharpJs.Electron
{
    public class Menu : NodeJsObject
    {
        protected override string ScriptProxy =>
                        @"function () { 

                            if (options && options.length > 0)
                            {
                                return Menu.buildFromTemplate(options);
                            }
                            else
                                return new Menu(); 
                        }()";
        protected override string Requires => require;

        string require = string.Empty;
        static readonly string mainRequire = @"const {Menu} = require('electron')";
        static readonly string remoteRequire = @"const {remote} = require('electron');
                                                const { Menu} = remote;"; 

        // Save off the ScriptObjectProxy implementation to cut down on bridge calls.
        static NodeObjectProxy scriptProxy;

        public static async Task<Menu> CreateMain()
        {
            var proxy = new Menu();
            proxy.require = mainRequire;
            if (scriptProxy != null)
                proxy.ScriptObjectProxy = scriptProxy;

            scriptProxy = await proxy.Initialize();
            return proxy;

        }

        public static async Task<Menu> CreateRemote()
        {
            var proxy = new Menu();
            proxy.require = remoteRequire;
            if (scriptProxy != null)
                proxy.ScriptObjectProxy = scriptProxy;

            scriptProxy = await proxy.Initialize();
            return proxy;

        }

        public static async Task<Menu> BuildFromTemplate(dynamic template)
        {
            var proxy = new Menu();
            proxy.require = remoteRequire;
            if (scriptProxy != null)
                proxy.ScriptObjectProxy = scriptProxy;

            scriptProxy = await proxy.Initialize(template);
            return proxy;

        }


        [ScriptableMember(ScriptAlias = "append")]
        public async void Append(MenuItem menuItem)
        {
            await Invoke<object>("Append", menuItem);
        }

        [ScriptableMember(ScriptAlias = "insert")]
        public async void Insert(int pos, MenuItem menuItem)
        {
            await Invoke<object>("Insert", pos, menuItem);
        }

        public async Task<ScriptObjectCollection<MenuItem>> Items()
        {
            return await GetProperty<ScriptObjectCollection<MenuItem>>("items"); ;
        }

        //[ScriptableMember(ScriptAlias = "items")]
        public object[] Itemss<commit_msg>Menu BuildFromTemplate now takes a strongly typed array of MenuItemOptions[]<commit_after>﻿using System.Threading.Tasks;
using WebSharpJs.NodeJS;
using WebSharpJs.Script;

namespace WebSharpJs.Electron
{
    public class Menu : NodeJsObject
    {
        protected override string ScriptProxy =>
                        @"function () { 

                            if (options && options.length > 0)
                            {
                                return Menu.buildFromTemplate(options);
                            }
                            else
                                return new Menu(); 
                        }()";
        protected override string Requires => require;

        string require = string.Empty;
        static readonly string mainRequire = @"const {Menu} = require('electron')";
        static readonly string remoteRequire = @"const {remote} = require('electron');
                                                const { Menu} = remote;"; 

        // Save off the ScriptObjectProxy implementation to cut down on bridge calls.
        static NodeObjectProxy scriptProxy;

        public static async Task<Menu> CreateMain()
        {
            var proxy = new Menu();
            proxy.require = mainRequire;
            if (scriptProxy != null)
                proxy.ScriptObjectProxy = scriptProxy;

            scriptProxy = await proxy.Initialize();
            return proxy;

        }

        public static async Task<Menu> CreateRemote()
        {
            var proxy = new Menu();
            proxy.require = remoteRequire;
            if (scriptProxy != null)
                proxy.ScriptObjectProxy = scriptProxy;

            scriptProxy = await proxy.Initialize();
            return proxy;

        }

        public static async Task<Menu> BuildFromTemplate(MenuItemOptions[] template)
        {
            var proxy = new Menu();
            proxy.require = remoteRequire;
            if (scriptProxy != null)
                proxy.ScriptObjectProxy = scriptProxy;

            scriptProxy = await proxy.Initialize(template);
            return proxy;

        }


        [ScriptableMember(ScriptAlias = "append")]
        public async void Append(MenuItem menuItem)
        {
            await Invoke<object>("Append", menuItem);
        }

        [ScriptableMember(ScriptAlias = "insert")]
        public async void Insert(int pos, MenuItem menuItem)
        {
            await Invoke<object>("Insert", pos, menuItem);
        }

        public async Task<ScriptObjectCollection<MenuItem>> Items()
        {
            return await GetProperty<ScriptObjectCollection<MenuItem>>("items"); ;
        }

        //[ScriptableMember(ScriptAlias = "items")]
        public object[] Itemss
{'fraction_non_alphanumeric': 0.0844811753902663, 'fraction_numerical': 0.0003673094582185491, 'mean_word_length': 1.620789220404235, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4335651', 'n_tokens_mistral': 1245, 'n_tokens_neox': 1186, 'n_words': 338}