From bade69ec793bfe5df1d4a6184f0727c8f567bcff Mon Sep 17 00:00:00 2001 From: Les De Ridder Date: Sat, 20 May 2017 04:23:38 +0200 Subject: [PATCH] Implement mounting --- background.js | 52 ++++++++++++++++ manifest.json | 24 +++++++ mount-info.html | 27 ++++++++ mount-info.js | 11 ++++ sakura.css | 162 ++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 276 insertions(+) create mode 100644 background.js create mode 100644 manifest.json create mode 100644 mount-info.html create mode 100644 mount-info.js create mode 100644 sakura.css diff --git a/background.js b/background.js new file mode 100644 index 0000000..3a21662 --- /dev/null +++ b/background.js @@ -0,0 +1,52 @@ +'use strict'; + +function onMountRequested(onSuccess, onError) { + console.log("mount requested"); + getMountInfo(function(mountInfo) { mount(mountInfo, onSuccess, onError); }); +} + + +function getMountInfo(callback) { + let windowCallback = function(appWindow) { + let listener = function(message) { + if(message.senderId == appWindow.id) { + callback(message.mountInfo); + } else { + console.log(message); + console.log(appWindow); + console.log(message.senderId); + console.log(appWindow.id); + } + chrome.runtime.onMessage.removeListener(listener); + }; + chrome.runtime.onMessage.addListener(listener); + }; + + let windowOptions = { outerBounds : { width: 800, height: 600 }, resizable : false, id: Date.now().toString() }; + chrome.app.window.create("mount-info.html", windowOptions, windowCallback); +} + +function mount(mountInfo, onSuccess, onError) { + console.log("mount()"); + let request = new XMLHttpRequest(); + request.open("GET", mountInfo.url, true); + request.onreadystatechange = function() { + if(request.readyState != XMLHttpRequest.DONE) return; + try { + JSON.parse(request.responseText); + + let options = { fileSystemId: mountInfo.url, displayName: mountInfo.name, writable: false }; + chrome.fileSystemProvider.mount(options); + + console.log("mount succeeded"); + onSuccess(); + } catch(exception) { + console.log(exception); + console.log("mount failed"); + onError(); + } + }; + request.send(); +} + +chrome.fileSystemProvider.onMountRequested.addListener(onMountRequested); diff --git a/manifest.json b/manifest.json new file mode 100644 index 0000000..32bbd37 --- /dev/null +++ b/manifest.json @@ -0,0 +1,24 @@ +{ + "name": "Nginx JSON autoindex File System Provider", + "version": "0.0.1", + "manifest_version": 2, + "description": + "Mount an nginx JSON autoindex URL as a file system", + "permissions": [ + "fileSystemProvider", + "http://*/", + "https://*/" + ], + "file_system_provider_capabilities": { + "source": "network", + "multiple_mounts": true + }, + "app" : { + "background": { + "scripts": [ + "background.js", + "mount-info.js" + ] + } + } +} diff --git a/mount-info.html b/mount-info.html new file mode 100644 index 0000000..4be6a35 --- /dev/null +++ b/mount-info.html @@ -0,0 +1,27 @@ + + + + +Nginx JSON autoindex Mount Info + + + +

Mount options

+ +
+ + + +
+ + + + +
+ + +
+ + + + diff --git a/mount-info.js b/mount-info.js new file mode 100644 index 0000000..1490011 --- /dev/null +++ b/mount-info.js @@ -0,0 +1,11 @@ +"use strict"; + +(function() { + window.onload = function() { + document.getElementById("mount-info-form").onsubmit = function() { + let mountInfo = { name: document.getElementById("mount-name").value, url: document.getElementById("mount-url").value }; + chrome.runtime.sendMessage({ mountInfo: mountInfo, senderId: chrome.app.window.current().id}); + window.close(); + } + } +})(); diff --git a/sakura.css b/sakura.css new file mode 100644 index 0000000..aa19262 --- /dev/null +++ b/sakura.css @@ -0,0 +1,162 @@ +/* Sakura.css v1.0.0 + * ================ + * Minimal css theme. + * Project: https://github.com/oxalorg/sakura + */ +/* Body */ +html { + font-size: 62.5%; + font-family: serif; } + +body { + font-size: 1.8rem; + line-height: 1.618; + max-width: 38em; + margin: auto; + color: #4a4a4a; + background-color: #f9f9f9; + padding: 13px; } + +@media (max-width: 684px) { + body { + font-size: 1.53rem; } } + +@media (max-width: 382px) { + body { + font-size: 1.35rem; } } + +h1, h2, h3, h4, h5, h6 { + line-height: 1.1; + font-family: Verdana, Geneva, sans-serif; + font-weight: 700; + overflow-wrap: break-word; + word-wrap: break-word; + -ms-word-break: break-all; + word-break: break-word; + -ms-hyphens: auto; + -moz-hyphens: auto; + -webkit-hyphens: auto; + hyphens: auto; } + +h1 { + font-size: 2.35em; } + +h2 { + font-size: 2.00em; } + +h3 { + font-size: 1.75em; } + +h4 { + font-size: 1.5em; } + +h5 { + font-size: 1.25em; } + +h6 { + font-size: 1em; } + +small, sub, sup { + font-size: 75%; } + +hr { + border-color: #2c8898; } + +a { + text-decoration: none; + color: #2c8898; } + a:hover { + color: #982c61; + border-bottom: 2px solid #4a4a4a; } + +ul { + padding-left: 1.4em; } + +li { + margin-bottom: 0.4em; } + +blockquote { + font-style: italic; + margin-left: 1.5em; + padding-left: 1em; + border-left: 3px solid #2c8898; } + +img { + max-width: 100%; } + +/* Pre and Code */ +pre { + background-color: #f1f1f1; + display: block; + padding: 1em; + overflow-x: auto; } + +code { + font-size: 0.9em; + padding: 0 0.5em; + background-color: #f1f1f1; + white-space: pre-wrap; } + +pre > code { + padding: 0; + background-color: transparent; + white-space: pre; } + +/* Tables */ +table { + text-align: justify; + width: 100%; + border-collapse: collapse; } + +td, th { + padding: 0.5em; + border-bottom: 1px solid #f1f1f1; } + +/* Buttons, forms and input */ +input, textarea { + border: 1px solid #4a4a4a; } + input:focus, textarea:focus { + border: 1px solid #2c8898; } + +textarea { + width: 100%; } + +.button, button, input[type="submit"], input[type="reset"], input[type="button"] { + display: inline-block; + padding: 5px 10px; + text-align: center; + text-decoration: none; + white-space: nowrap; + background-color: #2c8898; + color: #f9f9f9; + border-radius: 1px; + border: 1px solid #2c8898; + cursor: pointer; + box-sizing: border-box; } + .button[disabled], button[disabled], input[type="submit"][disabled], input[type="reset"][disabled], input[type="button"][disabled] { + cursor: default; + opacity: .5; } + .button:focus, .button:hover, button:focus, button:hover, input[type="submit"]:focus, input[type="submit"]:hover, input[type="reset"]:focus, input[type="reset"]:hover, input[type="button"]:focus, input[type="button"]:hover { + background-color: #982c61; + border-color: #982c61; + color: #f9f9f9; + outline: 0; } + +textarea, select, input[type] { + color: #4a4a4a; + padding: 6px 10px; + /* The 6px vertically centers text on FF, ignored by Webkit */ + margin-bottom: 10px; + background-color: #f1f1f1; + border: 1px solid #f1f1f1; + border-radius: 4px; + box-shadow: none; + box-sizing: border-box; } + textarea:focus, select:focus, input[type]:focus { + border: 1px solid #2c8898; + outline: 0; } + +label, legend, fieldset { + display: block; + margin-bottom: .5rem; + font-weight: 600; }