commit - 5ffaef7f71a51fd298f3f4138e382f06b05e6543
commit + ecfbb1d42fbd289d9c48e25806b7b377bf93acd2
blob - ab2dca1d89b75270959d211cc8b908fce094c895
blob + d9482f85fce0082d15897fadc13ceef873eefc08
--- defaults.c
+++ defaults.c
char *new_tab_url = NULL;
+int autosave = 20;
int dont_wrap_pre = 0;
int emojify_link = 1;
int enable_colors = 1;
emojify_link = !!val;
} else if (!strcmp(var, "set-title")) {
set_title = !!val;
+ } else if (!strcmp(var, "autosave")) {
+ autosave = val;
} else {
return 0;
}
blob - 8f9809f8b6c30ab5eac20e52cd6961288a4af83c
blob + 3bb7bee9fa10b99fdc77684477d6c89353acc874
--- defaults.h
+++ defaults.h
extern char *new_tab_url;
+extern int autosave;
extern int dont_wrap_pre;
extern int emojify_link;
extern int enable_colors;
blob - 0d715ad096cce9e10ddbd2e2eaab3528974e72ea
blob + 9aae5b14987ea75fa46c4e7429b368fad0180a0d
--- telescope.c
+++ telescope.c
static const char *opts = "Cc:hnT:v";
static struct imsgev *iev_fs, *iev_net;
+
+static struct event autosaveev;
struct tabshead tabshead = TAILQ_HEAD_INITIALIZER(tabshead);
struct proxylist proxies = TAILQ_HEAD_INITIALIZER(proxies);
const char *);
static int make_fs_request(struct tab *, int, const char *);
static int do_load_url(struct tab*, const char *, const char *);
+static void autosave_timer(int, short, void *);
static void parse_session_line(char *, const char **, uint32_t *);
static void load_last_session(void);
static pid_t start_child(enum telescope_process, const char *, int);
free_tab(struct tab *tab)
{
stop_tab(tab);
+
+ autosave_hook();
if (evtimer_pending(&tab->loadingev, NULL))
evtimer_del(&tab->loadingev);
}
ui_send_fs(IMSG_SESSION_END, 0, NULL, 0);
+}
+
+static void
+autosave_timer(int fd, short event, void *data)
+{
+ save_session();
+}
+
+/*
+ * Function to be called in "interesting" places where we may want to
+ * schedule an autosave (like on new tab or before loading an url.)
+ */
+void
+autosave_hook(void)
+{
+ struct timeval tv;
+
+ if (autosave <= 0)
+ return;
+
+ if (!evtimer_pending(&autosaveev, NULL)) {
+ tv.tv_sec = autosave;
+ tv.tv_usec = 0;
+
+ evtimer_add(&autosaveev, &tv);
+ }
}
/*
event_init();
+ /* Setup event handler for the autosave */
+ evtimer_set(&autosaveev, autosave_timer, NULL);
+
/* Setup event handlers for pipes to fs/net */
iev_fs->events = EV_READ;
event_set(&iev_fs->ev, iev_fs->ibuf.fd, iev_fs->events,
blob - 7a2377bbac51378de25faa9e84af9711308db2e4
blob + 756a7092d2927d064b0bb4d658654e5f5159672b
--- telescope.h
+++ telescope.h
void stop_tab(struct tab*);
void add_to_bookmarks(const char*);
void save_session(void);
+void autosave_hook(void);
/* tofu.c */
void tofu_init(struct ohash*, unsigned int, ptrdiff_t);
blob - 5b7da6d1130b55dc57f37640fa9daa167fbbef5a
blob + 8276391fde6c4cacf478669e857d4cfd80ffbc29
--- ui.c
+++ ui.c
load_url(tab, url, base, nohist);
return;
}
+
+ autosave_hook();
message("Loading %s...", url);
start_loading_anim(tab);
new_tab(const char *url, const char *base, struct tab *after)
{
struct tab *tab;
+
+ autosave_hook();
if ((tab = calloc(1, sizeof(*tab))) == NULL) {
event_loopbreak();