Skip to content

Commit

Permalink
move fetching icon into a separate thread
Browse files Browse the repository at this point in the history
  • Loading branch information
artemanufrij committed Feb 11, 2018
1 parent 4cd8bfb commit 3595041
Showing 1 changed file with 95 additions and 80 deletions.
175 changes: 95 additions & 80 deletions src/Widgets/Views/Editor.vala
Original file line number Diff line number Diff line change
Expand Up @@ -213,102 +213,117 @@ namespace Webpin.Widgets.Views {
grab_timer = Timeout.add (
500,
() => {
if (tmp_icon_file != "" ) {
FileUtils.remove (tmp_icon_file);
tmp_icon_file = "";
}
new Thread<void*> (
"grab_color_and_icon",
() => {
if (tmp_icon_file != "" ) {
FileUtils.remove (tmp_icon_file);
tmp_icon_file = "";
}

var url = app_url_entry.text;
var session = new Soup.Session.with_options ("user_agent", "WebPin/0.1.0 (https://github.com/artemanufrij/webpin)");
session.timeout = 2;
var msg = new Soup.Message ("GET", url);
session.send_message (msg);
var url = app_url_entry.text;
var session = new Soup.Session.with_options ("user_agent", "WebPin/0.1.0 (https://github.com/artemanufrij/webpin)");
session.timeout = 2;
var msg = new Soup.Message ("GET", url);
session.send_message (msg);

if (msg.status_code == 200) {
var body = (string)msg.response_body.data;
if (msg.status_code == 200) {
var body = (string)msg.response_body.data;

Regex regex = null;
try {
regex = new Regex ("(?<=<meta name=\"theme-color\" content=\")#[0-9a-fA-F]{6}");
} catch (Error err) {
warning (err.message);
}
Regex regex = null;
try {
regex = new Regex ("(?<=<meta name=\"theme-color\" content=\")#[0-9a-fA-F]{6}");
} catch (Error err) {
warning (err.message);
}

MatchInfo match_info = null;
if (regex != null && regex.match (body, 0, out match_info)) {
var result = match_info.fetch (0);
Gdk.RGBA return_value = {0, 0, 0, 1};
if (return_value.parse (result)) {
primary_color_button.set_rgba (return_value);
}
}
MatchInfo match_info = null;
if (regex != null && regex.match (body, 0, out match_info)) {
var result = match_info.fetch (0);
Gdk.RGBA return_value = {0, 0, 0, 1};
if (return_value.parse (result)) {
Idle.add (
() => {
primary_color_button.set_rgba (return_value);
return false;
});
}
}

if (tmp_icon_file == "") {
try {
regex = new Regex ("(?<=\"fluid-icon\" href=\")[/\\w\\.:\\-]*");
if (regex.match (body, 0, out match_info)) {
var icon_path = format_icon_path (url, match_info.fetch (0));
download_icon (icon_path);
if (tmp_icon_file == "") {
try {
regex = new Regex ("(?<=\"fluid-icon\" href=\")[/\\w\\.:\\-]*");
if (regex.match (body, 0, out match_info)) {
var icon_path = format_icon_path (url, match_info.fetch (0));
download_icon (icon_path);
}
} catch (Error err) {
warning (err.message);
}
}
} catch (Error err) {
warning (err.message);
}
}

if (tmp_icon_file == "") {
try {
regex = new Regex ("(rel=\"icon\").*href=\"([\\-/\\w]*64.png)");
if (regex.match (body, 0, out match_info)) {
var icon_path = format_icon_path (url, match_info.fetch (match_info.get_match_count () - 1));
download_icon (icon_path);
if (tmp_icon_file == "") {
try {
regex = new Regex ("(rel=\"icon\").*href=\"([\\-/\\w]*64.png)");
if (regex.match (body, 0, out match_info)) {
var icon_path = format_icon_path (url, match_info.fetch (match_info.get_match_count () - 1));
download_icon (icon_path);
}
} catch (Error err) {
warning (err.message);
}
}
} catch (Error err) {
warning (err.message);
}
}

if (tmp_icon_file == "") {
try {
regex = new Regex ("(rel=\"icon\").*href=\"([\\-/\\w]*96.png)");
if (regex.match (body, 0, out match_info)) {
var icon_path = format_icon_path (url, match_info.fetch (match_info.get_match_count () - 1));
download_icon (icon_path);
if (tmp_icon_file == "") {
try {
regex = new Regex ("(rel=\"icon\").*href=\"([\\-/\\w]*96.png)");
if (regex.match (body, 0, out match_info)) {
var icon_path = format_icon_path (url, match_info.fetch (match_info.get_match_count () - 1));
download_icon (icon_path);
}
} catch (Error err) {
warning (err.message);
}
}
} catch (Error err) {
warning (err.message);
}
}

if (tmp_icon_file == "") {
try {
regex = new Regex ("(\"apple-touch-icon\").*href=\"([\\-/\\w]*.png)");
if (regex.match (body, 0, out match_info)) {
var icon_path = format_icon_path (url, match_info.fetch (match_info.get_match_count () - 1));
download_icon (icon_path);
if (tmp_icon_file == "") {
try {
regex = new Regex ("(\"apple-touch-icon\").*href=\"([\\-/\\w]*.png)");
if (regex.match (body, 0, out match_info)) {
var icon_path = format_icon_path (url, match_info.fetch (match_info.get_match_count () - 1));
download_icon (icon_path);
}
} catch (Error err) {
warning (err.message);
}
}
} catch (Error err) {
warning (err.message);
}
}

if (tmp_icon_file == "") {
try {
regex = new Regex ("(?<=\"mask-icon\" href=\")[/\\w\\.:\\-]*");
if (regex.match (body, 0, out match_info)) {
var icon_path = format_icon_path (url, match_info.fetch (0));
download_icon (icon_path);
if (tmp_icon_file == "") {
try {
regex = new Regex ("(?<=\"mask-icon\" href=\")[/\\w\\.:\\-]*");
if (regex.match (body, 0, out match_info)) {
var icon_path = format_icon_path (url, match_info.fetch (0));
download_icon (icon_path);
}
} catch (Error err) {
warning (err.message);
}
}

if (tmp_icon_file != "") {
Idle.add (
() => {
icon_name_entry.set_text (tmp_icon_file);
return false;
});
}
} catch (Error err) {
warning (err.message);
}
}
msg.dispose ();
session.dispose ();

return null;
});

if (tmp_icon_file != "") {
icon_name_entry.set_text (tmp_icon_file);
}
}
msg.dispose ();
session.dispose ();

reset_grab_color_and_icon ();
return false;
Expand Down

0 comments on commit 3595041

Please sign in to comment.