Skip to content

Commit

Permalink
Automatically save the chapter instead of just when closed
Browse files Browse the repository at this point in the history
  • Loading branch information
DisableGraphics committed Apr 28, 2022
1 parent 6066304 commit e43755c
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@ int position{-1};
//Variables to know different details
std::string file{""}, folder{""}, saveFile;

void save()
{
std::ofstream chapter_file;
chapter_file.open(saveFile);

chapter_file << file;
chapter_file.close();
}

std::vector<std::string> getFoldersInFolder(std::string folda)
{
std::vector<std::string> toreturn;
Expand Down Expand Up @@ -290,6 +299,7 @@ void next_chapter(WebKitWebView * webView, Gtk::HeaderBar * titleBar)
titleBar->set_subtitle(getMangaName() + " - " + getChapterName());
gtk_widget_grab_focus(GTK_WIDGET(webView));
}
save();
}
else if(position == -2)
{
Expand Down Expand Up @@ -329,6 +339,7 @@ void previous_chapter(WebKitWebView * webView, Gtk::HeaderBar * titleBar)
titleBar->set_subtitle(getMangaName() + " - " + getChapterName());
gtk_widget_grab_focus(GTK_WIDGET(webView));
}
save();
}
else if (position == -2)
{
Expand Down Expand Up @@ -373,6 +384,7 @@ void open(WebKitWebView * webview, Gtk::HeaderBar * titlebar)
open_chapter(webview);
titlebar->set_subtitle(getMangaName() + " - " + getChapterName());
gtk_widget_grab_focus(GTK_WIDGET(webview));
save();
break;
}
}
Expand Down Expand Up @@ -440,7 +452,8 @@ void delete_manga(WebKitWebView * webview, Gtk::HeaderBar * headbar, Gtk::Popove
load_homepage(webview);
}
}
}
save();
}
}

menu->hide();
Expand All @@ -454,6 +467,8 @@ void close_manga(WebKitWebView * webView, Gtk::HeaderBar * headbar, Gtk::Popover
position = -1;
headbar->set_subtitle("");

save();

load_homepage(webView);
menu->hide();
}
Expand All @@ -462,11 +477,7 @@ void close_manga(WebKitWebView * webView, Gtk::HeaderBar * headbar, Gtk::Popover
bool on_close(GdkEventAny* event, Glib::RefPtr<Gtk::Application> app)
{
//Saves the chapter in chapter_file
std::ofstream chapter_file;
chapter_file.open(saveFile);

chapter_file << file;
chapter_file.close();
save();

//Deletes unnecesary folders and files
std::filesystem::remove_all((std::string)std::filesystem::current_path() + "/tmp/");
Expand Down

0 comments on commit e43755c

Please sign in to comment.