Skip to content
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

Merged

Conversation

Yusyuriv
Copy link
Member

@Yusyuriv Yusyuriv commented Apr 16, 2024

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.

@Yusyuriv Yusyuriv requested a review from taooceros April 16, 2024 07:03
@Yusyuriv Yusyuriv self-assigned this Apr 16, 2024

This comment has been minimized.

private BrowserType browserType = BrowserType.Chromium;
private string _name;
private string _dataDirectoryPath;
private BrowserType _browserType = BrowserType.Chromium;
Copy link
Member Author

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

Copy link
Member

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#).

Copy link
Member Author

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();
Copy link
Member Author

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"
Copy link
Member Author

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.

Comment on lines +93 to +100
private void Others_Click(object sender, RoutedEventArgs e)
{
CustomBrowsersList.Visibility = CustomBrowsersList.Visibility switch
{
EditSelectedCustomBrowser();
}
Visibility.Collapsed => Visibility.Visible,
_ => Visibility.Collapsed
};
}
Copy link
Member Author

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.

private const string queryAllBookmarks = @"SELECT moz_places.url, moz_bookmarks.title
FROM moz_places
INNER JOIN moz_bookmarks ON (
private const string QueryAllBookmarks = """
Copy link
Member Author

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.

Copy link
Member

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?

Copy link
Member Author

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:
image
image

Comment on lines +41 to +48
return reader
.Select(
x => new Bookmark(
x["title"] is DBNull ? string.Empty : x["title"].ToString(),
x["url"].ToString()
)
)
.ToList();
Copy link
Member Author

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.

Copy link
Member

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

Comment on lines +76 to +78
// get firefox default profile directory from profiles.ini
using var sReader = new StreamReader(profileIni);
var ini = sReader.ReadToEnd();
Copy link
Member Author

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();
Copy link
Member Author

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;
Copy link
Member Author

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.

Comment on lines +65 to +83
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();
Copy link
Member Author

@Yusyuriv Yusyuriv Apr 16, 2024

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.

@Yusyuriv Yusyuriv marked this pull request as ready for review April 16, 2024 08:04
private const string queryAllBookmarks = @"SELECT moz_places.url, moz_bookmarks.title
FROM moz_places
INNER JOIN moz_bookmarks ON (
private const string QueryAllBookmarks = """
Copy link
Member

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?

Comment on lines +41 to +48
return reader
.Select(
x => new Bookmark(
x["title"] is DBNull ? string.Empty : x["title"].ToString(),
x["url"].ToString()
)
)
.ToList();
Copy link
Member

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

Plugins/Flow.Launcher.Plugin.BrowserBookmark/Main.cs Outdated Show resolved Hide resolved
private BrowserType browserType = BrowserType.Chromium;
private string _name;
private string _dataDirectoryPath;
private BrowserType _browserType = BrowserType.Chromium;
Copy link
Member

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.

@VictoriousRaptor
Copy link
Contributor

LGTM. Tested?

This comment has been minimized.

@Yusyuriv
Copy link
Member Author

I did launch it, and it does work as expected. Here are bookmarks from my Firefox after the changes
image

Here's a bookmark from Edge
image

It was probably unintentional, but in your last commit you added an import in two files and modified a project file. @VictoriousRaptor

@VictoriousRaptor VictoriousRaptor force-pushed the code-cleanup/Flow.Launcher.Plugin.BrowserBookmark branch from 263f23e to 507a126 Compare May 1, 2024 03:11
@VictoriousRaptor
Copy link
Contributor

It was probably unintentional, but in your last commit you added an import in two files and modified a project file.

Fixed. Sorry about that.

@VictoriousRaptor VictoriousRaptor merged commit 3554136 into dev May 1, 2024
4 checks passed
@VictoriousRaptor VictoriousRaptor deleted the code-cleanup/Flow.Launcher.Plugin.BrowserBookmark branch May 1, 2024 03:42
@VictoriousRaptor VictoriousRaptor added this to the 1.19.0 milestone May 1, 2024
@jjw24 jjw24 added the enhancement New feature or request label May 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Code Refactor enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants