-
Notifications
You must be signed in to change notification settings - Fork 89
start working on themes #479
base: master
Are you sure you want to change the base?
Conversation
… PREFIX/ArticleView instead of grsource
src/ArticleTheme.vala
Outdated
|
||
public FeedReader.ArticleTheme() { | ||
// Local themes | ||
string theme_dir = GLib.Environment.get_home_dir() + "/.feedreader/themes/"; |
There was a problem hiding this comment.
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/"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will fix that :)
@jangernert Everything should work fine, except a small issue that i couldn't figure out (little tired :/) |
There was a problem hiding this 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.
src/ArticleTheme.vala
Outdated
} | ||
} | ||
}catch(Error err){ | ||
corrupted_theme = true; |
There was a problem hiding this comment.
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.
src/ArticleTheme.vala
Outdated
while ((name = theme_dir.read_name()) != null){ | ||
if (name == "theme.json"){ | ||
corrupted_theme = false; | ||
string path = Path.build_filename(theme_path, name); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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){ | ||
|
There was a problem hiding this comment.
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.
src/ArticleTheme.vala
Outdated
using Gee; | ||
|
||
public class FeedReader.ArticleTheme { | ||
private static ArrayList<HashMap<string, string>> ? themes = null; |
There was a problem hiding this comment.
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;
}
src/ArticleTheme.vala
Outdated
string path = Path.build_filename(location, name); | ||
if(FileUtils.test(path, FileTest.IS_DIR)){ | ||
var themeInfo = getThemeInfo(path); | ||
if (themeInfo.has_key("corrupted") == false){ |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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){ | ||
|
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Javascript habits :p
src/ArticleTheme.vala
Outdated
} | ||
} | ||
|
||
public static bool isExists(string theme_location){ |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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> |
There was a problem hiding this comment.
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>
?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 :)
@brendanlong Thanks for the review again! I've pushed few modifications on my latest commit :) |
src/ArticleTheme.vala
Outdated
public class FeedReader.ArticleTheme { | ||
private static ArrayList<HashMap<string, string>> ? themes = null; | ||
private static HashMap<string, ThemeInfo?> ? themes = null; |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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?
@jangernert Can you see if everything is alright for you? 👍 |
1171648
to
c147082
Compare
Just wanted to mention the cmake files ^^ |
@jangernert I will do that :) |
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. |
Yeah, lt's what i will work on those days :) |
50b6d96
to
879f9c3
Compare
Should fix #299 #240 once it's ready
This shouldn't be merged yet, more commits are coming this evening!