Skip to content

Commit

Permalink
Full screen notification v0
Browse files Browse the repository at this point in the history
  • Loading branch information
leits committed Dec 27, 2023
1 parent 0782abf commit 8804df3
Show file tree
Hide file tree
Showing 4 changed files with 141 additions and 11 deletions.
20 changes: 13 additions & 7 deletions MeetingBar.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
4654E66227F24A3F001848AB /* Protocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4654E66127F24A3F001848AB /* Protocol.swift */; };
4672B58229C130160055E7D7 /* AppIntent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4672B58129C130160055E7D7 /* AppIntent.swift */; };
467351B729057BC900EE3987 /* StringExtensionsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 467351B629057BC900EE3987 /* StringExtensionsTests.swift */; };
46B0E9692A78340B00C936DB /* AutoJoinScreen.swift in Sources */ = {isa = PBXBuildFile; fileRef = 46B0E9682A78340B00C936DB /* AutoJoinScreen.swift */; };
46E4794C2801D53B00B48059 /* MeetingServices.swift in Sources */ = {isa = PBXBuildFile; fileRef = 46E4794B2801D53B00B48059 /* MeetingServices.swift */; };
46E4794E2802141800B48059 /* Calendar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 46E4794D2802141800B48059 /* Calendar.swift */; };
46E479502802155700B48059 /* Event.swift in Sources */ = {isa = PBXBuildFile; fileRef = 46E4794F2802155700B48059 /* Event.swift */; };
Expand Down Expand Up @@ -116,6 +117,7 @@
4654E66127F24A3F001848AB /* Protocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Protocol.swift; sourceTree = "<group>"; };
4672B58129C130160055E7D7 /* AppIntent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppIntent.swift; sourceTree = "<group>"; };
467351B629057BC900EE3987 /* StringExtensionsTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StringExtensionsTests.swift; sourceTree = "<group>"; };
46B0E9682A78340B00C936DB /* AutoJoinScreen.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AutoJoinScreen.swift; sourceTree = "<group>"; };
46E4794B2801D53B00B48059 /* MeetingServices.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MeetingServices.swift; sourceTree = "<group>"; };
46E4794D2802141800B48059 /* Calendar.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Calendar.swift; sourceTree = "<group>"; };
46E4794F2802155700B48059 /* Event.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Event.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -190,26 +192,26 @@
144C017B2462D0C3000C9FFC /* MeetingBar */ = {
isa = PBXGroup;
children = (
E26A0BFB263449E300F117A9 /* Scripts.swift */,
4672B58129C130160055E7D7 /* AppIntent.swift */,
1BF37A902604C8050053D53C /* Resources */,
144C017C2462D0C3000C9FFC /* AppDelegate.swift */,
1452C9AD25AF5B1000C46CDF /* Views */,
46E4794A2801D4BD00B48059 /* EventStores */,
149AD20F25A8967C004976F1 /* Extensions */,
144C017C2462D0C3000C9FFC /* AppDelegate.swift */,
140D84312493A3FE0055E1CE /* StatusBarItemController.swift */,
140D84332493A4180055E1CE /* Constants.swift */,
01044AE027EA695A0070512E /* ActionsOnEventStart.swift */,
4672B58129C130160055E7D7 /* AppIntent.swift */,
E26A0BFB263449E300F117A9 /* Scripts.swift */,
14C59B8425CF45340019C9E4 /* AppStore.swift */,
140D84392493A6240055E1CE /* Helpers.swift */,
1BF37AA42604F7E00053D53C /* I18N.swift */,
14879B2A24E6889C00DB0A7E /* Notifications.swift */,
46E4794B2801D53B00B48059 /* MeetingServices.swift */,
46E4794A2801D4BD00B48059 /* EventStores */,
149AD20F25A8967C004976F1 /* Extensions */,
144C01822462D0C5000C9FFC /* Preview Content */,
144C01852462D0C5000C9FFC /* Main.storyboard */,
144C01882462D0C5000C9FFC /* Info.plist */,
144C01802462D0C5000C9FFC /* Assets.xcassets */,
144C01892462D0C5000C9FFC /* MeetingBar.entitlements */,
1BF37AA42604F7E00053D53C /* I18N.swift */,
01044AE027EA695A0070512E /* ActionsOnEventStart.swift */,
);
path = MeetingBar;
sourceTree = "<group>";
Expand All @@ -229,6 +231,7 @@
1452C9B225AF5C6F00C46CDF /* Preferences */,
1452C9B325AF5C7D00C46CDF /* Onboarding */,
1452C9BB25AF5D8700C46CDF /* Shared.swift */,
46B0E9682A78340B00C936DB /* AutoJoinScreen.swift */,
);
path = Views;
sourceTree = "<group>";
Expand Down Expand Up @@ -501,6 +504,7 @@
buildActionMask = 2147483647;
files = (
1452C9D825AF889A00C46CDF /* WelcomeScreen.swift in Sources */,
46B0E9692A78340B00C936DB /* AutoJoinScreen.swift in Sources */,
1452C9BC25AF5D8700C46CDF /* Shared.swift in Sources */,
1435E44C260954D00071B188 /* Changelog.swift in Sources */,
1452C9D225AF86E700C46CDF /* AdvancedTab.swift in Sources */,
Expand Down Expand Up @@ -726,6 +730,7 @@
CURRENT_PROJECT_VERSION = 150;
DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_ASSET_PATHS = "";
DEVELOPMENT_TEAM = KGH289N6T8;
ENABLE_HARDENED_RUNTIME = YES;
ENABLE_PREVIEWS = YES;
INFOPLIST_FILE = MeetingBar/Info.plist;
Expand Down Expand Up @@ -756,6 +761,7 @@
CURRENT_PROJECT_VERSION = 150;
DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_ASSET_PATHS = "";
DEVELOPMENT_TEAM = KGH289N6T8;
ENABLE_HARDENED_RUNTIME = YES;
ENABLE_PREVIEWS = YES;
INFOPLIST_FILE = MeetingBar/Info.plist;
Expand Down
8 changes: 4 additions & 4 deletions MeetingBar/ActionsOnEventStart.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ class ActionsOnEventStart: NSObject {

let startEndRange = nextEvent.startDate ... nextEvent.endDate

// time until the start of the event with a delay of 10 seconds
let timeInterval = nextEvent.startDate.timeIntervalSince(now) + 10
let timeInterval = nextEvent.startDate.timeIntervalSince(now)

let allDayCandidate = nextEvent.isAllDay && startEndRange.contains(now)

Expand All @@ -64,7 +63,7 @@ class ActionsOnEventStart: NSObject {
* ------------------------
*/
let actionTimeForEventAutoJoin = Double(Defaults[.automaticEventJoinTime].rawValue)
let nonAlldayCandidateForAutoJoin = (timeInterval > 0 && timeInterval < actionTimeForEventAutoJoin)
let nonAlldayCandidateForAutoJoin = (timeInterval > -15 && timeInterval < actionTimeForEventAutoJoin)

if autoJoinActionActive && (nonAlldayCandidateForAutoJoin || allDayCandidate) {
var events = Defaults[.processedEventsForAutoJoin]
Expand All @@ -76,7 +75,8 @@ class ActionsOnEventStart: NSObject {
// this is an edge case when the event was already notified for, but scheduled for a later time.
if matchedEvent == nil || matchedEvent?.lastModifiedDate != nextEvent.lastModifiedDate {
if nextEvent.meetingLink != nil {
nextEvent.openMeeting()
// nextEvent.openMeeting()
app.openAutJoinWindow(event: nextEvent)
}

// update the executed events
Expand Down
27 changes: 27 additions & 0 deletions MeetingBar/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,33 @@ class AppDelegate: NSObject, NSApplicationDelegate, UNUserNotificationCenterDele
changelogWindow.orderFrontRegardless()
}

func openAutJoinWindow(event: MBEvent) {
let screenFrame = NSScreen.main?.frame ?? NSRect(x: 0, y: 0, width: 800, height: 600)

let window = NSWindow(
contentRect: screenFrame,
styleMask: [.borderless],
backing: .buffered,
defer: false
)

window.contentView = NSHostingView(rootView: AutoJoinScreen(event: event, window: window))
window.appearance = NSAppearance(named: .darkAqua)
window.collectionBehavior = .canJoinAllSpaces
window.collectionBehavior = .moveToActiveSpace

window.titlebarAppearsTransparent = true
window.styleMask.insert(.fullSizeContentView)
window.title = "Meetingbar Autojoin"
window.level = .screenSaver

let controller = NSWindowController(window: window)
controller.showWindow(self)

window.center()
window.orderFrontRegardless()
}

@objc
func openPrefecencesWindow(_: NSStatusBarButton?) {
let contentView = PreferencesView()
Expand Down
97 changes: 97 additions & 0 deletions MeetingBar/Views/AutoJoinScreen.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
//
// AutoJoinScreen.swift
// MeetingBar
//
// Created by Andrii Leitsius on 31.07.2023.
// Copyright © 2023 Andrii Leitsius. All rights reserved.
//

import SwiftUI
import Defaults

struct AutoJoinScreen: View {
var event: MBEvent
var window: NSWindow?

var body: some View {
ZStack {
Rectangle.semiOpaqueWindow()
VStack {
Text(event.title).font(.system(size: 40)).padding(.bottom, 2)
Text(event.meetingLink?.service?.rawValue ?? "").font(.system(size: 16))
VStack {
Text(getEventDateString(event)).padding(.bottom, 2)
if #available(macOS 11.0, *) {
Text(event.startDate, style: .relative).font(.system(size: 16))
}
}.padding(15)
HStack(spacing: 40) {
Button("Dismiss") {
self.window?.close()
}
Button("Join event") {
self.event.openMeeting()
self.window?.close()
}.background(Color.accentColor.opacity(1))
}

}
}
.colorScheme(.dark)
.frame(maxWidth: .infinity, maxHeight: .infinity)
}
}

extension View {
public static func semiOpaqueWindow() -> some View {
if #available(macOS 11.0, *) {
return VisualEffect().ignoresSafeArea()
} else {
return VisualEffect()
}
}

}

struct VisualEffect: NSViewRepresentable {
func makeNSView(context: Context) -> NSView {
let view = NSVisualEffectView()
view.material = .underWindowBackground
view.blendingMode = .behindWindow
view.state = .active
return view
}
func updateNSView(_ view: NSView, context: Context) { }
}

func getEventDateString(_ event: MBEvent) -> String {
let formatter = DateIntervalFormatter()
formatter.dateStyle = .none
formatter.timeStyle = .short
return formatter.string(from: event.startDate, to: event.endDate)
}

func generateEvent() -> MBEvent {
let calendar = MBCalendar(title: "Fake calendar", ID: "fake_cal", source: nil, email: nil, color: .black)

let event = MBEvent(
ID: "test_event",
lastModifiedDate: nil,
title: "Test event",
status: .confirmed,
notes: nil,
location: nil,
url: URL(string: "https://zoom.us/j/5551112222")!,
organizer: nil,
startDate: Calendar.current.date(byAdding: .minute, value: 3, to: Date())!,
endDate: Calendar.current.date(byAdding: .minute, value: 33, to: Date())!,
isAllDay: false,
recurrent: false,
calendar: calendar
)
return event
}

#Preview {
AutoJoinScreen(event: generateEvent(), window: nil)
}

0 comments on commit 8804df3

Please sign in to comment.