Kaynağa Gözat

Updated shortcut opening method to floatwindow

Toby Chui 3 yıl önce
ebeveyn
işleme
a3accb1143

+ 5 - 0
legacy/Browser/backend/downimg.js

@@ -0,0 +1,5 @@
+//Get the http content of a webpage, given "url"
+requirelib("http");
+var ext = url.split(".").pop();
+var content = http.getb64(url);
+sendResp(content);

+ 4 - 0
legacy/Browser/backend/downpage.js

@@ -0,0 +1,4 @@
+//Get the http content of a webpage, given "url"
+requirelib("http");
+var content = http.get(url);
+sendResp(content);

+ 48 - 0
legacy/Browser/embedded.html

@@ -0,0 +1,48 @@
+<!DOCTYPE html>
+<html>
+	<head>
+		<meta charset="UTF-8">
+		<meta name="apple-mobile-web-app-capable" content="yes" />
+		<meta name="viewport" content="user-scalable=no, width=device-width, initial-scale=1, maximum-scale=1"/>
+		<meta name="theme-color" content="#4b75ff">
+		<link rel="stylesheet" href="../script/semantic/semantic.min.css">
+		<script src="../script/jquery.min.js"></script>
+		<script src="../script/semantic/semantic.min.js"></script>
+		<script src="../script/ao_module.js"></script>
+        <title>Browser</title>
+        <style>
+            body{
+                overflow: hidden;
+            }
+            #mainframe{
+                width: 100vw;
+                height: 100vh;
+                border: 0px solid transparent;
+            }
+        </style>
+    </head>
+    <body>
+        <iframe id="mainframe" src="">
+
+		</iframe>
+		<script>
+			//Get window hash
+			let targetFrameingURL = "";
+			if (window.location.hash.length > 0){
+				targetFrameingURL = window.location.hash.substr(1);
+				targetFrameingURL = JSON.parse(decodeURIComponent(targetFrameingURL));
+				console.log(targetFrameingURL);
+                $("#mainframe").attr("src", targetFrameingURL)
+
+                //Change title to match
+                ao_module_agirun("Browser/backend/downpage.js", {
+                    url: targetFrameingURL
+                }, function(data){
+                    //console.log(data);
+                    var pageTitle = $(data).filter('title').text();
+                    ao_module_setWindowTitle(pageTitle);
+                })
+			}
+		</script>
+    </body>
+</html>

BIN
legacy/Browser/img/baseline_language_black_48dp.png


BIN
legacy/Browser/img/desktop_icon.png


BIN
legacy/Browser/img/desktop_icon.psd


BIN
legacy/Browser/img/module_icon.png


BIN
legacy/Browser/img/module_icon.psd


BIN
legacy/Browser/img/small_icon.png


BIN
legacy/Browser/img/small_icon.psd


+ 162 - 0
legacy/Browser/index.html

@@ -0,0 +1,162 @@
+<!DOCTYPE html>
+<html>
+	<head>
+		<meta charset="UTF-8">
+		<meta name="apple-mobile-web-app-capable" content="yes" />
+		<meta name="viewport" content="user-scalable=no, width=device-width, initial-scale=1, maximum-scale=1"/>
+		<meta name="theme-color" content="#4b75ff">
+		<link rel="stylesheet" href="../script/semantic/semantic.min.css">
+		<script src="../script/jquery.min.js"></script>
+		<script src="../script/semantic/semantic.min.js"></script>
+		<script src="../script/ao_module.js"></script>
+		<title>Browser</title>
+		<style>
+			
+		</style>
+	</head>
+	<body>
+		<div id="renderer">
+
+		</div>
+		<script>
+			let renderingURL = "http://124.244.86.40:8080";
+			//Get window hash
+			let targetFrameingURL = "";
+			if (window.location.hash.length > 0){
+				targetFrameingURL = window.location.hash.substr(1);
+				targetFrameingURL = JSON.parse(decodeURIComponent(targetFrameingURL));
+				console.log(targetFrameingURL);
+			}
+
+			ao_module_agirun("Browser/backend/downpage.js", {
+				url: renderingURL
+			}, function(data){
+				var postScripts = manualScriptLoading(renderingURL, data, true);
+				//console.log(data);
+				var titleFilter = JSON.parse(JSON.stringify(data));
+				var pageTitle = $(titleFilter).filter('title').text();
+				var renderEle =  $(JSON.parse(JSON.stringify(data)));
+				console.log(renderEle);
+				$(renderEle).each(function(){
+					if (!$(this).is("script")){
+						$("#renderer").append($(this));
+						if ($(this).attr("src") !== undefined){
+							fixRelativePath(renderingURL, $(this).attr("src"), $(this));
+						}
+					}
+				});
+				ao_module_setWindowTitle(pageTitle);
+
+				//Get the script parts and execute it
+				setTimeout(function(){
+					postScripts.forEach(function(script){
+						$("#renderer").append($(script));
+					});
+				}, 300);
+
+				//Replace all images
+				$("img").each(function(){
+					bufferImageLoad(renderingURL, $(this).attr("src"), $(this));
+				});
+						
+			});
+
+
+			function manualScriptLoading(url, contentBody, srcOnly = true){
+				var scripts = $(contentBody).filter("script");
+				console.log(scripts);
+				var postScripts = [];
+				scripts.each(function(){
+					if (srcOnly){
+						if ($(this).attr("src") == undefined){
+							let internalScriptEle = $(this);
+							postScripts.push(internalScriptEle);
+						}else{
+							//Check for relative or absolute
+							if ($(this).attr("src").includes("//") == false){
+								let seperator = "/";
+								if ($(this).attr("src").substr(0, 1) == "/"){
+									seperator = "";
+								}
+								$(this).attr("src", url+seperator + $(this).attr("src"));
+								console.log("Fixing relative import with absolute: ", $(this).attr("src"));
+							}
+							$("head").append($(this));
+						}
+					}else{
+						//Check for relative or absolute
+						if ($(this).attr("src").includes("//") == false){
+								let seperator = "/";
+								if ($(this).attr("src").substr(0, 1) == "/"){
+									seperator = "";
+								}
+								$(this).attr("src", url+seperator + $(this).attr("src"));
+								console.log("Fixing relative import with absolute: ", $(this).attr("src"));
+							}
+							$("head").append($(this));
+					}
+					console.log($(this).attr("src"));
+				});
+				return postScripts;
+			}
+
+			function fixRelativePath(baseURL, relpath, element){
+				let fullURL = relpath;
+				if (!relpath.includes("//")){
+					let seperator = "/";
+					if (relpath.substr(0, 1) == "/"){
+						seperator = "";
+					}
+					fullURL = baseURL + seperator + relpath;
+				}
+				$(element).attr('src',fullURL);
+			}
+
+			function bufferImageLoad(baseURL, imageURL, object){
+				//Parse the relative URL
+				let fullURL = imageURL;
+				let ext = imageURL.split(".").pop();
+				if (!imageURL.includes("//")){
+					let seperator = "/";
+					if (imageURL.substr(0, 1) == "/"){
+						seperator = "";
+					}
+					fullURL = baseURL + seperator + imageURL;
+				}
+
+				console.log(fullURL);
+				
+				if (ext == "svg"){
+					$(object).attr("src", fullURL);
+				}else{
+					ao_module_agirun("Browser/backend/downimg.js", {
+						url: fullURL
+					}, function(base64){
+						$(object).attr("src", "data:image/" + ext + ";base64," + base64);
+					});
+				}
+
+				
+				
+			}
+
+			
+
+			function stringToBytes (str) {  
+				var ch, st, re = [];  
+				for (var i = 0; i < str.length; i++ ) {    
+					ch = str.charCodeAt(i);   
+					st = [];        
+					do {     
+						st.push( ch & 0xFF );
+						ch = ch >> 8;
+					} while ( ch );
+					re = re.concat( st.reverse() );  
+				}   // return an array of bytes  
+				return re;
+			} 
+
+
+		</script>
+	</body>
+</html>	

+ 24 - 0
legacy/Browser/init.agi

@@ -0,0 +1,24 @@
+/*
+	Camera App Register Script
+*/
+
+//Setup the module information
+var moduleLaunchInfo = {
+    Name: "Browser",
+	Desc: "Just an iframe",
+	Group: "Media",
+	IconPath: "Browser/img/module_icon.png",
+	Version: "1.0",
+	StartDir: "Browser/index.html",
+	SupportFW: true,
+	InitFWSize: [1024, 600],
+	LaunchFWDir: "Browser/index.html",
+	SupportEmb: true,
+	InitEmbSize: [360, 200],
+	LaunchEmb: "Browser/embedded.html",
+	SupportedExt: [".wapp"]
+}
+
+
+//Register the module
+registerModule(JSON.stringify(moduleLaunchInfo));

+ 30 - 0
mod/agi/agi.http.go

@@ -2,6 +2,7 @@ package agi
 
 import (
 	"bytes"
+	"encoding/base64"
 	"encoding/json"
 	"errors"
 	"io"
@@ -192,6 +193,34 @@ func (g *Gateway) injectHTTPFunctions(vm *otto.Otto, u *user.User) {
 		return otto.TrueValue()
 	})
 
+	vm.Set("_http_getb64", func(call otto.FunctionCall) otto.Value {
+		//Get URL from function variable and return bytes as base64
+		url, err := call.Argument(0).ToString()
+		if err != nil {
+			return otto.NullValue()
+		}
+
+		//Get respond of the url
+		res, err := http.Get(url)
+		if err != nil {
+			return otto.NullValue()
+		}
+
+		bodyContent, err := ioutil.ReadAll(res.Body)
+		if err != nil {
+			return otto.NullValue()
+		}
+
+		sEnc := base64.StdEncoding.EncodeToString(bodyContent)
+
+		r, err := otto.ToValue(string(sEnc))
+		if err != nil {
+			log.Println(err.Error())
+			return otto.NullValue()
+		}
+		return r
+	})
+
 	//Wrap all the native code function into an imagelib class
 	vm.Run(`
 		var http = {};
@@ -199,6 +228,7 @@ func (g *Gateway) injectHTTPFunctions(vm *otto.Otto, u *user.User) {
 		http.post = _http_post;
 		http.head = _http_head;
 		http.download = _http_download;
+		http.getb64 = _http_getb64;
 	`)
 
 }

+ 11 - 1
web/SystemAO/desktop/shortcutCreator.html

@@ -126,6 +126,13 @@
                 <input id="urlShortcut" type="text" placeholder="Website URL">
                 <i class="globe icon"></i>
               </div>
+            <br>
+            <p>Enter the shortcut icon for desktop / floatWindow icon</p>
+            <div class="ui icon fluid input">
+                <input id="urlShortcutImage" type="text" placeholder="Shortcut Logo" value="">
+                <i class="image icon"></i>
+              </div>
+            <br>
             <br><br>
             <button class="ui primary button" onclick="createURLShortcut();">
                 Next
@@ -260,7 +267,10 @@
             }
             var urlchunk = url.split("/");
             var iconpath = urlchunk[0] + "//" + urlchunk[2] + "/favicon.ico";
-
+            if ($("#urlShortcutImage").val() != ""){
+                iconpath = $("#urlShortcutImage").val().trim();
+            }
+            
             generateShortcutFile("url",shortcutname, url, iconpath);
             $(".stageTwo").slideUp();
             $("#stepTwoState").addClass("completed");

+ 31 - 4
web/desktop.system

@@ -3256,6 +3256,16 @@
             if (properties.type == "file" && isChrome){
                 htmlType = "a";
             }
+
+            var imageStyleOverride = "";
+            //Special type of override for files
+            if (properties.type == "shortcut"){
+                var fd = JSON.parse(decodeURIComponent(properties.compressedFiledata));
+                if (fd.ShortcutType == "url"){
+                    imageStyleOverride = `padding: 8px;`;
+                }
+            }
+            
            
             var thisIcon = $(`<${htmlType} href="javascript:void(0);" class="launchIcon" 
                     type="${properties.type}" 
@@ -3271,7 +3281,7 @@
                     filedata="${properties.compressedFiledata}" 
                     style="width:${properties.iwidth}px; height:${properties.iheight}px;left:${properties.screenX}px; top:${properties.screenY}px;">
                     <span class="launchIconWrapper">
-                        <img class="launchIconImage ${properties.size}" src="${properties.imagePath}" draggable="false"></img>
+                        <img class="launchIconImage ${properties.size}" src="${properties.imagePath}" style="${imageStyleOverride}" draggable="false"></img>
                         <p class="launchIconText ${properties.size}">${properties.shortenedName}</p>
                     </span>
                     </${htmlType}>`);
@@ -4241,7 +4251,13 @@
                     openFolder(filedata.ShortcutPath)
                 }else if (stype == "url"){
                     //Open the target webpage in a new tab
-                    window.open(filedata.ShortcutPath);
+                    newFloatWindow({
+                        url: filedata.ShortcutPath,
+                        appicon: filedata.ShortcutImage,
+                        title: filedata.ShortcutName,
+                        parent: filedata.ShortcutPath
+                    })
+                    //window.open(filedata.ShortcutPath);
                 }else{
                     console.log(filedata);
                 }
@@ -6234,8 +6250,19 @@
         function openSelectedFloatWindowInNewTab(){
             var fw = getFocusedFloatWindow();
             if (fw != undefined){
-                var currentURL = $(fw).find("iframe")[0].contentWindow.location;
-                window.open(currentURL);
+                try{
+                    var currentURL = $(fw).find("iframe")[0].contentWindow.location;
+                    window.open(currentURL);
+                }catch(ex){
+                    //Maybe CORS. Try to get it from window's parent properties
+                    let parentURL = $(fw).attr("parent");
+                    if (parentURL != undefined){
+                        window.open(parentURL);
+                    }else{
+                        console.log("Unable to access iframe object")
+                    }
+                }
+               
             }
             hideAllContextMenus();
         }