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
53 changes: 53 additions & 0 deletions Mail/Views/EasterEggViewModifier.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
Infomaniak Mail - iOS App
Copyright (C) 2025 Infomaniak Network SA

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import Lottie
import MailCore
import MailResources
import SwiftUI

struct EasterEggViewModifier: ViewModifier {
@Binding var presentedEasterEgg: EasterEgg?

func body(content: Content) -> some View {
content
.overlay(alignment: .bottom) {
if let showingEasterEgg = presentedEasterEgg {
LottieView(animation: .named(showingEasterEgg.lottieName, bundle: MailResourcesResources.bundle))
.animationDidFinish { _ in
presentedEasterEgg = nil
}
.playing(loopMode: .playOnce)
.frame(maxWidth: .infinity)
.scaledToFit()
.padding(.bottom, 96)
.ignoresSafeArea()
.allowsHitTesting(false)
.onAppear {
showingEasterEgg.onTrigger()
}
}
}
}
}

extension View {
func easterEggOverlay(_ presentedEasterEgg: Binding<EasterEgg?>) -> some View {
modifier(EasterEggViewModifier(presentedEasterEgg: presentedEasterEgg))
}
}
6 changes: 5 additions & 1 deletion Mail/Views/New Message/ComposeMessageView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ struct ComposeMessageView: View {
@LazyInjectService private var reviewManager: ReviewManageable

@Environment(\.dismiss) private var dismiss
@Environment(\.currentUser) private var currentUser
@Environment(\.dismissModal) private var dismissModal
@EnvironmentObject private var mainViewState: MainViewState

Expand Down Expand Up @@ -458,7 +459,10 @@ struct ComposeMessageView: View {
mainViewState.isShowingSetAppAsDefaultDiscovery = UserDefaults.shared.shouldPresentSetAsDefaultDiscovery
}
if !mainViewState.isShowingSetAppAsDefaultDiscovery {
mainViewState.isShowingChristmasEasterEgg = true
mainViewState.easterEgg = EasterEgg.determineEasterEgg(
localPack: mailboxManager.mailbox.pack,
isStaff: currentUser.value.isStaff ?? false
)
}
}
}
Expand Down
20 changes: 1 addition & 19 deletions Mail/Views/SplitView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import InfomaniakCoreCommonUI
import InfomaniakCoreSwiftUI
import InfomaniakDI
import KSuite
import Lottie
import MailCore
import MailCoreUI
import MailResources
Expand Down Expand Up @@ -134,24 +133,7 @@ struct SplitView: View {
}
}
}
.overlay(alignment: .bottom) {
if EasterEgg.christmas.shouldTrigger(mailboxManager.mailbox.pack, currentUser.value.isStaff ?? false)
&& mainViewState.isShowingChristmasEasterEgg {
LottieView(animation: LottieAnimation.named("easter_egg_xmas", bundle: MailResourcesResources.bundle))
.animationDidFinish { _ in
mainViewState.isShowingChristmasEasterEgg = false
}
.playing(loopMode: .playOnce)
.frame(maxWidth: .infinity)
.frame(height: 200)
.padding(.bottom, 96)
.ignoresSafeArea()
.allowsHitTesting(false)
.onAppear {
EasterEgg.christmas.onTrigger()
}
}
}
.easterEggOverlay($mainViewState.easterEgg)
.mailDiscoveryPresenter(isPresented: $mainViewState.isShowingUpdateAvailable) {
UpdateVersionView(image: MailResourcesAsset.documentStarsRocket.swiftUIImage) { willUpdate in
if willUpdate {
Expand Down
2 changes: 1 addition & 1 deletion MailCore/Cache/MainViewState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class MainViewState: ObservableObject, SelectedThreadOwnable {
@ModalPublished public var isShowingKSuiteProUpgrade = false
@ModalPublished public var destructiveAlert: DestructiveActionAlertState?
@ModalPublished public var modifiedScheduleDraftResource: ModifiedScheduleDraftResource?
@Published public var isShowingChristmasEasterEgg = false
@Published public var easterEgg: EasterEgg?

/// Represents the state of navigation
///
Expand Down
45 changes: 42 additions & 3 deletions MailCore/Utils/EasterEgg.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,19 @@ import InfomaniakCoreCommonUI
import InfomaniakDI

public struct EasterEgg {
public let lottieName: String
public let shouldTrigger: (LocalPack?, Bool) -> Bool
public let onTrigger: () -> Void

public static let christmas = EasterEgg { localPack, isStaff in
public static let allCases: [EasterEgg] = [
.christmas,
.newYear
]

// We only display for individual users not the business ones
private static let allowedPacks: Set<LocalPack> = [.myKSuiteFree, .myKSuitePlus, .starterPack]

public static let christmas = EasterEgg(lottieName: "easter_egg_xmas") { localPack, isStaff in
let calendar = Calendar(identifier: .gregorian)
let components = calendar.dateComponents([.day, .month], from: Date())
guard let month = components.month, let day = components.day else {
Expand All @@ -36,8 +45,6 @@ public struct EasterEgg {
return false
}

// We only display for individual users not the business ones
let allowedPacks: Set<LocalPack> = [.myKSuiteFree, .myKSuitePlus, .starterPack]
guard allowedPacks.contains(localPack ?? .kSuitePaid) || isStaff else {
return false
}
Expand All @@ -49,4 +56,36 @@ public struct EasterEgg {
@InjectService var matomoUtils: MatomoUtils
matomoUtils.track(eventWithCategory: .easterEgg, name: "XMas\(year)")
}

public static let newYear = EasterEgg(lottieName: "easter_egg_newyear") { localPack, isStaff in
let calendar = Calendar(identifier: .gregorian)
let components = calendar.dateComponents([.day, .month], from: Date())
guard let month = components.month, let day = components.day else {
return false
}

let isCorrectPeriod = (month == 12 && day == 31) || (month == 1 && day == 1)
guard isCorrectPeriod else {
return false
}

guard allowedPacks.contains(localPack ?? .kSuitePaid) || isStaff else {
return false
}

return true
} onTrigger: {
let year = Calendar(identifier: .gregorian).component(.year, from: Date())
@InjectService var matomoUtils: MatomoUtils
matomoUtils.track(eventWithCategory: .easterEgg, name: "newYear\(year)")
}

public static func determineEasterEgg(localPack: LocalPack?, isStaff: Bool) -> EasterEgg? {
for easterEgg in EasterEgg.allCases {
if easterEgg.shouldTrigger(localPack, isStaff) {
return easterEgg
}
}
return nil
}
}
1 change: 1 addition & 0 deletions MailResources/EasterEggs/easter_egg_newyear.json

Large diffs are not rendered by default.

Loading