Skip to content

Commit

Permalink
feat: support custom block url redirect
Browse files Browse the repository at this point in the history
  • Loading branch information
iloveitaly committed Dec 24, 2023
1 parent 3465711 commit 1f53aa8
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 9 deletions.
3 changes: 1 addition & 2 deletions Sources/hyper-focus/action_handler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,7 @@ enum ActionHandler {
}

static func blockTab(_ activeTab: BrowserTab?) {
// TODO: allow redirect to be configured
let redirectUrl: String? = "about:blank"
let redirectUrl = scheduleManager!.configuration.blocked_redirect_url ?? "about:blank"

// TODO: I don't know how to more elegantly unwrap the enum here...
switch activeTab {
Expand Down
11 changes: 7 additions & 4 deletions Sources/hyper-focus/hyper_focus.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,11 @@ struct Configuration: Codable {

var initial_wake: String?
var wake: String?
var blocked_redirect_url: String?
var schedule: [ScheduleItem]
}

var scheduleManager: ScheduleManager?
var systemObserver: SystemObserver?
var sleepWatcher: SleepWatcher?
var apiServer: ApiServer?
Expand All @@ -67,10 +69,11 @@ public enum focus_app {
return
}

let scheduleManager = ScheduleManager()
systemObserver = SystemObserver(scheduleManager: scheduleManager)
sleepWatcher = SleepWatcher(scheduleManager: scheduleManager)
apiServer = ApiServer(scheduleManager: scheduleManager)
// NOTE this is hte main entrypoint of the application
scheduleManager = ScheduleManager()
systemObserver = SystemObserver(scheduleManager: scheduleManager!)
sleepWatcher = SleepWatcher(scheduleManager: scheduleManager!)
apiServer = ApiServer(scheduleManager: scheduleManager!)
}
}

Expand Down
7 changes: 4 additions & 3 deletions Sources/hyper-focus/schedule_manager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class ScheduleManager {
var overrideSchedule: Configuration.ScheduleItem?
var plannedSchedule: Configuration.ScheduleItem?

let BLANK_SCHEDULE = Configuration.ScheduleItem()
let BLANK_PAUSE_SCHEDULE = Configuration.ScheduleItem()

init(_ config: Configuration? = nil) {
configuration = config ?? ConfigurationLoader.loadConfiguration()
Expand Down Expand Up @@ -128,9 +128,10 @@ class ScheduleManager {
}

func getSchedule() -> Configuration.ScheduleItem? {
// TODO: weird to have this check vs in the check poller, but we need a conditional to return BLANK_SCHEDULE
// TODO: weird to have this check vs in the check poller, but we need a conditional to return BLANK_PAUSE_SCHEDULE
if endPause != nil, Date() < endPause! {
return BLANK_SCHEDULE
// if we are in a pause, return a blank schedule
return BLANK_PAUSE_SCHEDULE
} else {
endPause = nil
}
Expand Down
3 changes: 3 additions & 0 deletions schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
"wake": {
"type": "string"
},
"blocked_redirect_url": {
"type": "string"
},
"schedule": {
"type": "array",
"items": {
Expand Down

0 comments on commit 1f53aa8

Please sign in to comment.