whimsical-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ru...@apache.org
Subject [whimsy] branch master updated: wire up install button
Date Sun, 10 Jun 2018 13:59:07 GMT
This is an automated email from the ASF dual-hosted git repository.

rubys pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/whimsy.git


The following commit(s) were added to refs/heads/master by this push:
     new e517d0b  wire up install button
e517d0b is described below

commit e517d0b0a627f78ac681fc45f5745483a58747b5
Author: Sam Ruby <rubys@intertwingly.net>
AuthorDate: Sun Jun 10 09:58:31 2018 -0400

    wire up install button
---
 www/board/agenda/public/whimsy.png            | Bin 0 -> 11094 bytes
 www/board/agenda/routes.rb                    |   1 +
 www/board/agenda/views/app.js.rb              |   1 +
 www/board/agenda/views/buttons/install.js.rb  |  15 +++++++++++++++
 www/board/agenda/views/manifest.json.erb      |  12 +++++++++++-
 www/board/agenda/views/models/pagecache.js.rb |  16 ++++++++++++++++
 www/board/agenda/views/router.js.rb           |   3 +++
 7 files changed, 47 insertions(+), 1 deletion(-)

diff --git a/www/board/agenda/public/whimsy.png b/www/board/agenda/public/whimsy.png
new file mode 100644
index 0000000..feedfe8
Binary files /dev/null and b/www/board/agenda/public/whimsy.png differ
diff --git a/www/board/agenda/routes.rb b/www/board/agenda/routes.rb
index bd8b91b..f0c8195 100755
--- a/www/board/agenda/routes.rb
+++ b/www/board/agenda/routes.rb
@@ -27,6 +27,7 @@ end
 # Progress Web App Manfest
 get '/manifest.json' do
   @svgmtime = File.mtime(File.expand_path('../../../whimsy.svg', __FILE__)).to_i
+  @pngmtime = File.mtime(File.expand_path('../public/whimsy.png', __FILE__)).to_i
 
   # capture all the variable content
   hash = {
diff --git a/www/board/agenda/views/app.js.rb b/www/board/agenda/views/app.js.rb
index 9d47574..41d5b82 100644
--- a/www/board/agenda/views/app.js.rb
+++ b/www/board/agenda/views/app.js.rb
@@ -54,6 +54,7 @@ require_relative 'buttons/summary'
 require_relative 'buttons/timestamp'
 require_relative 'buttons/vote'
 require_relative 'buttons/email'
+require_relative 'buttons/install'
 
 # Common elements
 require_relative 'elements/additional-info'
diff --git a/www/board/agenda/views/buttons/install.js.rb b/www/board/agenda/views/buttons/install.js.rb
new file mode 100644
index 0000000..21832dd
--- /dev/null
+++ b/www/board/agenda/views/buttons/install.js.rb
@@ -0,0 +1,15 @@
+#
+# Progressive Web Application 'Add to Home Screen' support
+#
+class Install < Vue
+  def render
+    _button.btn.btn_primary 'install', onClick: self.click
+  end
+
+  def click(event)
+    PageCache.installprompt.userChoice.then do |result|
+      console.log "install: #{result}"
+      PageCache.installprompt = nil
+    end
+  end
+end
diff --git a/www/board/agenda/views/manifest.json.erb b/www/board/agenda/views/manifest.json.erb
index b3f4bd7..865b406 100644
--- a/www/board/agenda/views/manifest.json.erb
+++ b/www/board/agenda/views/manifest.json.erb
@@ -3,9 +3,19 @@
   "name": "ASF Board Agenda",
   "icons": [
     {
+      "src": "/whimsy.png?<%= @pngmtime %>",
+      "type": "image/png",
+      "sizes": "144x144"
+    },
+    {
+      "src": "/whimsy.svg?<%= @svgmtime %>",
+      "type": "image/svg+xml",
+      "sizes": "192x192"
+    },
+    {
       "src": "/whimsy.svg?<%= @svgmtime %>",
       "type": "image/svg+xml",
-      "sizes": "120x84"
+      "sizes": "512x512"
     }
   ],
   "start_url": "/latest/",
diff --git a/www/board/agenda/views/models/pagecache.js.rb b/www/board/agenda/views/models/pagecache.js.rb
index df20dc8..813c3c2 100644
--- a/www/board/agenda/views/models/pagecache.js.rb
+++ b/www/board/agenda/views/models/pagecache.js.rb
@@ -8,6 +8,7 @@
 #
 
 class PageCache
+  Vue.util.defineReactive @@installPrompt, nil
 
   # is page cache available?
   def self.enabled
@@ -64,6 +65,7 @@ class PageCache
       end
     end
 
+    # fetch bootstrap from server, and update latest once it is received
     if Main.item == Agenda and Main.latest
       fetch('bootstrap.html').then do |response|
         response.text().then do |body|
@@ -72,6 +74,11 @@ class PageCache
       end
     end
 
+    window.addEventListener :beforeinstallprompt do |event|
+      @@installprompt = event
+      event.preventDefault();
+    end
+
     self.cleanup(scope.toString(), Server.agendas)
   end
 
@@ -114,4 +121,13 @@ class PageCache
       window.location.href = "../#{date}/"
     end
   end
+
+  # install prompt support
+  def self.installprompt
+    @@installprompt
+  end
+
+  def self.installprompt=(value)
+    @@installprompt == value
+  end
 end
diff --git a/www/board/agenda/views/router.js.rb b/www/board/agenda/views/router.js.rb
index 97c675e..a4af9d0 100644
--- a/www/board/agenda/views/router.js.rb
+++ b/www/board/agenda/views/router.js.rb
@@ -85,6 +85,9 @@ class Router
     elsif path == 'help'
       item = {view: Help}
 
+      # Progressive Web Application 'Add to Home Screen' support
+      item.buttons = [{button: Install}] if PageCache.installprompt
+
     elsif path == 'bootstrap.html'
       item = {view: BootStrapPage, title: ' '}
 

-- 
To stop receiving notification emails like this one, please contact
rubys@apache.org.

Mime
View raw message