Skip to content
This repository has been archived by the owner on Jan 11, 2023. It is now read-only.

start working on themes #479

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open

start working on themes #479

wants to merge 17 commits into from

Conversation

bilelmoussaoui
Copy link
Contributor

@bilelmoussaoui bilelmoussaoui commented May 13, 2017

Should fix #299 #240 once it's ready
This shouldn't be merged yet, more commits are coming this evening!


public FeedReader.ArticleTheme() {
// Local themes
string theme_dir = GLib.Environment.get_home_dir() + "/.feedreader/themes/";
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm pretty sure you can't use this path with flatpaks. Also there is already $HOME/.local/feedreader.
You can access that via GLib.Environment.get_user_data_dir() + "/feedreader/"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will fix that :)

@bilelmoussaoui
Copy link
Contributor Author

bilelmoussaoui commented May 13, 2017

@jangernert Everything should work fine, except a small issue that i couldn't figure out (little tired :/)
The installed themes are correctly detected on both locations global and local one, the fallback theme (saved on gresource works fine too), but the length of the static variable themes on ArticleTheme is always empty (i've added some printing on my local machine and the themes are correctly detected.. but not added to the static Variable)
My Vala skills aren't that good as yours, can you take a look?
Thanks!
Edit: already fixed it on my local machine, i will push that to themes branch with other fixes :)

@bilelmoussaoui bilelmoussaoui added this to the 2.2 milestone May 13, 2017
Copy link
Collaborator

@brendanlong brendanlong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ability for users to load third-party themes looks pretty cool!

I took a look through the pull request and thought you might be interested in some feedback. Let me know if any of this is unhelpful.

}
}
}catch(Error err){
corrupted_theme = true;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be good to log the error here for debugging purposes.

while ((name = theme_dir.read_name()) != null){
if (name == "theme.json"){
corrupted_theme = false;
string path = Path.build_filename(theme_path, name);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like we're reading through the directory but only doing something with one file. Could we replace this while loop with:

// etc.
string author = "";
try {
  string path = Path.build_filename(theme_path, "theme.json");
  Json.Parser parser = new Json.Parser();
  // etc.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code here is still not complete, i would like to check if there's an article.html & style.css file too. Otherwise the theme will be correct. But yeah it's better to use this 👍

}
}
}catch(GLib.FileError err){

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Logging something here would be nice too.

using Gee;

public class FeedReader.ArticleTheme {
private static ArrayList<HashMap<string, string>> ? themes = null;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider making the ThemeInfo into a struct:

public struct ThemeInfo {
  string name;
  string author;
  bool is_corrupted;
  // etc.
}

private static ArrayList<ThemeInfo>? themes = null;
// etc.

Since we know the contents of the map, using a struct is more efficient and easier to work with.

You might also consider making this a map from theme name to theme info so we can more easily lookup themes:

private static HashMap<string, ThemeInfo>? = null;

public static HashMap<string, ThemeInfo> getThemes() { ... }

public static ThemeInfo? getTheme(string name)
{
  var themes = getThemes();
  if (!themes.has(name))
    return null;
  return themes.get(name);
}

public static bool exists(string name)
{
  return getTheme(name) != null;
}

string path = Path.build_filename(location, name);
if(FileUtils.test(path, FileTest.IS_DIR)){
var themeInfo = getThemeInfo(path);
if (themeInfo.has_key("corrupted") == false){
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is the only thing we use "corrupted" for, consider just returning null when the theme is corrupt.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah much better!

}
}
} catch (GLib.FileError err){

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One more case where logging would be nice (or just don't catch the exception).

src/UtilsUI.vala Outdated
string css = "";
try
{
if (ArticleTheme.isExists(theme) == false) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be simpler to do if (!ArtistTheme.isExists(theme))

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Javascript habits :p

}
}

public static bool isExists(string theme_location){
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer if this was named exists()

src/UtilsUI.vala Outdated
string css_id = "$CSS";
int css_pos = article.str.index_of(css_id);
article.erase(css_pos, css_id.length);
article.insert(css_pos, css);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would string.replace() work here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was used before by @jangernert, i will see what can i do. But i was going to remove including the CSS file here as it's not needed. it's even better to just load the html file, this way third-party themes could contain images, fonts that we shouldn't load by ourselves (vala code)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

<div id="title" target="_blank" style="font-size:$LARGESIZEpt;"><a href="$URL">$TITLE</a></div>
<div id="author" style="font-size:$SMALLSIZEpt;">
$AUTHOR
</div>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be make sense to use more semantic tags like <h2> instead of <div>?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The theme isn't ready, it's just an example of how things works 👍
Once the Vala code is ready, i will work on two/three themes that will replace the default ones

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh cool, that makes sense :)

@bilelmoussaoui
Copy link
Contributor Author

@brendanlong Thanks for the review again! I've pushed few modifications on my latest commit :)

public class FeedReader.ArticleTheme {
private static ArrayList<HashMap<string, string>> ? themes = null;
private static HashMap<string, ThemeInfo?> ? themes = null;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is the second type argument ThemeInfo?? Are there cases where we would want them theme to null?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not at all, it's just valac complained about not using themeInfo?

@bilelmoussaoui
Copy link
Contributor Author

@jangernert Can you see if everything is alright for you? 👍

@jangernert
Copy link
Owner

Just wanted to mention the cmake files ^^
As default we should imo straight up port the current default theme and just strip out all the color variants

@bilelmoussaoui
Copy link
Contributor Author

@jangernert I will do that :)

@jangernert
Copy link
Owner

Code seems fine and worked flawlessly for me. The only thing missing is to have the 2 themes on the same quality level as the current themes. Otherwise it will be a downgrade from a user point of view.

@bilelmoussaoui
Copy link
Contributor Author

Yeah, lt's what i will work on those days :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
3 participants