Skip to content

Commit

Permalink
Merge branch 'refs/heads/main' into prod/festapp
Browse files Browse the repository at this point in the history
# Conflicts:
#	web/index.html
  • Loading branch information
miakh committed Aug 2, 2024
2 parents 1f55501 + f0c73cd commit 80c53fd
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 46 deletions.
9 changes: 9 additions & 0 deletions lib/appConfig.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:fstapp/dataModels/LanguageModel.dart';

Expand All @@ -11,6 +12,7 @@ class AppConfig {
static const bool isOwnProgramSupportedWithoutSignIn = true;
static const bool isOwnProgramSupported = true;
static const bool isNotificationsSupported = true;
static const bool isWebNotificationsSupported = true;
static const bool isUsersImportSupported = true;
static const String oneSignalAppId = '73f77f22-961a-4ded-9647-e33a7ac14f90';
static const String defaultLink = "conference2024";
Expand Down Expand Up @@ -56,6 +58,13 @@ class AppConfig {

static const int offsetHours = -1;

static bool isNotificationsCurrentlySupported() {
if(kIsWeb) {
return isNotificationsSupported && isWebNotificationsSupported;
}
return isNotificationsSupported;
}

static Color eventTypeToColor(String? type)
{
switch (type){
Expand Down
69 changes: 35 additions & 34 deletions lib/pages/SettingsPage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -107,41 +107,42 @@ class _SettingsPageState extends State<SettingsPage> {
),
const SizedBox(height: 24),
],
const Text("Notification Settings", style: TextStyle(fontSize: 20)).tr(),
const SizedBox(height: 16),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
const Text("Enable Notifications", style: TextStyle(fontSize: 16)).tr(),
Switch(
value: _notificationsEnabled,
onChanged: (value) async {
bool success;
if (value) {
success = await NotificationHelper.turnNotificationOn();
} else {
await NotificationHelper.turnNotificationOff();
success = true;
}
if (!success) {
setState(() {
_notificationError = true;
});
}
await loadSettings();
},
),
],
),
if (_notificationError)
Padding(
padding: const EdgeInsets.only(top: 8.0),
child: const Text(
"Failed to enable notifications.",
style: TextStyle(color: Colors.red),
textAlign: TextAlign.center,
).tr(),
if (AppConfig.isNotificationsCurrentlySupported()) ...[
const Text("Notification Settings", style: TextStyle(fontSize: 20)).tr(),
const SizedBox(height: 16),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
const Text("Enable Notifications", style: TextStyle(fontSize: 16)).tr(),
Switch(
value: _notificationsEnabled,
onChanged: (value) async {
bool success;
if (value) {
success = await NotificationHelper.turnNotificationOn();
} else {
await NotificationHelper.turnNotificationOff();
success = true;
}
if (!success) {
setState(() {
_notificationError = true;
});
}
await loadSettings();
},
),
],
),
if (_notificationError)
Padding(
padding: const EdgeInsets.only(top: 8.0),
child: const Text(
"Failed to enable notifications.",
style: TextStyle(color: Colors.red),
textAlign: TextAlign.center,
).tr(),
),],
const SizedBox(height: 24),
Center(
child: Column(
Expand Down
4 changes: 2 additions & 2 deletions lib/services/DialogHelper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -284,14 +284,14 @@ class DialogHelper{
),
actions: <Widget>[
TextButton(
child: Text("Don\'t Allow").tr(),
child: Text("Disable").tr(),
onPressed: () {
result = false;
Navigator.of(context).pop();
},
),
ElevatedButton(
child: Text("Allow").tr(),
child: Text("Enable").tr(),
onPressed: () async {
result = true;
Navigator.of(context).pop();
Expand Down
10 changes: 5 additions & 5 deletions lib/services/NotificationHelper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class NotificationHelper {
}

static Future<void> initialize() async {
if (!AppConfig.isNotificationsSupported) {
if (!AppConfig.isNotificationsCurrentlySupported()) {
return;
}

Expand All @@ -64,8 +64,8 @@ class NotificationHelper {
await NotificationHelper.login();
}

static Future<void> checkForNotificationPermission(BuildContext context, [bool forceIsPWA = false]) async {
if (!DataService.isPwaInstalledOrNative() && !forceIsPWA) {
static Future<void> checkForNotificationPermission(BuildContext context, [bool forceAsk = false]) async {
if (!DataService.isPwaInstalledOrNative() && !forceAsk) {
return;
}
var allowed = getNotificationPermission();
Expand Down Expand Up @@ -120,7 +120,7 @@ class NotificationHelper {
}

static Future<void> login() async {
if (!AppConfig.isNotificationsSupported || !getNotificationPermission() || !DataService.isLoggedIn()) {
if (!AppConfig.isNotificationsCurrentlySupported() || !getNotificationPermission() || !DataService.isLoggedIn()) {
return;
}

Expand All @@ -133,7 +133,7 @@ class NotificationHelper {
}

static Future<void> logout() async {
if (!AppConfig.isNotificationsSupported || !DataService.isLoggedIn()) {
if (!AppConfig.isNotificationsCurrentlySupported() || !DataService.isLoggedIn()) {
return;
}
if (kIsWeb) {
Expand Down
18 changes: 17 additions & 1 deletion web/OneSignalSDKWorker.js
Original file line number Diff line number Diff line change
@@ -1 +1,17 @@
importScripts("https://cdn.onesignal.com/sdks/web/v16/OneSignalSDK.sw.js");
importScripts('https://storage.googleapis.com/workbox-cdn/releases/5.1.2/workbox-sw.js');
importScripts("https://cdn.onesignal.com/sdks/web/v16/OneSignalSDK.sw.js");

const CACHE = "pwabuilder-offline";

self.addEventListener("message", (event) => {
if (event.data && event.data.type === "SKIP_WAITING") {
self.skipWaiting();
}
});

workbox.routing.registerRoute(
new RegExp('/*'),
new workbox.strategies.StaleWhileRevalidate({
cacheName: CACHE
})
);
16 changes: 12 additions & 4 deletions web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,18 @@
<meta name="theme-color" content="#ffffff">

<title>Festapp</title>
<script src="./OneSignalSDK.page.js" defer></script>
<script>
if (typeof navigator.serviceWorker !== 'undefined') {
navigator.serviceWorker.register('OneSignalSDKWorker.js?v=2')
.then(function(registration) {
console.log('Service Worker registered with scope:', registration.scope);
})
.catch(function(error) {
console.error('Service Worker registration failed:', error);
});
}
</script>
<script src="https://cdn.onesignal.com/sdks/web/v16/OneSignalSDK.page.js" defer></script>
<script>
window.OneSignalDeferred = window.OneSignalDeferred || [];

Expand Down Expand Up @@ -175,9 +186,6 @@
}
</script>

<script>
var serviceWorkerVersion = "{{flutter_service_worker_version}}";
</script>
<script src="flutter_bootstrap.js" async></script>

<style>
Expand Down

0 comments on commit 80c53fd

Please sign in to comment.