-
-
Notifications
You must be signed in to change notification settings - Fork 289
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Code cleanup: Flow.Launcher.Plugin.BrowserBookmark #2652
Code cleanup: Flow.Launcher.Plugin.BrowserBookmark #2652
Conversation
This comment has been minimized.
This comment has been minimized.
private BrowserType browserType = BrowserType.Chromium; | ||
private string _name; | ||
private string _dataDirectoryPath; | ||
private BrowserType _browserType = BrowserType.Chromium; |
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.
Add _
to private property name to be consistent with other private property names
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 suppose you want to say private field (they are different in c#).
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, sorry, I meant field, not property.
OnPropertyChanged(nameof(DataDirectoryPath)); | ||
} | ||
_name = value; | ||
OnPropertyChanged(); |
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.
BaseModel
class, which this class extends, has the [CallerMemberName]
attribute on this argument, so there's no need to pass it manually.
@@ -63,7 +63,6 @@ | |||
<StackPanel Margin="26,0,26,0"> | |||
<StackPanel Margin="0,0,0,12"> | |||
<TextBlock | |||
Grid.Column="0" |
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 a child of a Grid, this attribute doesn't do anything.
private void Others_Click(object sender, RoutedEventArgs e) | ||
{ | ||
CustomBrowsersList.Visibility = CustomBrowsersList.Visibility switch | ||
{ | ||
EditSelectedCustomBrowser(); | ||
} | ||
Visibility.Collapsed => Visibility.Visible, | ||
_ => Visibility.Collapsed | ||
}; | ||
} |
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.
In my opinion this is a little easier to read than the original if/else. What do you think?
This comment has been minimized.
This comment has been minimized.
private const string queryAllBookmarks = @"SELECT moz_places.url, moz_bookmarks.title | ||
FROM moz_places | ||
INNER JOIN moz_bookmarks ON ( | ||
private const string QueryAllBookmarks = """ |
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.
Rename private const
to start with a capital letter. Same with DbPathFormat
.
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 feel like this add newline that does not exist before? have you tested whether it still worked?
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.
This does add a linebreak at the and and also reduce indenting. Luckily, SQL is not a language with significant whitespace, so I don't think it matters, and I think a raw string literal ("""
) visually conveys the idea that the string is multiline much better than a verbatim string (@"
). I did test if it works: I added this text when reading from the database:
return reader | ||
.Select( | ||
x => new Bookmark( | ||
x["title"] is DBNull ? string.Empty : x["title"].ToString(), | ||
x["url"].ToString() | ||
) | ||
) | ||
.ToList(); |
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 think it's much more readable when every method call in the chain is on its own line. I'd like to hear your opinion.
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 I think it's fine. Though for me, I majorly like putting the first .Select
on the same line...though I don't know how others will think about this. @Flow-Launcher/team
// get firefox default profile directory from profiles.ini | ||
using var sReader = new StreamReader(profileIni); | ||
var ini = sReader.ReadToEnd(); |
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.
Replaced using
block with the using
declaration. Since there's no block anymore, it's no longer necessary to have ini
declared outside.
StartWithLastProfile=1 | ||
Version=2 | ||
*/ | ||
var lines = ini.Split("\r\n").ToList(); |
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.
This does exactly the same thing as before, but with less code.
*/ | ||
var lines = ini.Split("\r\n").ToList(); | ||
|
||
var defaultProfileFolderNameRaw = lines.FirstOrDefault(x => x.Contains("Default=") && x != "Default=1") ?? string.Empty; |
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.
Where
call is redundant because FirstOrDefault
also can accept a function for filtering.
return _cachedBookmarks | ||
.Select( | ||
c => new Result | ||
{ | ||
context.API.OpenUrl(c.Url); | ||
Title = c.Name, | ||
SubTitle = c.Url, | ||
IcoPath = @"Images\bookmark.png", | ||
Score = BookmarkLoader.MatchProgram(c, param).Score, | ||
Action = _ => | ||
{ | ||
_context.API.OpenUrl(c.Url); | ||
|
||
return true; | ||
}, | ||
ContextData = new BookmarkAttributes | ||
{ | ||
Url = c.Url | ||
return true; | ||
}, | ||
ContextData = new BookmarkAttributes { Url = c.Url } | ||
} | ||
}).Where(r => r.Score > 0); | ||
return returnList.ToList(); | ||
} | ||
else | ||
{ | ||
return cachedBookmarks.Select(c => new Result() | ||
{ | ||
Title = c.Name, | ||
SubTitle = c.Url, | ||
IcoPath = @"Images\bookmark.png", | ||
Score = 5, | ||
Action = _ => | ||
{ | ||
context.API.OpenUrl(c.Url); | ||
return true; | ||
}, | ||
ContextData = new BookmarkAttributes | ||
) | ||
.Where(r => r.Score > 0) | ||
.ToList(); |
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.
Same as in FirefoxBookmarkReader.cs
: I think it's much more readable when every chained method call is in a separate line, and I'd like to hear your opinion on this. Also, the variable is unnecessary here since it immediately returns, so I just continued the chain of method calls.
This comment has been minimized.
This comment has been minimized.
private const string queryAllBookmarks = @"SELECT moz_places.url, moz_bookmarks.title | ||
FROM moz_places | ||
INNER JOIN moz_bookmarks ON ( | ||
private const string QueryAllBookmarks = """ |
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 feel like this add newline that does not exist before? have you tested whether it still worked?
return reader | ||
.Select( | ||
x => new Bookmark( | ||
x["title"] is DBNull ? string.Empty : x["title"].ToString(), | ||
x["url"].ToString() | ||
) | ||
) | ||
.ToList(); |
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 I think it's fine. Though for me, I majorly like putting the first .Select
on the same line...though I don't know how others will think about this. @Flow-Launcher/team
private BrowserType browserType = BrowserType.Chromium; | ||
private string _name; | ||
private string _dataDirectoryPath; | ||
private BrowserType _browserType = BrowserType.Chromium; |
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 suppose you want to say private field (they are different in c#).
This comment has been minimized.
This comment has been minimized.
LGTM. Tested? |
This comment has been minimized.
This comment has been minimized.
I did launch it, and it does work as expected. Here are bookmarks from my Firefox after the changes It was probably unintentional, but in your last commit you added an import in two files and modified a project file. @VictoriousRaptor |
263f23e
to
507a126
Compare
Fixed. Sorry about that. |
Mostly just moving from block-scoped namespaces to file-scoped, and renaming private properties to start with
_
for consistency.There are a few other minor changes that I will address in comments.
Since GitHub's diff view doesn't work well for migrating from block-scoped to file-scoped namespaces, and as it turns out, Rider also doesn't display it well when looking directly at the pull request, I suggest pulling this branch in Rider locally and looking at the diff there as it seems to work correctly when the diff is local.