From 12044c6ea6bc8b1636d595d3216741fa539a5274 Mon Sep 17 00:00:00 2001 From: Nirmal Kumar R Date: Sun, 31 May 2026 00:43:24 +0530 Subject: [PATCH] feat: Add service worker for offline install --- index.html | 2 +- manifest.json | 15 +++++++++++++++ src/index.html | 9 +++++++++ sw.js | 21 +++++++++++++++++++++ 4 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 manifest.json create mode 100644 sw.js diff --git a/index.html b/index.html index 224ec56..b989e86 100644 --- a/index.html +++ b/index.html @@ -1 +1 @@ -Untitled - Pascar
Pascar
Dialog
Pascar - Keyboard Shortcuts
Menu Navigation
Alt+FOpen File menu
Alt+EOpen Edit menu
Alt+SOpen Search menu
Alt+VOpen View menu
Alt+HOpen Help menu
↑ / ↓Move through menu items
← / →Switch between menus
EnterActivate highlighted item
Letter keyActivate underlined shortcut
EscapeClose menu
File Operations
Ctrl+NNew file
Ctrl+OOpen file from disk
Ctrl+SSave / download file
Ctrl+Shift+SSave As...
Ctrl+PPrint
Editing
Ctrl+ZUndo
Ctrl+YRedo
Ctrl+XCut
Ctrl+CCopy
Ctrl+VPaste
Ctrl+ASelect All
DelDelete selection
F5Insert date/time
InsertToggle Insert/Overwrite
TabIndent (4 spaces)
Shift+TabUnindent
Search
Ctrl+FFind...
Ctrl+HFind & Replace...
F3Find Next
Shift+F3Find Previous
Ctrl+GGo to Line...
View
Alt+WToggle Word Wrap
Alt+LToggle Line Numbers
Ctrl++Zoom In
Ctrl+-Zoom Out
Ctrl+0Reset Zoom
Navigation
Ctrl+HomeBeginning of file
Ctrl+EndEnd of file
Ctrl+Left/RightMove word by word
Home / EndStart / end of line
Page Up / DownScroll one page
General
F1Show this help screen
EscapeClose menus / dialogs
Alt+F4Exit (close tab)
Press Escape or F1 to close this screen
Find:
Go to line:
Untitled UTF-8
Words: 0 Chars: 0 Ln 1, Col 1 INS
\ No newline at end of file +Untitled - Pascar
Pascar
Dialog
Pascar - Keyboard Shortcuts
Menu Navigation
Alt+FOpen File menu
Alt+EOpen Edit menu
Alt+SOpen Search menu
Alt+VOpen View menu
Alt+HOpen Help menu
↑ / ↓Move through menu items
← / →Switch between menus
EnterActivate highlighted item
Letter keyActivate underlined shortcut
EscapeClose menu
File Operations
Ctrl+NNew file
Ctrl+OOpen file from disk
Ctrl+SSave / download file
Ctrl+Shift+SSave As...
Ctrl+PPrint
Editing
Ctrl+ZUndo
Ctrl+YRedo
Ctrl+XCut
Ctrl+CCopy
Ctrl+VPaste
Ctrl+ASelect All
DelDelete selection
F5Insert date/time
InsertToggle Insert/Overwrite
TabIndent (4 spaces)
Shift+TabUnindent
Search
Ctrl+FFind...
Ctrl+HFind & Replace...
F3Find Next
Shift+F3Find Previous
Ctrl+GGo to Line...
View
Alt+WToggle Word Wrap
Alt+LToggle Line Numbers
Ctrl++Zoom In
Ctrl+-Zoom Out
Ctrl+0Reset Zoom
Navigation
Ctrl+HomeBeginning of file
Ctrl+EndEnd of file
Ctrl+Left/RightMove word by word
Home / EndStart / end of line
Page Up / DownScroll one page
General
F1Show this help screen
EscapeClose menus / dialogs
Alt+F4Exit (close tab)
Press Escape or F1 to close this screen
Find:
Go to line:
Untitled UTF-8
Words: 0 Chars: 0 Ln 1, Col 1 INS
\ No newline at end of file diff --git a/manifest.json b/manifest.json new file mode 100644 index 0000000..051e4d9 --- /dev/null +++ b/manifest.json @@ -0,0 +1,15 @@ +{ + "name": "Pascar Text Editor", + "short_name": "Pascar", + "start_url": "index.html", + "display": "standalone", + "background_color": "#1c1c1c", + "theme_color": "#295991", + "icons": [ + { + "src": "icon-192.png", + "sizes": "192x192", + "type": "image/png" + } + ] +} \ No newline at end of file diff --git a/src/index.html b/src/index.html index 2d46b62..b97709e 100644 --- a/src/index.html +++ b/src/index.html @@ -1324,6 +1324,15 @@ e.returnValue = ''; } }); + + // -- Service Worker to make this application work offline + if ('serviceWorker' in navigator) { + window.addEventListener('load', () => { + navigator.serviceWorker.register('sw.js') + .then(reg => console.log('Service Worker Registered')) + .catch(err => console.log('Registration Failed', err)); + }); + } })(); diff --git a/sw.js b/sw.js new file mode 100644 index 0000000..e23f278 --- /dev/null +++ b/sw.js @@ -0,0 +1,21 @@ +const CACHE_NAME = 'pascar'; +const ASSETS = [ + 'index.html', + 'manifest.json' +]; + +// Install: Cache the files +self.addEventListener('install', (e) => { + e.waitUntil( + caches.open(CACHE_NAME).then((cache) => cache.addAll(ASSETS)) + ); +}); + +// Fetch: Serve from cache if offline +self.addEventListener('fetch', (e) => { + e.respondWith( + caches.match(e.request).then((response) => { + return response || fetch(e.request); + }) + ); +}); \ No newline at end of file