use prelude
This commit is contained in:
parent
ceeb19d971
commit
254abfd803
@ -1,4 +1,4 @@
|
||||
version=0.26.1
|
||||
version=0.27.0
|
||||
assignment-operator=end-line
|
||||
break-cases=fit
|
||||
break-fun-decl=wrap
|
||||
|
||||
@ -15,6 +15,7 @@ depends: [
|
||||
"bos" {>= "0.2.0"}
|
||||
"directories"
|
||||
"fpath"
|
||||
"prelude"
|
||||
"scfg" {>= "0.2"}
|
||||
"odoc" {with-doc}
|
||||
]
|
||||
|
||||
@ -33,5 +33,6 @@
|
||||
(>= 0.2.0))
|
||||
directories
|
||||
fpath
|
||||
prelude
|
||||
(scfg
|
||||
(>= 0.2))))
|
||||
|
||||
28
src/ccbg.ml
28
src/ccbg.ml
@ -9,11 +9,12 @@ end
|
||||
module Project_dirs = Directories.Project_dirs (App_id)
|
||||
module User_dirs = Directories.User_dirs ()
|
||||
|
||||
let error msg =
|
||||
Format.eprintf "error: %s@." msg;
|
||||
exit 1
|
||||
let error = function
|
||||
| `Msg msg ->
|
||||
Fmt.epr "error: %s@." msg;
|
||||
exit 1
|
||||
|
||||
let some_or_fail msg = function None -> error msg | Some v -> v
|
||||
let some_or_fail msg = function None -> error (`Msg msg) | Some v -> v
|
||||
|
||||
let ok_or_fail r = Result.fold ~error ~ok:Fun.id r
|
||||
|
||||
@ -24,10 +25,13 @@ let config =
|
||||
some_or_fail "can't compute configuration directory path"
|
||||
Project_dirs.config_dir
|
||||
in
|
||||
let file_name = Filename.concat config_dir "config.scfg" in
|
||||
let config_dir = Fpath.of_string config_dir |> ok_or_fail in
|
||||
let file_name = Fpath.(config_dir / "config.scfg") in
|
||||
(* if the config file doesn't exist, then we use the empty configuration *)
|
||||
if not @@ Sys.file_exists file_name then []
|
||||
else ok_or_fail (Scfg.Parse.from_file file_name)
|
||||
match Bos.OS.File.exists file_name with
|
||||
| Error (`Msg e) -> Fmt.failwith "%s" e
|
||||
| Ok false -> []
|
||||
| Ok true -> ok_or_fail @@ Scfg.Parse.from_file file_name
|
||||
|
||||
let wallpaper_dir =
|
||||
match Scfg.Query.get_dir "wallpaper_dir" config with
|
||||
@ -41,7 +45,7 @@ let interval =
|
||||
| None -> 600
|
||||
| Some interval -> ok_or_fail (Scfg.Query.get_param_pos_int 0 interval)
|
||||
in
|
||||
Format.sprintf "%ds" interval
|
||||
Fmt.str "%ds" interval
|
||||
|
||||
let mode =
|
||||
match Scfg.Query.get_dir "mode" config with
|
||||
@ -51,11 +55,11 @@ let mode =
|
||||
| ("center" | "fill" | "fit" | "solid_color" | "stretch" | "tile") as mode
|
||||
->
|
||||
mode
|
||||
| invalid_mode -> Format.ksprintf error "invalid mode `%s`" invalid_mode )
|
||||
| invalid_mode -> Fmt.failwith "invalid mode `%s`" invalid_mode )
|
||||
|
||||
let wallpaper_files =
|
||||
match Bos.OS.Dir.contents (Fpath.v wallpaper_dir) with
|
||||
| Error (`Msg e) -> error e
|
||||
| Error e -> error e
|
||||
| Ok cnt -> (
|
||||
(* remove directories from the list... *)
|
||||
let cnt =
|
||||
@ -71,7 +75,7 @@ let wallpaper_files =
|
||||
cnt
|
||||
in
|
||||
match Array.of_list cnt with
|
||||
| [||] -> Format.ksprintf error "no wallpaper found in %s" wallpaper_dir
|
||||
| [||] -> Fmt.failwith "no wallpaper found in %s" wallpaper_dir
|
||||
| wallpaper_files -> wallpaper_files )
|
||||
|
||||
let random_wallpaper =
|
||||
@ -86,7 +90,7 @@ let rec new_wallpaper () =
|
||||
v "timeout" % interval % "swaybg" % "--mode" % mode % "--image"
|
||||
% random_wallpaper () )
|
||||
with
|
||||
| Ok () -> error "timeout failed"
|
||||
| Ok () -> error (`Msg "timeout failed")
|
||||
| Error (`Msg (_s : string)) ->
|
||||
(* timeout killed the swaybg process, we can launch a new one *)
|
||||
new_wallpaper ()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user