@@ 147,10 147,13 @@ downloadAssets session mimes (StyleAssets _ assets) = do
Dir.removeDirectoryRecursive dir `catch` ignoreError -- Clear cache.
Dir.createDirectoryIfMissing True dir
- fetchURLs session mimes assets $ filterMIMEs mimes $ saveDownload nullURI dir
+ -- Ensure core audio cues are saved with predictable names for UI layer to use.
+ let assets' = nub $ (u "about:link.wav":u "about:bulletpoint.wav":assets)
+ fetchURLs session mimes assets' $ filterMIMEs mimes $ saveDownload nullURI dir
where
ignoreError :: IOError -> IO ()
ignoreError _ = return ()
+ u = fromMaybe (URI "about:" Nothing "invalid" "" "") . parseAbsoluteURI
filterMIMEs mimes cb download@(_, mime, _)
| mime `elem` mimes = cb download
@@ 178,3 181,7 @@ c_renderDoc c_session c_page rewriteURLs = do
B.toStrict ssml `useAsCString` \cstr -> do
str <- peekCString cstr
newCString str
+
+foreign export ccall c_cachedir :: IO CString
+
+c_cachedir = Dir.getXdgDirectory Dir.XdgCache "rhapsode" >>= newCString
@@ 27,7 27,7 @@ void *c_fetchURL(struct session*, char*, struct page*, char*);
//struct page **c_fetchURLs(struct session*, struct page*, char**); // FIXME segfaults.
void c_freePage(struct page*);
-void c_enableLogging(struct session*);
+struct session *c_enableLogging(struct session*);
void c_writeLog(char*, struct session*);
char *c_renderDoc(struct session*, struct page*, _Bool);
@@ 35,6 35,8 @@ char **c_extractLinks(struct page*);
char **c_docLinksAndRendering(struct session*, struct page*, _Bool); // FIXME segfaults.
int c_ssmlHasMark(char*, char*);
+char *c_lastVisited(char*);
+
/* espeak-ng integration. Based on the espeak-ng command source code. */
SNDFILE *fd_wav = NULL;
char *path_wav = NULL;
@@ 204,10 206,12 @@ char *select_link(char **links, char *command) {
// Pass 3: Retrieve answer
for (int i = 0; strcmp(links[i], " ") != 0; i += 3) {
- if (score < levenshtein_distance(command, links[i]) &&
- score < levenshtein_distance(command, links[i+1]) &&
- score < levenshtein_distance(command, links[i+2])) continue;
- if (num_matches == 1) return links[i+2];
+ if (command[0] != '\0') {// "" to read entire link table...
+ if (score < levenshtein_distance(command, links[i]) &&
+ score < levenshtein_distance(command, links[i+1]) &&
+ score < levenshtein_distance(command, links[i+2])) continue;
+ if (num_matches == 1) return links[i+2];
+ }
// Communicate
printf("%s\t%s\t%s\n", links[i+2], links[i], links[i+1]);
@@ 429,6 433,11 @@ int main(int argc, char **argv) {
if (use_espeak) speak_err = speak_initialize();
char *ssml, **links, *uri;
+ if (optind >= argc) {
+ // No URLs specified, restore previous session or goto about:welcome
+ uri = c_lastVisited("about:welcome");
+ goto read_uri;
+ }
for (int i = optind; i < argc; i++) {
uri = argv[i];
@@ 439,7 448,7 @@ read_uri:
#endif
else printf("%s\n", argv[i]);
- if (logpath != NULL) c_enableLogging(session);
+ if (logpath != NULL) session = c_enableLogging(session);
struct page *page = c_fetchURL(session, mimes, referer, uri);
ssml = c_renderDoc(session, page, use_espeak);
@@ 448,6 457,7 @@ read_uri:
if (logpath != NULL) c_writeLog(logpath, session);
if (fd_ssml != NULL) fprintf(fd_ssml, "%s\n", ssml);
+ if (read_keyboard && strcmp(uri, "about:welcome")) select_link(links, "");
if (fd_links != NULL) write_links(fd_links, links);
if (use_espeak & speak_err == 0) speak(ssml, "main", NULL);
#ifdef WITH_SPEECHD