Skip to content

Commit

Permalink
Merge pull request #72 from aschuhardt/develop
Browse files Browse the repository at this point in the history
1.4.3 - bug fixes, a couple of quality of life items
  • Loading branch information
aschuhardt committed Nov 27, 2023
2 parents bfbf145 + 55af205 commit f485045
Show file tree
Hide file tree
Showing 12 changed files with 99 additions and 16 deletions.
15 changes: 15 additions & 0 deletions Database/SettingsDatabase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ internal class SettingsDatabase : ISettingsDatabase
private bool? _useCustomFontSize;
private string _customCss;
private bool? _useCustomCss;
private bool? _annotateLinkScheme;

public SettingsDatabase(ILogger<SettingsDatabase> logger, SQLiteConnection database)
{
Expand Down Expand Up @@ -316,6 +317,20 @@ public bool UseCustomCss
}
}

public bool AnnotateLinkScheme
{
get
{
_annotateLinkScheme ??= GetBoolValue(true);
return _annotateLinkScheme.GetValueOrDefault();
}
set
{
if (SetField(ref _annotateLinkScheme, value))
SetBoolValue(value);
}
}

public string CustomCss
{
get
Expand Down
1 change: 1 addition & 0 deletions Interfaces/ISettingsDatabase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ public interface ISettingsDatabase : INotifyPropertyChanged
int CustomFontSizeH2 { get; set; }
int CustomFontSizeH3 { get; set; }
bool UseCustomCss { get; set; }
bool AnnotateLinkScheme { get; set; }
}
8 changes: 8 additions & 0 deletions Models/Tab.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public partial class Tab : INotifyPropertyChanged
private bool _selected;
private string _title;
private Stack<Uri> _recentHistory;
private ICommand _afterSelected;

[GeneratedRegex("([^\\p{P}\\p{Z}\\p{Cc}\\p{Cf}\\p{Co}\\p{Cn}]){1,2}", RegexOptions.CultureInvariant)]
private static partial Regex DefaultLabelPattern();
Expand Down Expand Up @@ -88,6 +89,13 @@ public ICommand Load
set => SetField(ref _load, value);
}

[Ignore]
public ICommand AfterSelected
{
get => _afterSelected;
set => SetField(ref _afterSelected, value);
}

[Ignore]
public ICommand Print
{
Expand Down
9 changes: 9 additions & 0 deletions Resources/Localization/Text.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Resources/Localization/Text.resx
Original file line number Diff line number Diff line change
Expand Up @@ -701,4 +701,7 @@ Try again after you've granted the app permission to do so.</value>
<data name="BrowserView_PageWebView_OnNavigating_OK" xml:space="preserve">
<value>OK</value>
</data>
<data name="SettingsPage_Annotate_links" xml:space="preserve">
<value>Annotate non-Gemini links</value>
</data>
</root>
29 changes: 23 additions & 6 deletions Resources/Raw/whats-new.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,22 @@
}
</style>

<h4>Version 1.4.3 - November 27th, 2023</h4>
<ul>
<li>Visually annotate links with non-Gemini URLs when the link URL is not visible
<ul>
<li>This can be disabled in Settings</li>
</ul>
</li>
<li>Link context menus now show the link's URL</li>
<li>Fixed an issue causing the selected tab to stutter when swiping between tabs</li>
<li>Rosy Crow will no longer attempt to load each tab's page on startup
<ul>
<li>Page contents will be fetched for the first time only once the tab has been selected</li>
<li><a class="tracker-id" href="gemini://bbs.geminispace.org/s/Rosy-Crow-Issues/41">#41</a> This makes it so that multiple tabs won't all spam overlapping alerts on startup</li>
</ul>
</li>
</ul>
<h4>Version 1.4.2 - November 26th, 2023</h4>
<ul>
<li><a class="tracker-id" href="gemini://bbs.geminispace.org/s/Rosy-Crow-Issues/36">#36</a> Modified the swipe-style tab navigation so that it doesn't interfere with horizontal scrolling. <b>Swipe left or right on the navigation bar to navigate between tabs.</b></li>
Expand All @@ -22,12 +38,13 @@ <h5>Tabs <a class="tracker-id" href="gemini://bbs.geminispace.org/s/Rosy-Crow-Is
<ul>
<li>Tabs will now appear along the bottom of the screen</li>
<li>Swiping left and right in the app will navigate through the open tabs</li>
<li>A number of tab-related features can be accessed by long-pressing on a tab</li>
<ul>
<li>Tab icons can be manually set or fetched from the capsule's favicon.txt file if one exists</li>
<li>Tabs can be imported or exported as JSON files</li>
<li>Tabs can be visually rearranged</li>
</ul>
<li>A number of tab-related features can be accessed by long-pressing on a tab
<ul>
<li>Tab icons can be manually set or fetched from the capsule's favicon.txt file if one exists</li>
<li>Tabs can be imported or exported as JSON files</li>
<li>Tabs can be visually rearranged</li>
</ul>
</li>
<li>Tabs can be disabled in the Settings menu</li>
<li>Swipe-style tab navigation can also disabled in the Settings menu</li>
</ul>
Expand Down
6 changes: 4 additions & 2 deletions Services/Document/DocumentService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -342,12 +342,14 @@ private async Task<HtmlNode> RenderLinkLine(LinkLine line)
: RenderDefaultLinkLine(line);
}

private static HtmlNode RenderDefaultLinkLine(LinkLine line)
private HtmlNode RenderDefaultLinkLine(LinkLine line)
{
var node = HtmlNode.CreateNode(
$"<p><a href=\"{line.Uri}\">{HttpUtility.HtmlEncode(line.Text ?? line.Uri.ToString())}</a></p>");

if (string.IsNullOrWhiteSpace(line.Text) && !line.Uri.Scheme.Equals(Constants.GeminiScheme, StringComparison.OrdinalIgnoreCase))
if (_settingsDatabase.AnnotateLinkScheme &&
!string.IsNullOrWhiteSpace(line.Text) &&
!line.Uri.Scheme.Equals(Constants.GeminiScheme, StringComparison.OrdinalIgnoreCase))
{
node.PrependChild(HtmlNode.CreateNode($"<sup>({HttpUtility.HtmlEncode(line.Uri.Scheme.ToUpperInvariant())})&nbsp;</sup>"));
}
Expand Down
14 changes: 11 additions & 3 deletions Views/BrowserView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public partial class BrowserView : ContentView
private IPrintService _printService;
private bool _resetFindNext;
private Tab _tab;
private bool _hasEverLoaded;

public BrowserView()
: this(MauiProgram.Services.GetRequiredService<IOpalClient>(),
Expand Down Expand Up @@ -277,6 +278,7 @@ public async Task LoadPage(bool triggeredByRefresh = false, bool useCache = fals
return;

_tab.CanShowHostCertificate = false;
_hasEverLoaded = true;

if (_tab.Location == null || _tab.Location.Scheme == Constants.InternalScheme)
{
Expand Down Expand Up @@ -614,13 +616,15 @@ private string CreateTabLabel()
}

#if ANDROID
private void BuildContextMenu(IMenu menu, WebView view)
private void BuildContextMenu(IContextMenu menu, WebView view)
{
var hitTest = view.GetHitTestResult();

if (hitTest.Type is HitTestResult.AnchorType or HitTestResult.SrcAnchorType or HitTestResult.SrcImageAnchorType &&
!string.IsNullOrWhiteSpace(hitTest.Extra))
{
menu.SetHeaderTitle(hitTest.Extra.ToUri().ToString());

menu.Add(Text.BrowserView_BuildContextMenu_Copy_URL)?.SetOnMenuItemClickListener(
new ActionMenuClickHandler<string>(hitTest.Extra,
async uri => await Clipboard.Default.SetTextAsync(uri)));
Expand Down Expand Up @@ -701,13 +705,17 @@ private void BrowserView_OnBindingContextChanged(object sender, EventArgs e)
throw new InvalidOperationException();

_tab = tab;
tab.Refresh = new Command(async () => await LoadPage(true));
tab.Refresh = new Command(async () => await LoadPage(true).ConfigureAwait(false));
tab.FindNext = new Command(query => FindTextInPage((string)query));
tab.Print = new Command(Print, () => _tab.CanPrint);
tab.GoBack = new Command(GoBack, () => _tab.RecentHistory.TryPeek(out _));
tab.ClearFind = new Command(ClearFindResults, () => HasFindNextQuery);
tab.Load = new Command(async () => await LoadPage(false, true), () => !_isLoading);
tab.Load = new Command(async () => await LoadPage(false, true).ConfigureAwait(false), () => !_isLoading && _tab.Selected);
tab.Location = tab.Url.ToGeminiUri();

// After the tab has been selected AND its contents have never been loaded, then immediately force a load
// This is the preferable alternative to fetching every tab's page from the host at startup
tab.AfterSelected = new Command(async () => await LoadPage(false, true), () => !_hasEverLoaded);
}

private enum ResponseAction
Expand Down
6 changes: 3 additions & 3 deletions Views/MainPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
Loaded="MainPage_OnLoaded"
Appearing="MainPage_OnAppearing"
NavigationPage.HasNavigationBar="False"
views:MainPage.CurrentTab="{Binding SelectedTab, Source={x:Reference TabCollection}, Mode=TwoWay}"
views:MainPage.CurrentTab="{Binding SelectedTab, Source={x:Reference TabCollection}, Mode=OneWay}"
views:MainPage.CurrentTabViewTemplate="{DynamicResource TabViewTemplate}"
views:MainPage.Tabs="{Binding Tabs, Source={x:Reference TabCollection}}">
<ContentPage.Resources>
Expand All @@ -28,7 +28,7 @@
AbsoluteLayout.LayoutFlags="All" Loop="False"
ItemsSource="{Binding Tabs}"
ItemTemplate="{Binding CurrentTabViewTemplate}"
CurrentItem="{Binding CurrentTab, Mode=TwoWay}"
CurrentItem="{Binding SelectedTab, Source={x:Reference TabCollection}, Mode=TwoWay}"
IsSwipeEnabled="False" />
<Grid
x:Name="PullTab" ColumnDefinitions="*,Auto" IsVisible="{Binding PullTabVisible}"
Expand Down Expand Up @@ -163,4 +163,4 @@
ZIndex="10"
IsVisible="{Binding TabsEnabled}" />
</AbsoluteLayout>
</ContentPage>
</ContentPage>
7 changes: 5 additions & 2 deletions Views/MainPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ public MainPage(ISettingsDatabase settingsDatabase, IBrowsingDatabase browsingDa
ToggleMenuExpanded = new Command(() => IsMenuExpanded = !IsMenuExpanded);
HideMenu = new Command(() => IsMenuExpanded = false);
ExpandMenu = new Command(() => IsMenuExpanded = true);
NavigateLeft = new Command(() => Carousel.Position--, () => TabsEnabled && _settingsDatabase.SwipeEnabled && Carousel.Position > 0);
NavigateRight = new Command(() => Carousel.Position++, () => TabsEnabled && _settingsDatabase.SwipeEnabled && Carousel.Position < Tabs.Count - 1);
NavigateLeft = new Command(() => Carousel.ScrollTo(Carousel.Position - 1), () => TabsEnabled && _settingsDatabase.SwipeEnabled && Carousel.Position > 0);
NavigateRight = new Command(() => Carousel.ScrollTo(Carousel.Position + 1), () => TabsEnabled && _settingsDatabase.SwipeEnabled && Carousel.Position < Tabs.Count - 1);
LoadHomeUrl = new Command(TryLoadHomeUrl);
SetHomeUrl = new Command(TrySetHomeUrl);
ToggleBookmarked = new Command(TryToggleBookmarked);
Expand Down Expand Up @@ -845,5 +845,8 @@ private void Tabs_SelectedTabChanged(object sender, EventArgs e)
IsNavBarVisible = true;
if (UrlEntry.IsFocused)
UrlEntry.Unfocus();

if (CurrentTab?.AfterSelected?.CanExecute(null) ?? false)
CurrentTab.AfterSelected.Execute(null);
}
}
4 changes: 4 additions & 0 deletions Views/SettingsPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@
VerticalTextAlignment="Center" />
<Switch IsToggled="{Binding StrictTofuMode}" Grid.Column="1" />
</Grid>
<Grid ColumnDefinitions="*,Auto">
<Label Text="{x:Static localization:Text.SettingsPage_Annotate_links}" Grid.Column="0" VerticalTextAlignment="Center" />
<Switch IsToggled="{Binding AnnotateLinkScheme}" Grid.Column="1" />
</Grid>
<Grid ColumnDefinitions="*,Auto">
<Label Text="{x:Static localization:Text.SettingsPage_Show_tabs}" Grid.Column="0" VerticalTextAlignment="Center" />
<Switch IsToggled="{Binding TabsEnabled}" Grid.Column="1" />
Expand Down
13 changes: 13 additions & 0 deletions Views/SettingsPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,19 @@ public string CustomCss
}
}

public bool AnnotateLinkScheme
{
get => _settingsDatabase?.AnnotateLinkScheme ?? false;
set
{
if (value == _settingsDatabase.AnnotateLinkScheme)
return;

_settingsDatabase.AnnotateLinkScheme = value;
OnPropertyChanged();
}
}

private async void SettingChanged(object sender, PropertyChangedEventArgs e)
{
switch (e.PropertyName)
Expand Down

0 comments on commit f485045

Please sign in to comment.