-
Notifications
You must be signed in to change notification settings - Fork 25
/
run.rkt
97 lines (86 loc) · 3.54 KB
/
run.rkt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#lang racket/base
;; run.rkt -- toplevel file to run the ActivityLog2 application
;; This file is part of ActivityLog2, an fitness activity tracker
;; Copyright (C) 2015, 2019, 2020, 2021, 2023 Alex Harsányi <AlexHarsanyi@gmail.com>
;;
;; This program is free software: you can redistribute it and/or modify it
;; under the terms of the GNU General Public License as published by the Free
;; Software Foundation, either version 3 of the License, or (at your option)
;; any later version.
;;
;; This program is distributed in the hope that it will be useful, but WITHOUT
;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
;; FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
;; more details.
(require framework/splash
racket/class
racket/cmdline
racket/draw
racket/lazy-require
"rkt/check-missing-modules.rkt"
"rkt/app-info.rkt")
;; Get a timestamp as early in the startup process as possible. We pass this
;; to main to log the time it takes us to start up.
(define early-start-timestamp (current-inexact-monotonic-milliseconds))
;; Check and inform the user that these packages need to be installed...
(check-missing-modules
the-application
tzinfo
tzgeolookup
data-frame
plot-container
gui-widget-mixins
map-widget
colormaps
geoid)
;; Start up a splash screen, rest of the application will be lazy-required
;; below. This will make the splash screen show up while the rest of the app
;; is loading.
(define font
(send the-font-list find-or-create-font 24 'default 'normal 'normal))
(define small-font
(send the-font-list find-or-create-font 8 'default 'normal 'normal))
(define color (make-color #x69 #x69 #x69))
(define message "ActivityLog2 is loading ...")
(define (draw-splash dc gauge max-gauge width height)
(send dc clear)
(send dc set-smoothing 'smoothed)
(send dc set-text-foreground color)
(let-values (((cw ch) (send dc get-size)))
(let-values (([w h x y] (send dc get-text-extent message font #t)))
(let ((msg-x (- (/ cw 2) (/ w 2)))
(msg-y (- (/ ch 2) (/ h 2))))
(send dc set-font font)
(send dc draw-text message msg-x msg-y)))
(let ((version (string-append "Version " (app-version))))
(let-values (([w h x y] (send dc get-text-extent version small-font #t)))
(let ((msg-x 5)
(msg-y (- ch h 5)))
(send dc set-font small-font)
(send dc draw-text version msg-x msg-y))))))
;; Allow the user to specify an optional file on the command line. If
;; present, we use it as the initial database file.
(define cmdline-db-file
(command-line
#:program "ActivityLog2"
#:args filenames
(cond ((null? filenames)
;; Start the application with no course selected
#f)
((> (length filenames) 1)
(fprintf (current-error-port) "Only one database file can be specified in on the command line~%")
(exit 1))
(else
(let ([db-file (car filenames)])
(unless (file-exists? db-file)
(fprintf (current-error-port) "Database file ~a does not exist~%" db-file)
(exit 1))
db-file)))))
;; Remove the progress bar. The progress works fine while running the
;; application using racket, but does not work (shows no progress) when the
;; application is compiled into an executable...
(set-splash-progress-bar?! #f)
(start-splash (vector draw-splash 420 120) "ActivityLog2" 100)
(collect-garbage 'incremental)
(lazy-require ("rkt/main.rkt" (main)))
(main early-start-timestamp cmdline-db-file)