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
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ Click the timer icon and a hand-drawn desk opens under it: a window onto the tow
| Mug | Pauses or resumes. |
| Sticky notes on the wall | Open the settings. |
| Record player | Opens Spotify's now-playing note. |
| Notebook | Opens today's task list. |
| Cat | Pet it for hearts and a written *prrr~*. |

- **Small, calm motion.** The cat breathes, the coffee steams, and the record spins while music plays. With **Reduce Motion** turned on, the decorative motion stops.
Expand All @@ -45,6 +46,11 @@ Click the timer icon and a hand-drawn desk opens under it: a window onto the tow
- **Long breaks.** In a session with more than 4 rounds, the break after every 4th round is three times as long (at most 30 minutes).
- **A summary at the end.** You see minutes studied, your average focus with a small chart, and how many nudges you got.

### Today's tasks
- **A to-do list on the notebook.** Click the open notebook to see today's tasks. Type a task and press Return to add the next one, up to 6.
- **Tick, don't lose.** A ticked task fades and gets a pencil line through it. Click its box again to bring it back.
- **Clear when you want.** **clear done** takes the ticked tasks off the page. Nothing clears by itself, and the list stays after you quit.

### Focus tracking (optional)
- **Estimates focus from the camera.** During study phases, FocusGuard checks eye openness, gaze and head pose about 10 times a second. The card shows a focus percentage and a pencil-drawn chart.
- **Never guesses.** When the camera cannot see your eyes clearly, the figure is hidden instead of guessed.
Expand Down
7 changes: 7 additions & 0 deletions Resources/pl.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,10 @@
"Session done! The cat is proud of you~" = "Sesja skończona! Kot jest z ciebie dumny~";
"That's a wrap, well studied! ♡" = "Koniec, świetna nauka! ♡";
"Done! Time for a proper rest~" = "Gotowe! Czas na porządny odpoczynek~";
"Today's tasks" = "Zadania na dziś";
"today's tasks" = "zadania na dziś";
"add a task" = "dodaj zadanie";
"clear done" = "wyczyść zrobione";
"Close the tasks" = "Zamknij zadania";
"done" = "zrobione";
"not done" = "do zrobienia";
36 changes: 30 additions & 6 deletions Sources/FocusGuard/AppModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,20 @@ final class AppModel: ObservableObject {
@Published var nudgeText: String?
/// Frames still arrive but none could be scored for a while (face turned away, poor light): no figure beats a stale one.
@Published var focusStale = false
/// The settings and Spotify notes share one spot: opening one, from anywhere, puts the other away.
@Published var showSettings = false { didSet { if showSettings { showMusic = false } } }
/// The notes (settings, Spotify, tasks) share the room: opening one, from anywhere, puts the others away.
@Published var showSettings = false { didSet { if showSettings { showMusic = false; showTodos = false } } }
/// The Spotify note over the record player.
@Published var showMusic = false { didSet { if showMusic { showSettings = false } } }
@Published var showMusic = false { didSet { if showMusic { showSettings = false; showTodos = false } } }
/// The task list over the notebook. Closing it drops tasks whose text was erased.
@Published var showTodos = false {
didSet {
if showTodos { showSettings = false; showMusic = false }
else { todos.removeAll { $0.text.trimmingCharacters(in: .whitespaces).isEmpty } }
}
}
var noteOpen: Bool { showSettings || showMusic || showTodos }
/// Today's tasks, kept until the user clears the done ones.
@Published var todos: [Todo] { didSet { save() } }
/// ⌃⌥⌘F could not be registered (another app owns it); the settings note says so.
@Published var hotKeyTaken = false
/// The card's × put it away for a clean room; a click on the clock brings it back.
Expand Down Expand Up @@ -114,6 +124,7 @@ final class AppModel: ObservableObject {
largePanel = d.object(forKey: "largePanel") as? Bool ?? false
seenHint = d.object(forKey: "seenHint") as? Bool ?? false
cameraExplained = d.object(forKey: "cameraExplained") as? Bool ?? false
todos = d.data(forKey: "todos").flatMap { try? JSONDecoder().decode([Todo].self, from: $0) } ?? []
launchAtLogin = [.enabled, .requiresApproval].contains(SMAppService.mainApp.status)

spotify.objectWillChange.sink { [weak self] in self?.objectWillChange.send() }.store(in: &bag)
Expand Down Expand Up @@ -175,7 +186,8 @@ final class AppModel: ObservableObject {
/// Start with the settings on the card, after the one-time camera explanation.
func requestStart() {
showSettings = false
showMusic = false // the camera card must be seen, and the notes hide the card
showMusic = false
showTodos = false // the camera card must be seen, and the notes hide the card
if useCamera && !cameraExplained && AVCaptureDevice.authorizationStatus(for: .video) == .notDetermined {
showCameraWhy = true
} else {
Expand Down Expand Up @@ -234,6 +246,7 @@ final class AppModel: ObservableObject {
func clockTapped() {
showSettings = false
showMusic = false
showTodos = false
showCameraWhy = false
if cardHidden { cardHidden = false; return } // first click only brings the card back
if clock.phase.isRunning { togglePause() } else { requestStart() }
Expand All @@ -246,14 +259,16 @@ final class AppModel: ObservableObject {

func toggleSettings() {
showSettings.toggle()
showMusic = false
}

func toggleTodos() {
showTodos.toggle()
}

/// Click on the record player: what Spotify plays, with its controls. Asking now is what lets macOS show
/// its "control Spotify" prompt at a moment the user expects it.
func toggleMusic() {
showMusic.toggle()
showSettings = false
if showMusic { spotify.refresh(ask: true) }
}

Expand All @@ -277,6 +292,7 @@ final class AppModel: ObservableObject {
panelOpen = false
showSettings = false
showMusic = false
showTodos = false
showCameraWhy = false
}

Expand Down Expand Up @@ -408,9 +424,17 @@ final class AppModel: ObservableObject {
d.set(largePanel, forKey: "largePanel")
d.set(seenHint, forKey: "seenHint")
d.set(cameraExplained, forKey: "cameraExplained")
d.set(try? JSONEncoder().encode(todos), forKey: "todos")
}
}

/// One line on the task list in the notebook.
struct Todo: Codable, Identifiable, Equatable {
var id = UUID()
var text: String
var done = false
}

/// What the cat says. Each kind has several lines, and the same line never comes twice in a row.
@MainActor
enum Lines {
Expand Down
6 changes: 5 additions & 1 deletion Sources/FocusGuard/Debug.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import SwiftUI
enum DebugWindow {
static var window: NSWindow?

/// States: idle (default), hint, why, study, paused, sleep, settings, break, done, bubble, music, nomusic, nudge.
/// States: idle (default), hint, why, study, paused, sleep, settings, break, done, bubble, music, nomusic, nudge, todos.
/// `--large` draws the bigger panel.
static func configure(_ model: AppModel) {
model.persists = false // fixtures never touch the user's settings
Expand Down Expand Up @@ -42,6 +42,10 @@ enum DebugWindow {
}
if state == "paused" || state == "sleep" { model.togglePause(); model.pausedBySleep = state == "sleep" }
if state == "settings" { model.showSettings = true }
if state == "todos" {
model.todos = [Todo(text: "read chapter 4", done: true), Todo(text: "flashcards, 20 words"), Todo(text: "physics problem set")]
model.showTodos = true
}
if state == "nudge" { model.nudgeText = Lines.random(for: .lowFocus) }
if state == "break" { model.clock.tick(at: t0.addingTimeInterval(25 * 60 + 1)); model.timeShift = 27 * 60 }
if state == "done" { model.clock.tick(at: t0.addingTimeInterval(24 * 3600)); model.nudges = 2 }
Expand Down
20 changes: 16 additions & 4 deletions Sources/FocusGuard/DeskScene.swift
Original file line number Diff line number Diff line change
Expand Up @@ -158,12 +158,13 @@ struct DeskScene: View {
("sticky", OutlineShape(groups: [tod.props.noteLeft, tod.props.noteRight], smooth: false), "Settings"),
("mug", OutlineShape(groups: [tod.props.mug]), "Pause / resume"),
("clock", OutlineShape(groups: [tod.props.clock]), "Start, pause or resume a study session"),
("notebook", OutlineShape(groups: [tod.props.notebook], smooth: false), "Today's tasks"),
("cat", OutlineShape(groups: [tod.art.silhouette]), "Pet the cat")]
}

private func hover(at point: CGPoint?, _ tod: TimeOfDay) {
let frame = CGRect(x: 0, y: 0, width: W, height: H)
let notes = model.showSettings || model.showMusic // a note covers the room; its tap catcher takes the clicks
let notes = model.noteOpen // a note covers the room; its tap catcher takes the clicks
let name = notes ? nil : point.flatMap { p in targets(tod).first { $0.shape.path(in: frame).contains(p) }?.name }
guard name != hovered.value else { return }
if hovered.value != nil { NSCursor.pop() }
Expand Down Expand Up @@ -198,6 +199,7 @@ struct DeskScene: View {
Steam().place(Spots.steam).allowsHitTesting(false)
ClockDisplay().allowsHitTesting(false)

Hotspot(groups: [tod.props.notebook], smooth: false, lit: lit("notebook"), help: "Today's tasks", action: model.toggleTodos)
Hotspot(groups: [tod.props.clock], lit: lit("clock"), help: "Start, pause or resume a study session", action: model.clockTapped)
Hotspot(groups: [tod.props.mug], lit: lit("mug"), help: "Pause / resume", action: model.togglePause)
Hotspot(groups: [tod.props.noteLeft, tod.props.noteRight], smooth: false, lit: lit("sticky"), help: "Settings") {
Expand All @@ -206,7 +208,7 @@ struct DeskScene: View {
Hotspot(groups: [tod.props.record], lit: lit("record"), help: "Spotify: now playing", action: model.toggleMusic)

// A note takes the card's place; the card's × hides it until the clock is clicked.
if !model.showSettings && !model.showMusic && !(model.cardHidden && model.cardKey != "why") { SessionCard() }
if !model.noteOpen && !(model.cardHidden && model.cardKey != "why") { SessionCard() }

if model.showPreview && model.camera == .running {
Polaroid(session: model.cameraService.session).place(Spots.polaroid)
Expand All @@ -227,21 +229,31 @@ struct DeskScene: View {
.transition(.scale(scale: 0.8, anchor: .bottomLeading).combined(with: .opacity))
}

if model.showTodos {
Color.black.opacity(0.001).onTapGesture { model.showTodos = false }
TodoNote()
.frame(height: 240, alignment: .bottom) // grows upward from the notebook
.position(x: 372, y: 150)
.transition(.scale(scale: 0.8, anchor: .bottom).combined(with: .opacity))
}

CloseButton().position(x: 622, y: 52) // on the top-right corner of the room, above the notes' tap catchers
}
.frame(width: W, height: H)
.onContinuousHover(coordinateSpace: .local) { phase in
if case .active(let p) = phase { hover(at: p, tod) } else { hover(at: nil, tod) }
}
.onChange(of: model.showSettings || model.showMusic) { hover(at: nil, tod) }
.onChange(of: model.noteOpen) { hover(at: nil, tod) }
.onDisappear { hover(at: nil, tod) }
// The tooltip follows the object under the pointer (a per-hotspot .help would also go by frame).
.help(hovered.value.flatMap { name in targets(tod).first { $0.name == name }?.help } ?? "")
// The notebook explains itself, so it shows no tooltip.
.help(hovered.value.flatMap { name in name == "notebook" ? nil : targets(tod).first { $0.name == name }?.help } ?? "")
.fixedSize()
.coordinateSpace(name: "scene")
.animation(.easeInOut(duration: 1.2), value: tod)
.animation(.spring(duration: 0.3), value: model.showSettings)
.animation(.spring(duration: 0.3), value: model.showMusic)
.animation(.spring(duration: 0.3), value: model.showTodos)
.animation(.spring(duration: 0.3), value: model.showPreview && model.camera == .running)
.animation(.easeOut(duration: 0.25), value: model.cardKey)
.animation(.easeOut(duration: 0.25), value: model.cardHidden)
Expand Down
2 changes: 2 additions & 0 deletions Sources/FocusGuard/PanelController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ final class PanelController: NSObject {
private func escape() {
if model.showSettings { model.showSettings = false }
else if model.showMusic { model.showMusic = false }
else if model.showTodos { model.showTodos = false }
else if model.showCameraWhy { model.showCameraWhy = false }
else { hide() }
}
Expand All @@ -205,6 +206,7 @@ final class PanelController: NSObject {
case 53: escape(); return true
case 49: // space
if model.usingKeyboard && model.controlFocused { return false } // the focused control gets it
if model.showTodos { return false } // the task list is typed into
if event.isARepeat { return true } // holding space must not flip pause on and off
if model.showMusic { model.spotify.send(.playPause); return true } // the record sleeve: space plays or pauses Spotify
// Only the plain card answers space: a question or the note on top must not start or pause anything.
Expand Down
5 changes: 5 additions & 0 deletions Sources/FocusGuard/Silhouettes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import SwiftUI
/// The cat differs in every scene.
struct Props {
var clock: [CGPoint], mug: [CGPoint], noteLeft: [CGPoint], noteRight: [CGPoint], record: [CGPoint]
/// The open notebook in the middle of the desk.
var notebook: [CGPoint]
/// The dark LCD glass of the desk clock: top-left, top-right, bottom-right, bottom-left.
var lcd: [CGPoint]
/// Vinyl and label of the record player as ellipses: center, semi-axes, tilt in degrees.
Expand All @@ -23,13 +25,15 @@ struct Props {
noteLeft: pts("768,744,778,745,802,749,822,751,837,753,840,756,838,761,832,769,825,775,810,777,799,778,793,782,790,785,790,791,787,799,780,803,762,801,740,796,716,790,706,786,714,778,730,768,746,757,760,749"),
noteRight: pts("1176,770,1181,769,1195,768,1220,765,1240,761,1244,762,1262,774,1278,788,1268,793,1251,800,1234,804,1230,803,1226,796,1223,787,1220,783,1215,779,1209,777,1195,776,1180,774,1177,772"),
record: pts("81,649,91,637,110,629,174,613,260,597,317,586,329,587,334,599,346,641,360,684,374,733,377,744,400,749,406,753,431,760,469,766,517,776,560,780,564,799,564,821,561,827,557,843,517,867,460,900,383,941,374,943,357,938,260,916,174,894,167,893,166,867,168,827,146,829,131,824,124,807,103,727,88,685,81,660"),
notebook: pts("792,782,850,769,920,764,975,767,1002,777,1035,769,1100,765,1170,767,1212,779,1221,785,1285,922,1282,936,1190,936,1005,941,840,938,725,938,727,925"),
lcd: pts("548,704,711,683,711,727,549,752"),
vinyl: (CGPoint(x: 353, y: 809), 120, 39, -4), label: (CGPoint(x: 356, y: 804), 44.5, 15, -4.5),
tonearm: pts("376,748,401,748,403,753,413,761,437,780,447,782,456,791,456,806,450,808,447,796,437,790,397,766,383,766,376,762"))
static let morning: Props = {
var p = day
p.mug = pts("1324,668,1329,664,1342,659,1361,657,1385,656,1403,658,1417,661,1425,666,1427,676,1427,689,1434,690,1442,693,1448,701,1452,713,1452,728,1451,743,1447,755,1441,762,1434,765,1427,766,1427,772,1424,780,1415,786,1397,790,1379,791,1361,789,1344,785,1332,779,1326,771,1324,755,1323,713,1324,683")
p.noteLeft = pts("764,743,778,744,802,746,826,749,838,752,836,756,829,765,821,771,818,773,802,774,794,777,789,781,786,786,782,793,778,801,777,801,762,797,746,794,730,791,714,787,700,784,702,781,710,775,726,766,742,756,758,747")
p.notebook = pts("787,780,840,767,915,762,970,765,1000,772,1030,765,1090,762,1165,765,1208,774,1218,781,1282,922,1280,935,1190,932,1005,936,840,934,722,935,725,920")
p.noteRight = pts("1183,768,1188,768,1202,767,1220,761,1233,756,1237,758,1248,765,1262,775,1273,785,1273,787,1265,791,1244,797,1229,802,1226,800,1223,793,1219,784,1216,781,1212,778,1202,775,1188,773,1183,770")
return p
}()
Expand All @@ -39,6 +43,7 @@ struct Props {
noteLeft: pts("756,749,770,749,802,751,822,754,833,757,832,761,824,769,817,777,815,779,802,779,790,781,787,784,785,788,783,789,780,789,776,797,773,805,762,804,738,801,730,799,714,794,698,790,692,788,693,785,706,779,722,770,738,761,746,756"),
noteRight: pts("1173,771,1185,771,1202,770,1209,769,1220,766,1230,763,1240,761,1244,763,1262,775,1279,790,1280,792,1278,794,1262,799,1244,805,1232,809,1230,803,1227,796,1225,791,1222,787,1218,786,1212,780,1202,779,1188,778,1179,778,1176,775,1174,772"),
record: pts("59,651,67,640,84,631,150,616,230,600,301,586,313,589,319,601,330,641,344,690,359,739,360,749,381,749,390,759,430,767,454,765,495,771,528,778,544,781,549,783,551,806,552,825,551,837,544,842,495,872,446,901,413,918,380,929,377,941,373,947,344,946,341,941,156,899,147,884,146,876,146,836,144,829,124,833,116,833,107,821,84,740,72,700,62,668"),
notebook: pts("782,782,840,770,915,765,975,769,1002,780,1035,770,1100,766,1170,769,1214,784,1223,790,1287,930,1290,942,1190,942,1002,945,840,942,717,942,720,930"),
lcd: pts("533,704,702,682,701,730,534,754"),
vinyl: (CGPoint(x: 337, y: 811), 123, 40, -5), label: (CGPoint(x: 338, y: 806), 45, 13.5, -5.5),
tonearm: pts("359,751,383,750,389,756,399,763,421,783,431,787,441,799,443,807,436,810,430,801,424,796,414,790,387,773,373,767,359,767"))
Expand Down
Loading
Loading