Example #1
0
    void onWebQuery(UWKWebQuery query)
    {
        var request = UWKJson.Deserialize(query.Request) as Dictionary <string, object>;

        var message = request["message"] as string;

        if (message == "UnityMessage")
        {
            var payload = request["payload"] as Dictionary <string, object>;

            var messageCount = (long)payload["messageCount"];

            query.Success("Query Response from Unity: Message Count = " + messageCount);
        }
    }
Example #2
0
    private static void onWebQuery(UWKWebQuery query)
    {
        var request = UWKJson.Deserialize(query.Request) as Dictionary <string, object>;

        var message = request ["message"] as string;

        if (message == "ButtonClicked")
        {
            var payload = UWKJson.Serialize(request ["payload"] as Dictionary <string, object>);

            query.Success("Query Response from Unity: Success!");

                        #if UNITY_EDITOR
            EditorUtility.DisplayDialog("Hello!", "Button clicked, value passed:\n" + payload, "OK!");
                        #endif
        }
    }
Example #3
0
        public void saveFile()
        {
            Dictionary <string, object> qry = new Dictionary <string, object>();

            qry.Add("cmd", "saveFile");
            qry.Add("params", new Dictionary <string, object>());

            view.makeQuery(qry, delegate(bool success, string value) {
                if (!success)
                {
                    Debug.LogError("Query failed.");
                }
                else
                {
                    content = (UWKJson.Deserialize(value) as IDictionary <string, object>)["content"] as string;
                }
            });
        }
Example #4
0
    public static void Initialize()
    {
        // TODO: setup initialization JSON elsewhere, possibly a file
        Dictionary <string, object> djson = new Dictionary <string, object>();

        Dictionary <string, object> app;

        djson["application"] = app = new Dictionary <string, object>();

        app["hasProLicense"] = Application.HasProLicense();

        string dataPath = Application.dataPath;

        #if UNITY_5_0
            #if !UNITY_EDITOR
        // Unity 5 bug
        dataPath += "/Resources";
            #endif
        #endif

        app["dataPath"]              = dataPath;
        app["persistentDataPath"]    = Application.persistentDataPath;
        app["temporaryCachePath"]    = Application.temporaryCachePath;
        app["isEditor"]              = Application.isEditor;
        app["platform"]              = Application.platform;
        app["unityVersion"]          = Application.unityVersion;
        app["targetFrameRate"]       = Application.targetFrameRate;
        app["graphicsDeviceVersion"] = SystemInfo.graphicsDeviceVersion;
        app["imeEnabled"]            = UWKCore.IMEEnabled;

        // Proxy
        app["proxyEnabled"]  = UWKConfig.ProxyEnabled;
        app["proxyHostName"] = UWKConfig.ProxyHostname;
        app["proxyUsername"] = UWKConfig.ProxyUsername;
        app["proxyPassword"] = UWKConfig.ProxyPassword;
        app["proxyPort"]     = UWKConfig.ProxyPort;
        app["authEnabled"]   = UWKConfig.AuthEnabled;
        app["authUsername"]  = UWKConfig.AuthUsername;
        app["authPassword"]  = UWKConfig.AuthPassword;

#if UNITY_EDITOR
        app["companyName"] = PlayerSettings.companyName;
        app["productName"] = PlayerSettings.productName;
#else
        // Unity doesn't provide this data at runtime
        // so, load it from our config

        app["companyName"] = "DefaultCompany";
        app["productName"] = "DefaultProduct";

        var cfgfile = Application.streamingAssetsPath + "/uWebKit/Config/uwebkit.cfg";

        if (File.Exists(cfgfile))
        {
            var jsonString = "";

            #if !UNITY_WEBPLAYER
            jsonString = File.ReadAllText(cfgfile);
            #endif

            var cfg = UWKJson.Deserialize(jsonString) as Dictionary <string, object>;

            if (cfg.ContainsKey("companyName"))
            {
                app["companyName"] = (string)cfg["companyName"];
            }

            if (cfg.ContainsKey("productName"))
            {
                app["productName"] = (string)cfg["productName"];
            }
        }
#endif

        var json         = UWKJson.Serialize(djson);
        var nativeString = NativeUtf8FromString(json);

        int betaCheck = UWK_Initialize(log, error, processMessage, nativeString);

        if (betaCheck >= 99)
        {
            UWKCore.BetaVersion = true;

            betaCheck -= 100;

            if (betaCheck == -1)
            {
                Debug.LogError("uWebKit Beta Expired");
#if UNITY_EDITOR
                EditorUtility.DisplayDialog("uWebKit Beta Expired", "This BETA version of uWebKit has expired.\nPlease visit http://www.uwebkit.com", "Ok");
                EditorApplication.ExecuteMenuItem("Edit/Play");
#endif
            }
            else
            {
                string message = String.Format("There are {0} days left of this expiring uWebKit BETA", betaCheck);

                if (betaCheck == 0)
                {
                    message = String.Format("There is less than a day left of this expiring uWebKit BETA");
                }

                if (!UWK_HasDisplayedBetaMessage())
                {
#if UNITY_EDITOR
                    EditorUtility.DisplayDialog("uWebKit BETA Version", "\nThis is a BETA version of uWebKit.\n\n" + message, "Ok");
#endif
                }

                Debug.Log(message);
            }
        }

        Marshal.FreeHGlobal(nativeString);
    }
Example #5
0
    /// <summary>
    /// Internal Plugin -> Unity message receiving
    /// </summary>
    public static void ProcessMessage(ref UWKMessage msg)
    {
        UWKWebView view = null;

        bool msgView = false;

        switch (msg.type)
        {
        case UWKMessageType.UMSG_VIEW_LOADFINISHED:
        case UWKMessageType.UMSG_VIEW_URLCHANGED:
        case UWKMessageType.UMSG_VIEW_TITLECHANGED:
        case UWKMessageType.UMSG_VIEW_LOADPROGRESS:
        case UWKMessageType.UMSG_VIEW_ICONCHANGED:
        case UWKMessageType.UMSG_JAVASCRIPT_CONSOLE:
        case UWKMessageType.UMSG_JAVASCRIPT_MESSAGE:
        case UWKMessageType.UMSG_VIEW_CONTENTSIZECHANGED:
        case UWKMessageType.UMSG_IME_FOCUSIN:
        case UWKMessageType.UMSG_IME_FOCUSOUT:
        case UWKMessageType.UMSG_VIEW_REQUESTNEWVIEW:
            msgView = true;
            break;
        }

        if (msgView)
        {
            if (!viewLookup.TryGetValue(msg.browserID, out view))
            {
                Debug.Log("Warning: Unable to get view for message: " + Enum.GetName(typeof(UWKMessageType), msg.type));
                return;
            }
        }

        switch (msg.type)
        {
        case UWKMessageType.UMSG_VIEW_LOADFINISHED:
            view.LoadFinished(view);
            break;

        case UWKMessageType.UMSG_VIEW_URLCHANGED:
            view.URLChanged(view, UWKPlugin.GetMessageString(ref msg, 0));
            break;

        case UWKMessageType.UMSG_VIEW_TITLECHANGED:
            view.TitleChanged(view, UWKPlugin.GetMessageString(ref msg, 0));
            break;

        case UWKMessageType.UMSG_VIEW_LOADPROGRESS:
            view.LoadProgress(view, msg.iParams[0]);
            break;

        case UWKMessageType.UMSG_VIEW_ICONCHANGED:

            int size = UWKPlugin.GetMsgDataSize(ref msg, 0);

            if (size > 0)
            {
                byte[] bytes = new byte[size];

                if (UWKPlugin.GetMsgDataBytes(ref msg, 0, size, bytes))
                {
                    view.IconChanged(msg.iParams[0], msg.iParams[1], bytes);
                }
            }

            break;

        case UWKMessageType.UMSG_JAVASCRIPT_CONSOLE:
            view.JSConsole(view, UWKPlugin.GetMessageString(ref msg, 0), msg.iParams[0], UWKPlugin.GetMessageString(ref msg, 1));
            break;

        case UWKMessageType.UMSG_JAVASCRIPT_MESSAGE:
            var json = UWKPlugin.GetMessageString(ref msg, 1);
            var dict = UWKJson.Deserialize(json) as Dictionary <string, object>;
            view.JSMessageReceived(view, UWKPlugin.GetMessageString(ref msg, 0), json, dict);
            break;

        case UWKMessageType.UMSG_VIEW_CONTENTSIZECHANGED:
            view.ContentSizeChanged(view, msg.iParams[0], msg.iParams[1]);
            break;

        case UWKMessageType.UMSG_IME_FOCUSIN:
            view.IMEFocusIn(ref msg);
            break;

        case UWKMessageType.UMSG_IME_FOCUSOUT:
            view.IMEFocusOut();
            break;

        case UWKMessageType.UMSG_VIEW_REQUESTNEWVIEW:
            view.NewViewRequested(view, UWKPlugin.GetMessageString(ref msg, 0));
            break;

        case UWKMessageType.UMSG_ACTIVATION_STATE:
            #if UNITY_EDITOR
            if (msg.iParams[0] != 1 && msg.iParams[0] != 5)
            {
                if (sInstance.gameObject.GetComponent <UWKActivation>() == null)
                {
                    sInstance.gameObject.AddComponent <UWKActivation>();
                }
            }
            UWKActivation.SetActivationState(msg.iParams[0]);
            #endif

            break;
        }
    }