)
     app.logger.setLevel(logging.INFO)
 
+VAPID_PUBLIC_KEY = ""
+_vapid_key_path = datadir.get_vapid_public_key_path()
+if _vapid_key_path.exists():
+    with open(_vapid_key_path, "r") as f:
+        VAPID_PUBLIC_KEY = f.read().strip()
+
 @app.route("/")
 def index():
     all_users = db.query("select * from users order by username asc")
         gif_data=get_gif_data(),
         # Add to Playlist dropdown entries
         current_user_playlists=get_current_user_playlists(),
+        vapid_public_key=VAPID_PUBLIC_KEY,
         **colors.DEFAULT_COLORS,
     )
 
 
 def get_app_log_path():
     return _data_dir / "app.log"
 
+def get_vapid_public_key_path():
+    return _data_dir / "vapid-public.key"
+
 def get_vapid_private_key_path():
     return _data_dir / "vapid-private.key"
 
 
 
                     sent_notifications += 1
                 except pywebpush.WebPushException as ex:
-                    if ex.response.status_code == 410:  # Subscription deleted
-                        app.logger.warning(f"Deleting dead push subscription: {subid}")
-                        db.query("DELETE FROM users_push_subscriptions WHERE subid = ?", [subid])
-                        db.commit()
-                    else:
-                        app.logger.error(f"Failed to send push: {ex}")
+                    # Failed to send notification, delete this subscription
+                    app.logger.warning(f"Deleting dead push subscription: {subid} - {ex}")
+                    db.query("DELETE FROM users_push_subscriptions WHERE subid = ?", [subid])
+                    db.commit()
 
         if sent_notifications > 0:
             app.logger.info(f"Pushed {sent_notifications} notifications")
 
             if (!existingSubscription || !window.localStorage.getItem("subid"))
             {
                 // Subscribe via browser's push service
-                const vapid_public_key = "BLsO37LostwqKch7SFr5Df0MexEoBOcujdMRY7wJurRPc_MGdz9rAkMrqs_dil4qSFxVbVyAA3FqLEPSL-WRNZs";
+                const vapid_public_key = "{{ vapid_public_key }}";
                 const options = {userVisibleOnly: true, applicationServerKey: vapid_public_key};
                 const subscription = await registration.pushManager.subscribe(options);
                 console.log(JSON.stringify(subscription));
 
 
 {% block body %}
 
-<button onclick="requestNotificationPermission()" class="button">Enable Notifications</button>
-
 <h2 class="mt0">hello!</h2>
 <div style="display: flex; flex-direction: row; justify-content: center; gap: 10px; align-items: center;">
 <div>🎶</div>