Skip to content

Commit

Permalink
Sync scanner will notify the user whe the sync queue is cleared
Browse files Browse the repository at this point in the history
  • Loading branch information
choptastic committed Jul 11, 2022
1 parent df1156d commit e4faab4
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/sync_scanner.erl
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
start_link/0,
rescan/0,
info/0,
queue_size/0,
enable_patching/0,
pause/0,
unpause/0
Expand Down Expand Up @@ -73,7 +74,8 @@ rescan() ->
_ ->
io:format("Listening on fsevents...~n"),
ok
end.
end,
gen_server:cast(?SERVER, notify_when_empty).

unpause() ->
gen_server:cast(?SERVER, unpause),
Expand All @@ -90,6 +92,9 @@ info() ->
gen_server:cast(?SERVER, info),
ok.

queue_size() ->
gen_server:call(?SERVER, queue_size).

set_growl(T) when ?LOG_OR_GROWL_ON(T) ->
sync_utils:set_env(growl,all),
sync_notify:growl_success("Sync","Desktop Notifications Enabled"),
Expand Down Expand Up @@ -135,10 +140,25 @@ init([]) ->
sync_method = sync_utils:get_env(sync_method, scanner)
}}.

handle_call(queue_size, _From, State) ->
Size = queue:len(State#state.action_queue),
{reply, Size, State};
handle_call(_Request, _From, State) ->
Reply = ok,
{reply, Reply, State}.

handle_cast(notify_when_empty, State) ->
case queue:len(State#state.action_queue) of
0 ->
io:format("~nSync Queue is empty. Sync is ready and actively watching for changes...~n"),
NewTimers = proplists:delete(notify_when_empty, State#state.timers),
NewState = State#state{timers=NewTimers},
{noreply, NewState};
_ ->
NewTimers = schedule_cast(notify_when_empty, 100, State#state.timers),
NewState = State#state{timers=NewTimers},
{noreply, NewState}
end;
handle_cast(pause, State) ->
{noreply, State#state {paused=true}};
handle_cast(unpause, State) ->
Expand Down

0 comments on commit e4faab4

Please sign in to comment.