예제 #1
0
파일: U3Service.cs 프로젝트: jimjag/crayon
        public override void RegisterListener(Dictionary <string, object> request, Func <Dictionary <string, object>, bool> callback)
        {
            U3Window window = GetWindow(request);

            if (window == null)
            {
                return;
            }

            switch (GetValue <string>(request, "type", ""))
            {
            case "events":
                window.EventsListener = callback;
                break;

            case "batch":
                window.BatchListener = callback;
                break;

            case "closed":
                window.ClosedListener = callback;
                break;

            case "loaded":
                window.LoadedListener = callback;
                break;

            default:
                throw new NotImplementedException();
            }
        }
예제 #2
0
파일: U3Service.cs 프로젝트: jimjag/crayon
        public override async Task <Dictionary <string, object> > HandleRequest(Dictionary <string, object> request)
        {
            U3Window window = GetWindow(request);

            switch (GetValue(request, "type", ""))
            {
            case "prepareWindow":
                window = PlatformUtil.CreateWindow(idAlloc++, this.Hub);
                this.windows[window.ID] = window;
                return(new Dictionary <string, object>()
                {
                    { "windowId", window.ID }
                });

            case "show":
            {
                int      width           = GetValue <int>(request, "width", 0);
                int      height          = GetValue <int>(request, "height", 0);
                string   iconBase64      = GetValue <string>(request, "icon", "");
                object[] initialData     = GetValue <object[]>(request, "initialData", null) ?? new object[0];
                string   title           = GetValue <string>(request, "title", "Crayon Window");
                bool     keepAspectRatio = GetValue <bool>(request, "keepAspectRatio", false);
                string   closeMethod     = await window.CreateAndShowWindow(
                    title,
                    iconBase64 == ""?null : Convert.FromBase64String(iconBase64),
                    width, height,
                    keepAspectRatio,
                    initialData);

                return(new Dictionary <string, object>()
                    {
                        { "cause", closeMethod }
                    });
            }

            case "data":
                await window.SendData(new Dictionary <string, object>() { { "buffer", request["buffer"] } });

                return(new Dictionary <string, object>());

            default:
                throw new NotImplementedException();
            }
        }