Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
175 changes: 175 additions & 0 deletions VITTY/ServerStatus.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
//
// ServerStatus.swift
// VITTY
//
// Created by Rujin Devkota on 8/4/25.
//

import Foundation
import Alamofire
import SwiftUI
import OSLog

@Observable
class ServerStatusManager {
var isServerDown = false
var isCheckingServer = false
var showMaintenanceAlert = false

private let logger = Logger(
subsystem: Bundle.main.bundleIdentifier!,
category: String(describing: ServerStatusManager.self)
)


func checkServerStatus(completion: @escaping (Bool) -> Void) {
isCheckingServer = true

let url = APIConstants.base_url

AF.request(url, method: .get)
.validate()
.responseString { response in
DispatchQueue.main.async {
self.isCheckingServer = false

switch response.result {
case .success(let responseString):

let isServerUp = responseString.contains("Welcome to VITTY API!🎉")
self.isServerDown = !isServerUp

if !isServerUp {
self.showMaintenanceAlert = true
self.logger.warning("Server is under maintenance")
}

completion(isServerUp)

case .failure(let error):
self.logger.error("Server check failed: \(error)")
self.isServerDown = true
self.showMaintenanceAlert = true
completion(false)
}
}
}
}


// function for testing
// func checkServerStatus(completion: @escaping (Bool) -> Void) {
// isCheckingServer = true
//
//
// DispatchQueue.main.async {
// self.isCheckingServer = false
// self.isServerDown = false
// self.showMaintenanceAlert = false
//
//
// completion(true)
// }
// }

func hideMaintenanceAlert() {
showMaintenanceAlert = false
}

func retryServerCheck(completion: @escaping (Bool) -> Void) {
checkServerStatus(completion: completion)
}
}

// MARK: - Maintenance Alert View
struct MaintenanceAlertView: View {
@Binding var isPresented: Bool
let onRetry: () -> Void
let onContinue: () -> Void

var body: some View {
ZStack {
Color.black.opacity(0.5)
.edgesIgnoringSafeArea(.all)

VStack(spacing: 20) {

HStack {
Spacer()
Button(action: {
isPresented = false
onContinue()
}) {
Image(systemName: "xmark")
.foregroundColor(.gray)
.font(.system(size: 18))
}
}


RoundedRectangle(cornerRadius: 16)
.fill(Color.gray.opacity(0.3))
.frame(width: 80, height: 80)
.overlay(
Image(systemName: "wrench.and.screwdriver")
.foregroundColor(.white)
.font(.system(size: 32))
)


Text("Server Maintenance")
.font(.custom("Poppins-SemiBold", size: 24))
.foregroundColor(.white)


Text("The server is currently under maintenance. Some features may be temporarily unavailable.")
.font(.custom("Poppins-Regular", size: 16))
.foregroundColor(.gray)
.multilineTextAlignment(.center)
.padding(.horizontal, 20)

// Buttons
HStack(spacing: 15) {
Button(action: {
onRetry()
}) {
Text("Retry")
.font(.custom("Poppins-Medium", size: 16))
.foregroundColor(.black)
.frame(maxWidth: .infinity)
.padding(.vertical, 12)
.background(Color.white)
.cornerRadius(8)
}

Button(action: {
isPresented = false
onContinue()
}) {
Text("Continue")
.font(.custom("Poppins-Medium", size: 16))
.foregroundColor(.white)
.frame(maxWidth: .infinity)
.padding(.vertical, 12)
.background(Color.clear)
.overlay(
RoundedRectangle(cornerRadius: 8)
.stroke(Color.gray, lineWidth: 1)
)
}
}
.padding(.horizontal, 20)


Text("Thank you for your patience")
.font(.custom("Poppins-Regular", size: 14))
.foregroundColor(.gray)
.padding(.top, 10)
}
.padding(30)
.background(Color("Background"))
.cornerRadius(20)
.padding(.horizontal, 30)
}
}
}
8 changes: 8 additions & 0 deletions VITTY/VITTY.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
4B183EE82D7C78B600C9D801 /* Courses.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B183EE72D7C78B300C9D801 /* Courses.swift */; };
4B183EEA2D7C793800C9D801 /* RemindersData.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B183EE92D7C791400C9D801 /* RemindersData.swift */; };
4B183EEC2D7CB15800C9D801 /* CourseRefs.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B183EEB2D7CB11500C9D801 /* CourseRefs.swift */; };
4B1A500F2E3E61530060314D /* GoogleService-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 4B1A500E2E3E61530060314D /* GoogleService-Info.plist */; };
4B1A50112E409F8C0060314D /* ServerStatus.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B1A50102E409F860060314D /* ServerStatus.swift */; };
4B1BDBCC2E1396B1008C2DE9 /* ToolTip.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B1BDBCB2E1396A9008C2DE9 /* ToolTip.swift */; };
4B2D648F2E20BA6300412CB7 /* NetworkMonitor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B2D648E2E20BA5A00412CB7 /* NetworkMonitor.swift */; };
4B2D64902E20BA6300412CB7 /* NetworkMonitor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B2D648E2E20BA5A00412CB7 /* NetworkMonitor.swift */; };
Expand Down Expand Up @@ -197,6 +199,8 @@
4B183EE72D7C78B300C9D801 /* Courses.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Courses.swift; sourceTree = "<group>"; };
4B183EE92D7C791400C9D801 /* RemindersData.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RemindersData.swift; sourceTree = "<group>"; };
4B183EEB2D7CB11500C9D801 /* CourseRefs.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CourseRefs.swift; sourceTree = "<group>"; };
4B1A500E2E3E61530060314D /* GoogleService-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "GoogleService-Info.plist"; sourceTree = "<group>"; };
4B1A50102E409F860060314D /* ServerStatus.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ServerStatus.swift; sourceTree = "<group>"; };
4B1BDBCB2E1396A9008C2DE9 /* ToolTip.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ToolTip.swift; sourceTree = "<group>"; };
4B2D648E2E20BA5A00412CB7 /* NetworkMonitor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NetworkMonitor.swift; sourceTree = "<group>"; };
4B2DD6942E0A702D00BC3B67 /* CircleRequests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CircleRequests.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -414,10 +418,12 @@
isa = PBXGroup;
children = (
4BC853C52DF6F71B0092B2E2 /* VittyWidgetExtension.entitlements */,
4B1A500E2E3E61530060314D /* GoogleService-Info.plist */,
4B8FB2C72E39D29F00E50AE2 /* GoogleService-Info.plist */,
5251A7FF2B46E3C000D44CFE /* .swift-format */,
314A408E27383BEC0058082F /* VITTYApp.swift */,
314A409027383BEC0058082F /* ContentView.swift */,
4B1A50102E409F860060314D /* ServerStatus.swift */,
314A409227383BEE0058082F /* Assets.xcassets */,
AFEFCB6C27C90233007B2029 /* VITTY.entitlements */,
AFEFCB6B27C90042007B2029 /* VITTYRelease.entitlements */,
Expand Down Expand Up @@ -1122,6 +1128,7 @@
31128CFA2772F57E0084C9EA /* Poppins-SemiBoldItalic.ttf in Resources */,
31128CFC2772F57E0084C9EA /* Poppins-Regular.ttf in Resources */,
4B8FB2C82E39D29F00E50AE2 /* GoogleService-Info.plist in Resources */,
4B1A500F2E3E61530060314D /* GoogleService-Info.plist in Resources */,
314A409627383BEE0058082F /* Preview Assets.xcassets in Resources */,
314A409327383BEE0058082F /* Assets.xcassets in Resources */,
);
Expand Down Expand Up @@ -1213,6 +1220,7 @@
4B7DA5E72D71AC54007354A3 /* CirclesRow.swift in Sources */,
4B7DA5E52D70B2CA007354A3 /* Circles.swift in Sources */,
525F759D2B809F8400E3B418 /* LectureDetailView.swift in Sources */,
4B1A50112E409F8C0060314D /* ServerStatus.swift in Sources */,
520BA6432B47FFF900124850 /* SuggestedFriendsViewModel.swift in Sources */,
314A408F27383BEC0058082F /* VITTYApp.swift in Sources */,
52978F8E2C3A7924008CF46C /* BottomBarView.swift in Sources */,
Expand Down
Loading
Loading