Skip to content

Commit d53f835

Browse files
YuvalYuval
authored andcommitted
fixed android bug not connecting to local dev SQL
fixed notfication bug on android changing notfication radius to 100 fixing internal files for running local dev - latest changes pushing to azure production build
1 parent a432f99 commit d53f835

10 files changed

Lines changed: 75 additions & 16 deletions

File tree

01-Database/GroundShareDB.sql

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1271,17 +1271,51 @@ BEGIN
12711271
END
12721272
GO
12731273

1274-
-- Fetch every device token belonging to any user subscribed to the given location.
1274+
-- Fetch every device token belonging to any user subscribed to a location
1275+
-- within @RadiusMeters of the given location's coordinates (Haversine).
12751276
CREATE OR ALTER PROCEDURE sp_GetTokensForLocation
1276-
@Location_ID INT
1277+
@Location_ID INT,
1278+
@RadiusMeters INT = 100
12771279
AS
12781280
BEGIN
12791281
SET NOCOUNT ON;
1280-
SELECT dt.Token, dt.Platform, dt.User_ID
1282+
1283+
DECLARE @Lat FLOAT, @Lng FLOAT;
1284+
SELECT @Lat = Latitude, @Lng = Longitude
1285+
FROM location
1286+
WHERE Location_ID = @Location_ID;
1287+
1288+
-- Fall back to exact-match when the event location has no coordinates.
1289+
IF @Lat IS NULL OR @Lng IS NULL
1290+
BEGIN
1291+
SELECT dt.Token, dt.Platform, dt.User_ID
1292+
FROM device_token dt
1293+
INNER JOIN notification_subscription ns ON ns.User_ID = dt.User_ID
1294+
WHERE ns.Location_ID = @Location_ID;
1295+
RETURN;
1296+
END
1297+
1298+
-- Haversine argument clamped to [-1, 1] to avoid ACOS domain errors
1299+
-- when two points are identical (floating-point can yield 1.0000000001).
1300+
SELECT DISTINCT dt.Token, dt.Platform, dt.User_ID
12811301
FROM device_token dt
1282-
INNER JOIN notification_subscription ns
1283-
ON ns.User_ID = dt.User_ID
1284-
WHERE ns.Location_ID = @Location_ID;
1302+
INNER JOIN notification_subscription ns ON ns.User_ID = dt.User_ID
1303+
INNER JOIN location l ON l.Location_ID = ns.Location_ID
1304+
WHERE l.Latitude IS NOT NULL
1305+
AND l.Longitude IS NOT NULL
1306+
AND 6371000 * ACOS(
1307+
CASE
1308+
WHEN (COS(RADIANS(@Lat)) * COS(RADIANS(l.Latitude)) *
1309+
COS(RADIANS(l.Longitude) - RADIANS(@Lng)) +
1310+
SIN(RADIANS(@Lat)) * SIN(RADIANS(l.Latitude))) > 1 THEN 1
1311+
WHEN (COS(RADIANS(@Lat)) * COS(RADIANS(l.Latitude)) *
1312+
COS(RADIANS(l.Longitude) - RADIANS(@Lng)) +
1313+
SIN(RADIANS(@Lat)) * SIN(RADIANS(l.Latitude))) < -1 THEN -1
1314+
ELSE (COS(RADIANS(@Lat)) * COS(RADIANS(l.Latitude)) *
1315+
COS(RADIANS(l.Longitude) - RADIANS(@Lng)) +
1316+
SIN(RADIANS(@Lat)) * SIN(RADIANS(l.Latitude)))
1317+
END
1318+
) <= @RadiusMeters;
12851319
END
12861320
GO
12871321

02-Server/Properties/launchSettings.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"dotnetRunMessages": true,
1515
"launchBrowser": true,
1616
"launchUrl": "swagger",
17-
"applicationUrl": "http://localhost:5227",
17+
"applicationUrl": "http://0.0.0.0:5227",
1818
"environmentVariables": {
1919
"ASPNETCORE_ENVIRONMENT": "Development"
2020
}
@@ -24,7 +24,7 @@
2424
"dotnetRunMessages": true,
2525
"launchBrowser": true,
2626
"launchUrl": "swagger",
27-
"applicationUrl": "https://localhost:7072;http://localhost:5227",
27+
"applicationUrl": "https://0.0.0.0:7072;http://0.0.0.0:5227",
2828
"environmentVariables": {
2929
"ASPNETCORE_ENVIRONMENT": "Development"
3030
}

02-Server/appsettings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,13 @@
2828
"Microsoft.AspNetCore": "Warning"
2929
}
3030
},
31-
"AllowedHosts": "localhost",
31+
"AllowedHosts": "*",
3232
"Cors": {
3333
"AllowedOrigins": [
3434
"http://localhost:5173",
3535
"http://localhost:4173",
3636
"https://localhost:5173",
37+
"https://localhost",
3738
"https://app-groundshare-web-ekfneqfaahaca8ek.israelcentral-01.azurewebsites.net"
3839
]
3940
}

03-Client/.env.example

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@
2020
# Local dev (matches 02-Server Kestrel default):
2121
VITE_API_BASE_URL=http://localhost:5227/api
2222
#
23+
# Android device/emulator testing against your local backend:
24+
# 1. Find your machine's LAN IP (ipconfig → IPv4 Address, e.g. 192.168.1.50)
25+
# 2. Set VITE_API_BASE_URL to that IP in .env.local:
26+
# VITE_API_BASE_URL=http://192.168.1.50:5227/api
27+
# 3. Run Vite and point Capacitor at it (no build needed):
28+
# $env:CAPACITOR_DEV_SERVER_URL="http://192.168.1.50:5173"; npx cap run android
29+
#
2330
# Production (set during Phase 7 Azure deploy):
2431
# VITE_API_BASE_URL=https://app-groundshare-api.azurewebsites.net/api
2532

03-Client/android/app/build.gradle.kts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,3 @@ try {
6060
logger.info("google-services.json not found, google-services plugin not applied. Push Notifications won't work")
6161
}
6262

63-
apply plugin: 'com.google.gms.google-services'

03-Client/android/app/capacitor.build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ dependencies {
1313
implementation project(':capacitor-camera')
1414
implementation project(':capacitor-filesystem')
1515
implementation project(':capacitor-geolocation')
16+
implementation project(':capacitor-push-notifications')
1617
implementation project(':capacitor-splash-screen')
1718
implementation project(':capacitor-status-bar')
1819
implementation project(':capgo-capacitor-social-login')

03-Client/android/capacitor.settings.gradle

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ project(':capacitor-filesystem').projectDir = new File('../node_modules/@capacit
1414
include ':capacitor-geolocation'
1515
project(':capacitor-geolocation').projectDir = new File('../node_modules/@capacitor/geolocation/android')
1616

17+
include ':capacitor-push-notifications'
18+
project(':capacitor-push-notifications').projectDir = new File('../node_modules/@capacitor/push-notifications/android')
19+
1720
include ':capacitor-splash-screen'
1821
project(':capacitor-splash-screen').projectDir = new File('../node_modules/@capacitor/splash-screen/android')
1922

03-Client/capacitor.config.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,28 @@
11
import type { CapacitorConfig } from '@capacitor/cli';
22

3+
// Default config: bundled dist/ loads from https://localhost (Capacitor's
4+
// Android scheme). API calls go to VITE_API_BASE_URL baked into the bundle
5+
// at build time — set it in .env.local for dev, .env.production for release.
6+
//
7+
// For live-reload against the Vite dev server, use the official tooling:
8+
// npx cap run android --livereload --external
9+
// That flag injects the Capacitor bridge scripts correctly, unlike a raw
10+
// server.url override.
311
const config: CapacitorConfig = {
412
appId: 'com.groundshare.app',
513
appName: 'GroundShare',
614
webDir: 'dist',
715
android: {
8-
// Default in Capacitor 7+. Explicit here so the origin
9-
// required by the server CORS allowlist is visible in the repo.
10-
// WebView origin on Android: https://localhost
11-
allowMixedContent: false,
16+
// Needed so the WebView can hit http:// LAN backends during local dev.
17+
// Safe: release builds should use https:// for VITE_API_BASE_URL anyway.
18+
allowMixedContent: true,
1219
},
1320
server: {
14-
// Default in Capacitor 7+. iOS origin: capacitor://localhost.
1521
androidScheme: 'https',
1622
iosScheme: 'capacitor',
23+
// Needed alongside allowMixedContent for Android to permit cleartext
24+
// HTTP requests to the LAN dev backend.
25+
cleartext: true,
1726
},
1827
};
1928

03-Client/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
<meta charset="UTF-8" />
66
<meta name="viewport" content="width=device-width, initial-scale=1.0, viewport-fit=cover" />
77
<meta name="theme-color" content="#063c55" />
8+
<meta name="mobile-web-app-capable" content="yes" />
89
<meta name="apple-mobile-web-app-capable" content="yes" />
910
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
1011
<link rel="icon" href="/favicon.ico" />

03-Client/src/app/context/AuthContext.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,11 @@ export function AuthProvider({ children }: { children: ReactNode }) {
8383
return;
8484
}
8585

86-
api.getMyProfile()
86+
const timeout = new Promise<never>((_, reject) =>
87+
setTimeout(() => reject(new Error("timeout")), 10_000)
88+
);
89+
90+
Promise.race([api.getMyProfile(), timeout])
8791
.then((data) => {
8892
setUser(data as UserData);
8993
void registerForPush();

0 commit comments

Comments
 (0)