Skip to content

Commit

Permalink
Link to install known plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
alanhamlett committed Aug 22, 2024
1 parent 3f8985e commit a7bd592
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 44 deletions.
48 changes: 37 additions & 11 deletions WakaTime/Views/MonitoredAppsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -138,17 +138,11 @@ class MonitoredAppsView: NSView, NSOutlineViewDataSource, NSOutlineViewDelegate
let nameLabel = NSTextField(labelWithString: appData.name)
nameLabel.translatesAutoresizingMaskIntoConstraints = false

let isMonitored = MonitoringManager.isAppMonitored(for: appData.bundleId)
let switchControl = NSSwitch()
switchControl.translatesAutoresizingMaskIntoConstraints = false
switchControl.state = isMonitored ? .on : .off
switchControl.target = self
switchControl.action = #selector(switchToggled(_:))
switchControl.tag = appData.tag
let action = switchOrLink(appData)

cellView.addSubview(imageView)
cellView.addSubview(nameLabel)
cellView.addSubview(switchControl)
cellView.addSubview(action)

// Determine if the current item is the last in the list
let isLastItem = apps.last == appData
Expand Down Expand Up @@ -177,17 +171,49 @@ class MonitoredAppsView: NSView, NSOutlineViewDataSource, NSOutlineViewDelegate

nameLabel.leadingAnchor.constraint(equalTo: imageView.trailingAnchor, constant: 10),
nameLabel.centerYAnchor.constraint(equalTo: cellView.centerYAnchor),
nameLabel.trailingAnchor.constraint(equalTo: switchControl.leadingAnchor, constant: -5),
nameLabel.trailingAnchor.constraint(equalTo: action.leadingAnchor, constant: -5),

switchControl.trailingAnchor.constraint(equalTo: cellView.trailingAnchor, constant: -10),
switchControl.centerYAnchor.constraint(equalTo: cellView.centerYAnchor),
action.trailingAnchor.constraint(equalTo: cellView.trailingAnchor, constant: -10),
action.centerYAnchor.constraint(equalTo: cellView.centerYAnchor),
])

return cellView
}

func switchOrLink(_ appData: AppData) -> NSView {
if MonitoredApp.pluginAppIds[appData.bundleId] != nil {
let button = NSButton()
button.translatesAutoresizingMaskIntoConstraints = false
button.bezelStyle = NSButton.BezelStyle.rounded
button.title = "Install plugin"
button.action = #selector(clickInstallPlugin(_:))
button.widthAnchor.constraint(equalToConstant: 100).isActive = true
button.tag = appData.tag
return button
}

let isMonitored = MonitoringManager.isAppMonitored(for: appData.bundleId)
let switchControl = NSSwitch()
switchControl.translatesAutoresizingMaskIntoConstraints = false
switchControl.state = isMonitored ? .on : .off
switchControl.target = self
switchControl.action = #selector(switchToggled(_:))
switchControl.tag = appData.tag
return switchControl
}

@objc func switchToggled(_ sender: NSSwitch) {
let appData = apps[sender.tag]
MonitoringManager.set(monitoringState: sender.state == .on ? .on : .off, for: appData.bundleId)
}

@objc func clickInstallPlugin(_ sender: NSButton) {
let appData = apps[sender.tag]
guard
let path = MonitoredApp.pluginAppIds[appData.bundleId],
let url = URL(string: "https://wakatime.com/\(path)")
else { return }

NSWorkspace.shared.open(url)
}
}
70 changes: 37 additions & 33 deletions WakaTime/Watchers/MonitoredApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,41 +47,45 @@ enum MonitoredApp: String, CaseIterable {

// Hide these from the Monitored Apps menu
static let unsupportedAppIds = [
"aptana.studio",
"com.apple.finder",
"com.google.android.studio",
"com.jetbrains.CLion",
"com.jetbrains.DataSpell",
"com.jetbrains.PhpStorm",
"com.jetbrains.PyCharm",
"com.jetbrains.RubyMine",
"com.jetbrains.RustRover",
"com.jetbrains.WebStorm",
"com.jetbrains.goland",
"com.jetbrains.intellij",
"com.jetbrains.intellij.ce",
"com.jetbrains.pycharm.ce",
"com.jetbrains.rider",
"com.microsoft.VSCode",
"com.microsoft.VSCodeInsiders",
"com.sublimetext.2",
"com.sublimetext.3",
"com.sublimetext.4",
"com.visualstudio.code.oss",
"com.vscodium",
"epp.package.committers",
"epp.package.cpp",
"epp.package.dsl",
"epp.package.embedcpp",
"epp.package.java",
"epp.package.jee",
"epp.package.modeling",
"epp.package.parallel",
"epp.package.php",
"epp.package.rcp",
"epp.package.scout",
"macos-wakatime.WakaTime",
"org.vim.MacVim",
]

// link to plugin install pages with wakatime.com domain prepended for apps with plugins available
static let pluginAppIds: [String: String] = [
"aptana.studio": "aptana",
"com.google.android.studio": "android-studio",
"com.jetbrains.CLion": "clion",
"com.jetbrains.DataSpell": "dataspell",
"com.jetbrains.PhpStorm": "phpstorm",
"com.jetbrains.PyCharm": "pycharm",
"com.jetbrains.pycharm.ce": "pycharm",
"com.jetbrains.RubyMine": "rubymine",
"com.jetbrains.RustRover": "rustrover",
"com.jetbrains.WebStorm": "webstorm",
"com.jetbrains.goland": "goland",
"com.jetbrains.intellij": "intellij-idea",
"com.jetbrains.intellij.ce": "intellij-idea",
"com.jetbrains.rider": "rider",
"com.microsoft.VSCode": "vs-code",
"com.microsoft.VSCodeInsiders": "vs-code",
"com.sublimetext.2": "sublime",
"com.sublimetext.3": "sublime",
"com.sublimetext.4": "sublime",
"com.visualstudio.code.oss": "vs-code",
"com.vscodium": "vs-code",
"epp.package.committers": "eclipse",
"epp.package.cpp": "eclipse",
"epp.package.dsl": "eclipse",
"epp.package.embedcpp": "eclipse",
"epp.package.java": "eclipse",
"epp.package.jee": "eclipse",
"epp.package.modeling": "eclipse",
"epp.package.parallel": "eclipse",
"epp.package.php": "eclipse",
"epp.package.rcp": "eclipse",
"epp.package.scout": "eclipse",
"org.vim.MacVim": "vim",
]

static var allBundleIds: [String] {
Expand Down

0 comments on commit a7bd592

Please sign in to comment.