Skip to content

Commit

Permalink
Add settings for flash/sound when event is close (#297)
Browse files Browse the repository at this point in the history
  • Loading branch information
pakerwreah authored Nov 15, 2024
1 parent 7d6ac15 commit ff317f6
Show file tree
Hide file tree
Showing 22 changed files with 178 additions and 73 deletions.
4 changes: 2 additions & 2 deletions Calendr.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1491,7 +1491,7 @@
"$(inherited)",
"@executable_path/../Frameworks",
);
MARKETING_VERSION = 1.14.6;
MARKETING_VERSION = 1.14.7;
PRODUCT_BUNDLE_IDENTIFIER = br.paker.Calendr;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "Calendr/Config/Calendr-Bridging-Header.h";
Expand Down Expand Up @@ -1519,7 +1519,7 @@
"$(inherited)",
"@executable_path/../Frameworks",
);
MARKETING_VERSION = 1.14.6;
MARKETING_VERSION = 1.14.7;
PRODUCT_BUNDLE_IDENTIFIER = br.paker.Calendr;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "Calendr/Config/Calendr-Bridging-Header.h";
Expand Down
1 change: 1 addition & 0 deletions Calendr.xcodeproj/xcshareddata/xcschemes/Calendr.xcscheme
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = "pt"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
Expand Down
10 changes: 8 additions & 2 deletions Calendr/Assets/Strings.generated.swift
Original file line number Diff line number Diff line change
Expand Up @@ -221,10 +221,16 @@ internal enum Strings {
internal enum NextEvent {
/// Shorten if 'notch' is present
internal static let detectNotch = Strings.tr("Localizable", "settings.next_event.detect_notch", fallback: "Shorten if 'notch' is present")
/// Font size
internal static let fontSize = Strings.tr("Localizable", "settings.next_event.font_size", fallback: "Font size")
/// Grab attention when event is close
internal static let grabAttention = Strings.tr("Localizable", "settings.next_event.grab_attention", fallback: "Grab attention when event is close")
/// Show next event
internal static let showNextEvent = Strings.tr("Localizable", "settings.next_event.show_next_event", fallback: "Show next event")
internal enum GrabAttention {
/// Flashing
internal static let flashing = Strings.tr("Localizable", "settings.next_event.grab_attention.flashing", fallback: "Flashing")
/// Play sound
internal static let sound = Strings.tr("Localizable", "settings.next_event.grab_attention.sound", fallback: "Play sound")
}
}
internal enum Tab {
/// About
Expand Down
4 changes: 3 additions & 1 deletion Calendr/Assets/cs.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@

"settings.next_event" = "Další událost";
"settings.next_event.show_next_event" = "Zobrazit další událost";
"settings.next_event.font_size" = "Velikost písma";
//"settings.next_event.grab_attention" = "Grab attention when event is close";
//"settings.next_event.grab_attention.flashing" = "Flashing";
//"settings.next_event.grab_attention.sound" = "Play sound";
"settings.next_event.detect_notch" = "Zkrátit, pokud je 'výřez' přítomen";

"settings.calendar" = "Kalendář";
Expand Down
4 changes: 3 additions & 1 deletion Calendr/Assets/de.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@

"settings.next_event" = "Nächster Termin";
"settings.next_event.show_next_event" = "Zeige nächsten Termin";
"settings.next_event.font_size" = "Schriftgröße";
//"settings.next_event.grab_attention" = "Grab attention when event is close";
//"settings.next_event.grab_attention.flashing" = "Flashing";
//"settings.next_event.grab_attention.sound" = "Play sound";
"settings.next_event.detect_notch" = "Kürzen, wenn 'notch' vorhanden ist";

"settings.calendar" = "Kalender";
Expand Down
4 changes: 3 additions & 1 deletion Calendr/Assets/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@

"settings.next_event" = "Next Event";
"settings.next_event.show_next_event" = "Show next event";
"settings.next_event.font_size" = "Font size";
"settings.next_event.grab_attention" = "Grab attention when event is close";
"settings.next_event.grab_attention.flashing" = "Flashing";
"settings.next_event.grab_attention.sound" = "Play sound";
"settings.next_event.detect_notch" = "Shorten if 'notch' is present";

"settings.calendar" = "Calendar";
Expand Down
4 changes: 3 additions & 1 deletion Calendr/Assets/es.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@

"settings.next_event" = "Próximo evento";
"settings.next_event.show_next_event" = "Mostrar próximo evento";
"settings.next_event.font_size" = "Tamaño de fuente";
//"settings.next_event.grab_attention" = "Grab attention when event is close";
//"settings.next_event.grab_attention.flashing" = "Flashing";
//"settings.next_event.grab_attention.sound" = "Play sound";
"settings.next_event.detect_notch" = "Acortar si 'notch' está presente";

"settings.calendar" = "Calendario";
Expand Down
4 changes: 3 additions & 1 deletion Calendr/Assets/fr.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@

"settings.next_event" = "Prochain événement";
"settings.next_event.show_next_event" = "Afficher prochain événement";
"settings.next_event.font_size" = "Taille de police";
//"settings.next_event.grab_attention" = "Grab attention when event is close";
//"settings.next_event.grab_attention.flashing" = "Flashing";
//"settings.next_event.grab_attention.sound" = "Play sound";
"settings.next_event.detect_notch" = "Raccourcir si 'notch' est présent";

"settings.calendar" = "Calendrier";
Expand Down
4 changes: 3 additions & 1 deletion Calendr/Assets/it.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@

"settings.next_event" = "Prossimo evento";
"settings.next_event.show_next_event" = "Mostra il prossimo evento";
"settings.next_event.font_size" = "Dimensione del font";
//"settings.next_event.grab_attention" = "Grab attention when event is close";
//"settings.next_event.grab_attention.flashing" = "Flashing";
//"settings.next_event.grab_attention.sound" = "Play sound";
"settings.next_event.detect_notch" = "Più corto se c'è il 'notch'";

"settings.calendar" = "Calendario";
Expand Down
4 changes: 3 additions & 1 deletion Calendr/Assets/pt.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@

"settings.next_event" = "Próximo Evento";
"settings.next_event.show_next_event" = "Mostrar próximo evento";
"settings.next_event.font_size" = "Tamanho da fonte";
"settings.next_event.grab_attention" = "Chamar atenção quando o evento estiver próximo";
"settings.next_event.grab_attention.flashing" = "Piscando";
"settings.next_event.grab_attention.sound" = "Tocar som";
"settings.next_event.detect_notch" = "Encurtar se 'notch' estiver presente";

"settings.calendar" = "Calendário";
Expand Down
4 changes: 3 additions & 1 deletion Calendr/Assets/sk.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@

"settings.next_event" = "Ďalšia udalosť";
"settings.next_event.show_next_event" = "Zobraziť ďalšiu udalosť";
"settings.next_event.font_size" = "Veľkosť písma";
//"settings.next_event.grab_attention" = "Grab attention when event is close";
//"settings.next_event.grab_attention.flashing" = "Flashing";
//"settings.next_event.grab_attention.sound" = "Play sound";
"settings.next_event.detect_notch" = "Skrátiť, ak je prítomný 'výrez'";

"settings.calendar" = "Kalendár";
Expand Down
4 changes: 3 additions & 1 deletion Calendr/Assets/sv.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@

"settings.next_event" = "Nästa händelse";
"settings.next_event.show_next_event" = "Visa nästa händelse";
"settings.next_event.font_size" = "Teckenstorlek";
//"settings.next_event.grab_attention" = "Grab attention when event is close";
//"settings.next_event.grab_attention.flashing" = "Flashing";
//"settings.next_event.grab_attention.sound" = "Play sound";
"settings.next_event.detect_notch" = "Korta om 'notch' finns";

"settings.calendar" = "Kalender";
Expand Down
4 changes: 3 additions & 1 deletion Calendr/Assets/zh-Hans.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@

"settings.next_event" = "下一个日程";
"settings.next_event.show_next_event" = "显示下一个日程";
"settings.next_event.font_size" = "字体大小";
//"settings.next_event.grab_attention" = "Grab attention when event is close";
//"settings.next_event.grab_attention.flashing" = "Flashing";
//"settings.next_event.grab_attention.sound" = "Play sound";
"settings.next_event.detect_notch" = "为屏幕“刘海”缩短长度";

"settings.calendar" = "日历";
Expand Down
4 changes: 3 additions & 1 deletion Calendr/Assets/zh-Hant-TW.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@

"settings.next_event" = "下一個事件";
"settings.next_event.show_next_event" = "顯示下一個事件";
"settings.next_event.font_size" = "字型大小";
//"settings.next_event.grab_attention" = "Grab attention when event is close";
//"settings.next_event.grab_attention.flashing" = "Flashing";
//"settings.next_event.grab_attention.sound" = "Play sound";
"settings.next_event.detect_notch" = "若有 '瀏海' 則縮短";

"settings.calendar" = "行事曆";
Expand Down
37 changes: 21 additions & 16 deletions Calendr/MenuBar/NextEventViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,10 @@ class NextEventViewModel {

backgroundColor = nextEventObservable
.skipNil()
.map { [dateProvider] nextEvent in
.withLatestFrom(
Observable.combineLatest(settings.eventStatusItemFlashing, settings.eventStatusItemSound)
) { ($0, $1.0, $1.1) }
.map { [dateProvider] nextEvent, flashing, sound in

guard !nextEvent.isInProgress else {
return nextEvent.event.calendar.color.withAlphaComponent(0.2)
Expand All @@ -179,26 +182,28 @@ class NextEventViewModel {

guard let minutes = diff.minute, let seconds = diff.second else { return .clear }

// play when event starts
if minutes == 0 && seconds == 0 {
DispatchQueue.main.asyncAfter(deadline: .now() + .seconds(1)) {
soundPlayer.play(.glass)
if sound {
// play at 5 minutes
if minutes == 5 && seconds == 0 {
soundPlayer.play(.ping)
}
}

// play at 5 minutes + 1 minute to start
if [1, 5].contains(minutes) && seconds == 0 {
soundPlayer.play(.ping)
// play at 30 seconds to start
if minutes == 0 && seconds == 30 {
soundPlayer.play(.ping)
}
}

// flash continuously under 30 seconds to start
if minutes == 0 && seconds <= 30 {
return seconds % 2 == 0 ? .systemRed : .clear
}
if flashing {
// flash continuously under 30 seconds to start
if minutes == 0 && seconds <= 30 {
return seconds % 2 == 0 ? .systemRed : .clear
}

// flash 5x every minute
if minutes <= 5 {
return seconds > 50 && seconds % 2 == 1 ? .systemRed : .clear
// flash 5x every minute
if minutes <= 5 {
return seconds > 50 && seconds % 2 == 1 ? .systemRed : .clear
}
}

return .clear
Expand Down
10 changes: 8 additions & 2 deletions Calendr/Mocks/MockNextEventSettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,25 @@ class MockNextEventSettings: MockEventDetailsSettings, NextEventSettings {
let showEventStatusItem: Observable<Bool>
let eventStatusItemTextScaling: Observable<Double>
let eventStatusItemCheckRange: Observable<Int>
let eventStatusItemFlashing: Observable<Bool>
let eventStatusItemSound: Observable<Bool>
let eventStatusItemLength: Observable<Int>
let eventStatusItemDetectNotch: Observable<Bool>

init(
showItem: Bool = true,
textScaling: Double = 1,
checkRange: Int = 10,
flashing: Bool = true,
sound: Bool = true,
textScaling: Double = 1,
length: Int = 20,
detectNotch: Bool = false
) {
showEventStatusItem = .just(showItem)
eventStatusItemTextScaling = .just(textScaling)
eventStatusItemCheckRange = .just(checkRange)
eventStatusItemFlashing = .just(flashing)
eventStatusItemSound = .just(sound)
eventStatusItemTextScaling = .just(textScaling)
eventStatusItemLength = .just(length)
eventStatusItemDetectNotch = .just(detectNotch)
}
Expand Down
2 changes: 1 addition & 1 deletion Calendr/Previews/NextEventPreview.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ struct NextEventPreview: PreviewProvider {

static let events: [EventModel] = [
.make(
start: dateProvider.now + 5,
start: dateProvider.now + 70,
end: dateProvider.now + 999,
title: "Test with a very long event name and some more extra text",
type: .event(.accepted),
Expand Down
Loading

0 comments on commit ff317f6

Please sign in to comment.