Skip to content

Commit

Permalink
Add support for zooming/adjusting text size
Browse files Browse the repository at this point in the history
Fixes #55
  • Loading branch information
joelekstrom committed Jan 8, 2022
1 parent 60c5ac9 commit a22e22c
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 8 deletions.
4 changes: 2 additions & 2 deletions Fastmate.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 10.13;
MARKETING_VERSION = 1.7.0;
MARKETING_VERSION = 1.8.0;
PRODUCT_BUNDLE_IDENTIFIER = io.ekstrom.Fastmate;
PRODUCT_NAME = "$(TARGET_NAME)";
};
Expand All @@ -384,7 +384,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 10.13;
MARKETING_VERSION = 1.7.0;
MARKETING_VERSION = 1.8.0;
PRODUCT_BUNDLE_IDENTIFIER = io.ekstrom.Fastmate;
PRODUCT_NAME = "$(TARGET_NAME)";
};
Expand Down
27 changes: 21 additions & 6 deletions Fastmate/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="19455" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" initialViewController="B8D-0N-5wS">
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="19529" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" initialViewController="B8D-0N-5wS">
<dependencies>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="19455"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="19529"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
Expand Down Expand Up @@ -119,8 +119,7 @@
<action selector="paste:" target="Ady-hI-5gd" id="UvS-8e-Qdg"/>
</connections>
</menuItem>
<menuItem title="Paste and Match Style" keyEquivalent="V" id="WeT-3V-zwk">
<modifierMask key="keyEquivalentModifierMask" option="YES" command="YES"/>
<menuItem title="Paste and Match Style" keyEquivalent="v" id="WeT-3V-zwk">
<connections>
<action selector="pasteAsPlainText:" target="Ady-hI-5gd" id="cEh-KX-wJQ"/>
</connections>
Expand Down Expand Up @@ -297,6 +296,22 @@
<action selector="toggleFullScreen:" target="Ady-hI-5gd" id="dU3-MA-1Rq"/>
</connections>
</menuItem>
<menuItem isSeparatorItem="YES" id="snc-8b-V4W"/>
<menuItem title="Actual Size" keyEquivalent="0" id="lRM-y0-uvs">
<connections>
<action selector="resetZoomLevel:" target="Ady-hI-5gd" id="uVm-MT-hkD"/>
</connections>
</menuItem>
<menuItem title="Zoom In" keyEquivalent="+" id="21e-Cc-JSl" userLabel="Zoom In">
<connections>
<action selector="zoomIn:" target="Ady-hI-5gd" id="r9K-JI-m1h"/>
</connections>
</menuItem>
<menuItem title="Zoom Out" keyEquivalent="-" id="Rza-Jp-51v" userLabel="Zoom Out">
<connections>
<action selector="zoomOut:" target="Ady-hI-5gd" id="H2r-XN-y0p"/>
</connections>
</menuItem>
</items>
</menu>
</menuItem>
Expand Down Expand Up @@ -411,11 +426,11 @@
<objects>
<viewController title="Fastmate Settings" showSeguePresentationStyle="single" id="Tjh-E4-m7V" customClass="SettingsViewController" sceneMemberID="viewController">
<view key="view" id="F1O-1e-Ohl">
<rect key="frame" x="0.0" y="0.0" width="535" height="253"/>
<rect key="frame" x="0.0" y="0.0" width="535" height="266"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<tabView translatesAutoresizingMaskIntoConstraints="NO" id="kKl-dg-XhU">
<rect key="frame" x="13" y="10" width="509" height="229"/>
<rect key="frame" x="13" y="10" width="509" height="242"/>
<font key="font" metaFont="system"/>
<tabViewItems>
<tabViewItem label="General" identifier="" id="hnf-kG-bEx">
Expand Down
19 changes: 19 additions & 0 deletions Fastmate/WebViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ @interface WebViewController () <WKNavigationDelegate, WKUIDelegate, WKScriptMes
@property (nonatomic, strong) id currentURLObserver;
@property (nonatomic, strong) NSURL *baseURL;
@property (nonatomic, strong) NSTextField *linkPreviewTextField;
@property (nonatomic, assign) CGFloat zoomLevel;

// If the user is for example viewing a PDF inline, this value will point to the actual file
@property (nonatomic, strong) NSURL *lastViewedUserContent;
Expand All @@ -29,6 +30,7 @@ @implementation WebViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self configureUserContentController];
self.zoomLevel = 1.0;

WKWebViewConfiguration *configuration = [WKWebViewConfiguration new];
configuration.applicationNameForUserAgent = @"Fastmate";
Expand Down Expand Up @@ -264,6 +266,23 @@ - (IBAction)copyFastmateLinkToCurrentItem:(id)sender {
[self copyURLToPasteboard:components.URL];
}

- (IBAction)zoomIn:(id)sender {
self.zoomLevel += 0.1;
}

- (IBAction)zoomOut:(id)sender {
self.zoomLevel -= 0.1;
}

- (IBAction)resetZoomLevel:(id)sender {
self.zoomLevel = 1.0;
}

- (void)setZoomLevel:(CGFloat)zoomLevel {
_zoomLevel = zoomLevel;
[self.webView evaluateJavaScript:[NSString stringWithFormat:@"document.body.style.zoom = %f;", self.zoomLevel]];
}

- (void)copyURLToPasteboard:(NSURL *)URL {
NSPasteboard *pasteboard = NSPasteboard.generalPasteboard;
[pasteboard clearContents];
Expand Down

0 comments on commit a22e22c

Please sign in to comment.