Skip to content

Commit

Permalink
Better procedure for install the command line tool.
Browse files Browse the repository at this point in the history
  • Loading branch information
sbarex committed Jan 29, 2022
1 parent 66c4f0e commit 5109670
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 10 deletions.
36 changes: 28 additions & 8 deletions QLMarkdown/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -125,19 +125,39 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSMenuItemValidation {


@IBAction func installCLITool(_ sender: Any) {
guard let app = Bundle.main.url(forResource: "qlmarkdown_cli", withExtension: nil) else {
guard let srcApp = Bundle.main.url(forResource: "qlmarkdown_cli", withExtension: nil) else {
return
}
let dstApp = URL(fileURLWithPath: "/usr/local/bin/qlmarkdown_cli")

let alert1 = NSAlert()
alert1.messageText = "The tool will be installed in \(dstApp.path) \nDo you want to continue?"
alert1.informativeText = "You can call the tool directly from this path: \n\(srcApp.path) \n\nManually install from a Terminal shell with this command: \nln -sfv \(srcApp.path) \(dstApp.path)"
alert1.alertStyle = .informational
alert1.addButton(withTitle: "OK").keyEquivalent = "\r"
alert1.addButton(withTitle: "Cancel").keyEquivalent = "\u{1b}"
guard alert1.runModal() == .alertFirstButtonReturn else {
return
}
guard access(dstApp.deletingLastPathComponent().path, W_OK) == 0 else {
let alert = NSAlert()
alert.messageText = "Unable to install the tool: \(dstApp.deletingLastPathComponent().path) is not writable"
alert.informativeText = "You can directly call the tool from this path: \n\(srcApp.path) \n\nManually intall from a Terminal shell with this command: \nln -sfv \(srcApp.path) \(dstApp.path)"
alert.alertStyle = .warning
alert.addButton(withTitle: "Close").keyEquivalent = "\u{1b}"
alert.runModal()
return
}

let alert = NSAlert()
let path = "/usr/local/bin/qlmarkdown_cli"
do {
try FileManager.default.createSymbolicLink(at: URL(fileURLWithPath: path), withDestinationURL: app)
try FileManager.default.createSymbolicLink(at: dstApp, withDestinationURL: srcApp)
alert.messageText = "Command line tool installed"
alert.informativeText = "Path: \(path)"
alert.informativeText = "You can call it from this path: \(dstApp.path)"
alert.alertStyle = .informational
} catch {
alert.messageText = "Unable to link the command line tool link into `\(path)`!"
alert.informativeText = error.localizedDescription
alert.messageText = "Unable to install the command line tool"
alert.informativeText = "(\(error.localizedDescription))\n\nYou can manually install the tool from a Terminal shell with this command: \nln -sfv \(srcApp.path) \(dstApp.path)"
alert.alertStyle = .critical
}
alert.runModal()
Expand All @@ -150,8 +170,8 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSMenuItemValidation {
NSWorkspace.shared.activateFileViewerSelecting([u])
} else {
let alert = NSAlert()
alert.messageText = "The command line tool is not installed!"
alert.alertStyle = .informational
alert.messageText = "The command line tool is not installed."
alert.alertStyle = .warning

alert.runModal()
}
Expand Down
4 changes: 2 additions & 2 deletions QLMarkdown/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@
<action selector="checkForUpdates:" target="Voe-Tx-rLC" id="JWB-gK-Wfw"/>
</connections>
</menuItem>
<menuItem title="Install the command line tool" id="eLR-wj-sll">
<menuItem title="Install the command line tool" id="eLR-wj-sll">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="installCLITool:" target="Voe-Tx-rLC" id="BHr-CG-89n"/>
</connections>
</menuItem>
<menuItem title="Reveal the command line tool" alternate="YES" id="R79-ew-3D9">
<menuItem title="Reveal the command line tool" alternate="YES" id="R79-ew-3D9">
<modifierMask key="keyEquivalentModifierMask" option="YES"/>
<connections>
<action selector="revealCLITool:" target="Voe-Tx-rLC" id="a9e-gM-h4J"/>
Expand Down

0 comments on commit 5109670

Please sign in to comment.