about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorelioat <elioat@tilde.institute>2024-01-15 21:15:17 -0500
committerelioat <elioat@tilde.institute>2024-01-15 21:15:17 -0500
commite71fd1a14ed539b7c8d328e5df13df65ae939189 (patch)
treed1226cfdba61a7e0fc7ee4f3191ae65d93dc7531
parent12723d963540e99bb60197042e705260e01882ce (diff)
downloadtour-e71fd1a14ed539b7c8d328e5df13df65ae939189.tar.gz
*
-rw-r--r--js/inknswitch/ink.js68
-rw-r--r--js/inknswitch/sw.js15
2 files changed, 40 insertions, 43 deletions
diff --git a/js/inknswitch/ink.js b/js/inknswitch/ink.js
index dbfa0e4..3ac1892 100644
--- a/js/inknswitch/ink.js
+++ b/js/inknswitch/ink.js
@@ -1,12 +1,12 @@
 if ('serviceWorker' in navigator) {
     navigator.serviceWorker.register('./sw.js')
     .then(function(registration) {
-      console.log('Service Worker registered with scope:', registration.scope);
+        console.log('Service Worker registered with scope:', registration.scope);
     })
     .catch(function(err) {
-      console.log('Service Worker registration failed:', err);
+        console.error('Service Worker registration failed:', err);
     });
-  }
+}
 
 document.getElementById('noteArea').focus(); // ensures that textarea is focused when the page loads
 
@@ -125,6 +125,25 @@ if (savedImage) {
     img.src = savedImage;
 }
 
+const saveCanvasAsImage = () => {
+    const confirmDownload = confirm('Do you really want to save the canvas as an image?');
+    if (confirmDownload) {
+        const dataUrl = canvas.toDataURL();
+        const a = document.createElement('a');
+        a.href = dataUrl;
+        a.download = 'canvas.png';
+        a.click();
+    }
+}
+
+const clearCanvas = () => {
+    const confirmClear = confirm('Do you really want to clear the canvas?');
+    if (confirmClear) {
+        ctx.clearRect(0, 0, canvas.width, canvas.height);
+        localStorage.removeItem('canvasImage');
+    }
+}
+
 // Toggle between drawing and note mode
 const toggle = () => {
     if (canvas.style.pointerEvents === 'none') {
@@ -155,37 +174,11 @@ toggleButton.addEventListener('click', toggle);
 
 const helpText = "This is a modal note taking tool. With it, you can type text that'll be saved to the browser, and you can draw pictures that'll also be saved to the browser. You are in typing mode right now. To toggle between modes tap either cmd + d, ctrl + d or cmd + 1, or ctrl + 1. When in drawing mode, tap c to clear the canvas, tap s to save the contents of the canvas to a png."
 
-// Currently unused
-// const saveTextAsFile() => {
-//     const textToWrite = document.getElementById('noteArea').value;
-//     const textFileAsBlob = new Blob([textToWrite], { type: 'text/plain' });
-//     const fileNameToSaveAs = 'notes.txt';
-
-//     const downloadLink = document.createElement('a');
-//     downloadLink.download = fileNameToSaveAs;
-//     downloadLink.href = window.URL.createObjectURL(textFileAsBlob);
-//     downloadLink.style.display = 'none';
-//     document.body.appendChild(downloadLink);
-//     downloadLink.click();
-//     document.body.removeChild(downloadLink);
-// }
-
 const handleSelectChange = () => {
     if (selectElement.value === 'clear') {
-        const confirmClear = confirm('Do you really want to clear the canvas?');
-        if (confirmClear) {
-            ctx.clearRect(0, 0, canvas.width, canvas.height);
-            localStorage.removeItem('canvasImage');
-        }
+        clearCanvas();
     } else if (selectElement.value === 'save') {
-        const confirmDownload = confirm('Do you really want to save the canvas as an image?');
-        if (confirmDownload) {
-            const dataUrl = canvas.toDataURL();
-            const a = document.createElement('a');
-            a.href = dataUrl;
-            a.download = 'canvas.png';
-            a.click();
-        }
+        saveCanvasAsImage();
     } else if (selectElement.value === 'help') {
         alert(helpText);
     }
@@ -206,23 +199,16 @@ const handleKeyDown = (e) => {
 
     // C key to clear the canvas
     if (e.key === 'c' && canvas.style.pointerEvents === 'auto') {
-        const confirmClear = confirm('Do you really want to clear the canvas?');
-        if (confirmClear) {
-            ctx.clearRect(0, 0, canvas.width, canvas.height);
-            localStorage.removeItem('canvasImage');
-        }
+        clearCanvas();
     }
 
     // S key to save the canvas as an image
     if (e.key === 's' && canvas.style.pointerEvents === 'auto') {
-        const dataUrl = canvas.toDataURL();
-        const a = document.createElement('a');
-        a.href = dataUrl;
-        a.download = 'canvas.png';
-        a.click();
+        saveCanvasAsImage();
     }
 
     localStorage.setItem('noteContent', noteArea.value);
 };
 
 document.addEventListener('keydown', handleKeyDown);
+
diff --git a/js/inknswitch/sw.js b/js/inknswitch/sw.js
index 81e6bf4..4a63871 100644
--- a/js/inknswitch/sw.js
+++ b/js/inknswitch/sw.js
@@ -4,12 +4,23 @@ self.addEventListener('install', function(event) {
         return cache.addAll([
           './index.html',
           './ink.js',
-          './icon.png',
           './android-icon-36x36.png',
           './android-icon-48x48.png',
           './android-icon-72x72.png',
           './android-icon-96x96.png',
-          './android-icon-144x144.png'
+          './android-icon-144x144.png',
+          './android-icon-192x192.png',
+          './apple-icon-57x57.png',
+          './apple-icon-60x60.png',
+          './apple-icon-72x72.png',
+          './apple-icon-76x76.png',
+          './apple-icon-114x114.png',
+          './apple-icon-120x120.png',
+          './apple-icon-144x144.png',
+          './apple-icon-152x152.png',
+          './apple-icon-180x180.png',
+          './apple-icon-precomposed.png',
+          './apple-icon.png',
         ]);
       })
     );