diff --git a/addons/background.js b/addons/background.js deleted file mode 100644 index 0c92ddd..0000000 --- a/addons/background.js +++ /dev/null @@ -1,31 +0,0 @@ -var portFromCS; - -function connected(p) { - portFromCS = p; - portFromCS.postMessage({ message: "Initiate" }); - portFromCS.onDisconnect.addListener(disconnected); -} - -function disconnected() { - console.log("Not a local Tiddlywiki file"); -} - -function onResponse(response) { - sendResponse({ response: "Saved Successfully" }); - //console.log("Background script sends success response to content script") -} - -function onError(error) { - console.log(`Error: ${error}`); -} - -function handleMessage(request, sender, sendResponse) { - console.log("Sending native message"); - var sending = browser.runtime.sendNativeMessage( - "timimi", request); - sending.then(onResponse, onError); -} - - -browser.runtime.onConnect.addListener(connected); -browser.runtime.onMessage.addListener(handleMessage); diff --git a/addons/content-script.js b/addons/content-script.js deleted file mode 100644 index 92863ff..0000000 --- a/addons/content-script.js +++ /dev/null @@ -1,73 +0,0 @@ -var twport = browser.runtime.connect({ name: "port-from-cs" }); -var idGenerator = 1; - -// Checking if the active tab is a local tiddlywiki file -function checkTW() { - var results = {}; - // Test for TiddlyWiki Classic - var versionArea = document.getElementById("versionArea"); - results.isTiddlyWikiClassic = (document.location.protocol === "file:") && - document.getElementById("storeArea") && - (versionArea && /TiddlyWiki/.test(versionArea.textContent)); - // Test for TiddlyWiki 5 - var metaTags = document.getElementsByTagName("meta"); - for (var t = 0; t < metaTags.length; t++) { - if (metaTags[t].name === "application-name" && metaTags[t].content === "TiddlyWiki") { - results.isTiddlyWiki5 = true; - } - } - results.isTiddlyWiki = results.isTiddlyWikiClassic || results.isTiddlyWiki5; - // Test for file URI - if (document.location.protocol === "file:") { - results.isLocalFile = true; - } - return results; -} - -var checkTWResults = checkTW(); - - -if (checkTWResults.isTiddlyWiki5 && checkTWResults.isLocalFile) { - - var messageBox = document.getElementById("tiddlyfox-message-box"); - if (!messageBox) { - messageBox = document.createElement("div"); - messageBox.id = "tiddlyfox-message-box"; - messageBox.style.display = "none"; - document.body.appendChild(messageBox); - } - // Listen to initiate message from background script - twport.onMessage.addListener(function(m) { - console.log(m.message); - // Attach the event handler to the message box - messageBox.addEventListener("tiddlyfox-save-file", onSaveTiddlyWiki, false); - - function onSaveTiddlyWiki(event) { - // Get the details from the message - var messageElement = event.target, - path = messageElement.getAttribute("data-tiddlyfox-path"), - content = messageElement.getAttribute("data-tiddlyfox-content"), - backupPath = messageElement.getAttribute("data-tiddlyfox-backup-path"), - messageId = "tiddlywiki-save-file-response-" + idGenerator++; - // Send the details to background script. Not using port because we need a promise and port.postMessage is not a promise - var sending = browser.runtime.sendMessage({ path: path, messageId: messageId, content: content, backupPath: backupPath }); - sending.then(handleResponse, handleError); - - function handleResponse(message) { - messageElement.parentNode.removeChild(messageElement); - console.log("Saved successfully to " + path); - console.log("Message ID is " + messageId); - var event = document.createEvent("Events"); - event.initEvent("tiddlyfox-have-saved-file", true, false); - event.savedFilePath = path; - messageElement.dispatchEvent(event); - } - - function handleError() { - console.log(`Error: ${error}`); - } - } - }); -} else { - twport.disconnect(); -} \ No newline at end of file diff --git a/chrome-chromium b/chrome-chromium new file mode 160000 index 0000000..9e0a6a7 --- /dev/null +++ b/chrome-chromium @@ -0,0 +1 @@ +Subproject commit 9e0a6a77b394eed84b3d47439c366531fb3973eb diff --git a/addons/.web-extension-id b/firefox/addons/.web-extension-id similarity index 100% rename from addons/.web-extension-id rename to firefox/addons/.web-extension-id diff --git a/firefox/addons/background.js b/firefox/addons/background.js new file mode 100644 index 0000000..524b968 --- /dev/null +++ b/firefox/addons/background.js @@ -0,0 +1,9 @@ + +function handleMessage(request, sender, sendResponse) { + console.log("Sending native message"); + browser.runtime.sendNativeMessage( + "timimi", request); +} + + +browser.runtime.onMessage.addListener(handleMessage); diff --git a/firefox/addons/content-script.js b/firefox/addons/content-script.js new file mode 100644 index 0000000..eb397bd --- /dev/null +++ b/firefox/addons/content-script.js @@ -0,0 +1,71 @@ +//var twport = browser.runtime.connect({ name: "port-from-cs" }); +var idGenerator = 1; + +// Checking if the active tab is a local tiddlywiki file +function checkTW() { + var results = {}; + // Test for TiddlyWiki Classic + var versionArea = document.getElementById("versionArea"); + results.isTiddlyWikiClassic = (document.location.protocol === "file:") && + document.getElementById("storeArea") && + (versionArea && /TiddlyWiki/.test(versionArea.textContent)); + // Test for TiddlyWiki 5 + var metaTags = document.getElementsByTagName("meta"); + for (var t = 0; t < metaTags.length; t++) { + if (metaTags[t].name === "application-name" && metaTags[t].content === "TiddlyWiki") { + results.isTiddlyWiki5 = true; + } + } + results.isTiddlyWiki = results.isTiddlyWikiClassic || results.isTiddlyWiki5; + // Test for file URI + if (document.location.protocol === "file:") { + results.isLocalFile = true; + } + return results; +} + +var checkTWResults = checkTW(); + + +if (checkTWResults.isTiddlyWiki5 && checkTWResults.isLocalFile) { + + var messageBox = document.getElementById("tiddlyfox-message-box"); + if (!messageBox) { + messageBox = document.createElement("div"); + messageBox.id = "tiddlyfox-message-box"; + messageBox.style.display = "none"; + document.body.appendChild(messageBox); + } + // Listen to initiate message from background script + // Attach the event handler to the message box + messageBox.addEventListener("tiddlyfox-save-file", onSaveTiddlyWiki, false); + + function onSaveTiddlyWiki(event) { + // Get the details from the message + var messageElement = event.target, + path = messageElement.getAttribute("data-tiddlyfox-path"), + content = messageElement.getAttribute("data-tiddlyfox-content"), + backupPath = messageElement.getAttribute("data-tiddlyfox-backup-path"), + messageId = "tiddlywiki-save-file-response-" + idGenerator++; + // Send the details to background script. Not using port because we need a promise and port.postMessage is not a promise + var sending = browser.runtime.sendMessage({ path: path, messageId: messageId, content: content, backupPath: backupPath }); + sending.then(handleResponse, handleError); + + function handleResponse(message) { + messageElement.parentNode.removeChild(messageElement); + console.log("Saved successfully to " + path); + console.log("Message ID is " + messageId); + var event = document.createEvent("Events"); + event.initEvent("tiddlyfox-have-saved-file", true, false); + event.savedFilePath = path; + messageElement.dispatchEvent(event); + } + + function handleError() { + console.log(`Error: ${error}`); + } + } + +} else { + twport.disconnect(); +} \ No newline at end of file diff --git a/addons/icons/Credits.html b/firefox/addons/icons/Credits.html similarity index 100% rename from addons/icons/Credits.html rename to firefox/addons/icons/Credits.html diff --git a/addons/icons/index.svg b/firefox/addons/icons/index.svg similarity index 100% rename from addons/icons/index.svg rename to firefox/addons/icons/index.svg diff --git a/addons/manifest.json b/firefox/addons/manifest.json similarity index 100% rename from addons/manifest.json rename to firefox/addons/manifest.json diff --git a/addons/web-ext-artifacts/timimi-1.3-an+fx.xpi b/firefox/addons/web-ext-artifacts/timimi-1.3-an+fx.xpi similarity index 100% rename from addons/web-ext-artifacts/timimi-1.3-an+fx.xpi rename to firefox/addons/web-ext-artifacts/timimi-1.3-an+fx.xpi diff --git a/native-messaging-hosts/timimi.json b/firefox/native-messaging-hosts/timimi.json similarity index 100% rename from native-messaging-hosts/timimi.json rename to firefox/native-messaging-hosts/timimi.json diff --git a/native-messaging-hosts/timimi.py b/firefox/native-messaging-hosts/timimi.py similarity index 100% rename from native-messaging-hosts/timimi.py rename to firefox/native-messaging-hosts/timimi.py diff --git a/installScripts/linux.sh b/installScripts/linux.sh index 9fb3244..90796f5 100644 --- a/installScripts/linux.sh +++ b/installScripts/linux.sh @@ -1,4 +1,4 @@ git clone --depth=1 https://github.com/ibnishak/Timimi.git -cp -r Timimi/native-messaging-hosts $HOME/.mozilla +cp -r Timimi/firefox/native-messaging-hosts $HOME/.mozilla sed -ie "s/richie/$USER/" $HOME/.mozilla/native-messaging-hosts/timimi.json -cp Timimi/addons/web-ext-artifacts/timimi-1.3-an+fx.xpi $HOME \ No newline at end of file +cp Timimi/addons/web-ext-artifacts/timimi-1.3-an+fx.xpi $HOME