Skip to content

Commit

Permalink
Merge pull request #127 from wakatime/main
Browse files Browse the repository at this point in the history
Release v2.2.0
  • Loading branch information
alanhamlett authored Jul 17, 2023
2 parents e8dec24 + 8cde90d commit 86041ce
Show file tree
Hide file tree
Showing 19 changed files with 147 additions and 14 deletions.
23 changes: 15 additions & 8 deletions .github/workflows/on_push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
run: xcodegen
-
name: Build app to run linters
run: xcodebuild
run: xcodebuild -scheme WakaTime

version:
name: Version
Expand Down Expand Up @@ -98,7 +98,14 @@ jobs:
run: xcodegen
-
name: Build app
run: xcodebuild -configuration Release
id: build
run: |
xcodebuild -scheme WakaTime -configuration Release
app=`find /Users/runner/Library/Developer/Xcode/DerivedData/ -name WakaTime.app`
echo "$app"
directory=`dirname $app`
echo "$directory"
echo "directory=$directory" >> $GITHUB_OUTPUT
-
name: Import Code-Signing Certificates
uses: Apple-Actions/import-codesign-certs@v1
Expand All @@ -110,7 +117,7 @@ jobs:
-
name: Codesign
run: |
codesign -v --force --deep --timestamp -s "WakaTime" --options runtime build/Release/WakaTime.app
codesign -v --force --deep --timestamp -s "WakaTime" --options runtime ${{ steps.build.outputs.directory }}/WakaTime.app
-
name: Store Credentials
env:
Expand All @@ -121,18 +128,18 @@ jobs:
-
name: Notarize Helper
run: |
ditto -c -k --keepParent "build/Release/WakaTime.app/Contents/Library/LoginItems/WakaTime Helper.app" helper.zip
ditto -c -k --keepParent "${{ steps.build.outputs.directory }}/WakaTime.app/Contents/Library/LoginItems/WakaTime Helper.app" helper.zip
xcrun notarytool submit helper.zip --keychain-profile "notarytool-profile" --wait
xcrun stapler staple "build/Release/WakaTime.app/Contents/Library/LoginItems/WakaTime Helper.app"
xcrun stapler staple "${{ steps.build.outputs.directory }}/WakaTime.app/Contents/Library/LoginItems/WakaTime Helper.app"
-
name: Notarize App
run: |
ditto -c -k --keepParent build/Release/WakaTime.app main.zip
ditto -c -k --keepParent ${{ steps.build.outputs.directory }}/WakaTime.app main.zip
xcrun notarytool submit main.zip --keychain-profile "notarytool-profile" --wait
xcrun stapler staple build/Release/WakaTime.app
xcrun stapler staple ${{ steps.build.outputs.directory }}/WakaTime.app
-
name: Zip
run: ditto -c -k --sequesterRsrc --keepParent build/Release/WakaTime.app WakaTime.zip
run: ditto -c -k --sequesterRsrc --keepParent ${{ steps.build.outputs.directory }}/WakaTime.app WakaTime.zip
-
name: Upload artifacts
uses: actions/upload-artifact@v3
Expand Down
1 change: 1 addition & 0 deletions Scripts/Firebase/upload-dSYM.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"${BUILD_DIR%/Build/*}/SourcePackages/checkouts/firebase-ios-sdk/Crashlytics/run"
75 changes: 74 additions & 1 deletion WakaTime/AppDelegate.swift
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
import Cocoa
import Sparkle
import UserNotifications

class AppDelegate: NSObject, NSApplicationDelegate {
var window: NSWindow!
var statusBarItem: NSStatusItem!
var settingsWindowController = SettingsWindowController()
var monitoredAppsWindowController = MonitoredAppsWindowController()
var wakaTime: WakaTime?
var updaterController = SPUStandardUpdaterController(startingUpdater: true, updaterDelegate: nil, userDriverDelegate: nil)
var updaterController: SPUStandardUpdaterController!

let updateNotificationIdentifier = "UpdateCheck"

func applicationDidFinishLaunching(_ aNotification: Notification) {
updaterController = SPUStandardUpdaterController(startingUpdater: true, updaterDelegate: self, userDriverDelegate: self)

wakaTime = WakaTime()

// Handle deep links
Expand All @@ -35,6 +40,8 @@ class AppDelegate: NSObject, NSApplicationDelegate {
menu.addItem(withTitle: "Quit", action: #selector(AppDelegate.quitClicked(_:)), keyEquivalent: "")

statusBarItem.menu = menu

UNUserNotificationCenter.current().delegate = self
}

@objc func handleGetURL(_ event: NSAppleEventDescriptor, withReplyEvent replyEvent: NSAppleEventDescriptor) {
Expand Down Expand Up @@ -81,3 +88,69 @@ class AppDelegate: NSObject, NSApplicationDelegate {
monitoredAppsWindowController.showWindow(self)
}
}

// MARK: - SPUUpdaterDelegate

extension AppDelegate: SPUUpdaterDelegate {
func updater(_ updater: SPUUpdater, willScheduleUpdateCheckAfterDelay delay: TimeInterval) {
UNUserNotificationCenter.current().requestAuthorization(options: [.badge, .alert, .sound]) { _, _ in }
}
}

// MARK: - SPUStandardUserDriverDelegate

extension AppDelegate: SPUStandardUserDriverDelegate {
// Declares that we support gentle scheduled update reminders to Sparkle's standard user driver
var supportsGentleScheduledUpdateReminders: Bool {
true
}

func standardUserDriverWillHandleShowingUpdate(
_ handleShowingUpdate: Bool,
forUpdate update: SUAppcastItem,
state: SPUUserUpdateState
) {
NSApp.setActivationPolicy(.regular)

if !state.userInitiated {
NSApp.dockTile.badgeLabel = "1"

do {
let content = UNMutableNotificationContent()
content.title = "A new update is available"
content.body = "Version \(update.displayVersionString) is now available"

let request = UNNotificationRequest(identifier: updateNotificationIdentifier, content: content, trigger: nil)

UNUserNotificationCenter.current().add(request)
}
}
}

func standardUserDriverDidReceiveUserAttention(forUpdate update: SUAppcastItem) {
NSApp.dockTile.badgeLabel = ""

UNUserNotificationCenter.current().removeDeliveredNotifications(withIdentifiers: [updateNotificationIdentifier])
}

func standardUserDriverWillFinishUpdateSession() {
NSApp.setActivationPolicy(.accessory)
}
}

// MARK: - UNUserNotificationCenterDelegate

extension AppDelegate: UNUserNotificationCenterDelegate {
func userNotificationCenter(
_ center: UNUserNotificationCenter,
didReceive response: UNNotificationResponse,
withCompletionHandler completionHandler: @escaping () -> Void
) {
if response.notification.request.identifier == updateNotificationIdentifier
&& response.actionIdentifier == UNNotificationDefaultActionIdentifier {
updaterController.checkForUpdates(nil)
}

completionHandler()
}
}
7 changes: 2 additions & 5 deletions WakaTime/Helpers/SettingsManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,8 @@ class SettingsManager {
!loginItemRegistered(),
PropertiesManager.shouldLaunchOnLogin
else { return false }
#if DEBUG
return false
#else
return true
#endif

return Bundle.main.version != "local-build"
}

static func registerAsLoginItem() {
Expand Down
File renamed without changes.
34 changes: 34 additions & 0 deletions WakaTime/Resources/GoogleService-Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CLIENT_ID</key>
<string>473173879994-q78fldrplnkhrr4oa5h10mkv15g1ng2g.apps.googleusercontent.com</string>
<key>REVERSED_CLIENT_ID</key>
<string>com.googleusercontent.apps.473173879994-q78fldrplnkhrr4oa5h10mkv15g1ng2g</string>
<key>API_KEY</key>
<string>AIzaSyDBdPD7ZIMm7XtDueuhOBd-rx7kF3jIc0U</string>
<key>GCM_SENDER_ID</key>
<string>473173879994</string>
<key>PLIST_VERSION</key>
<string>1</string>
<key>BUNDLE_ID</key>
<string>macos-wakatime.WakaTime</string>
<key>PROJECT_ID</key>
<string>wakatime-macos-desktop-app</string>
<key>STORAGE_BUCKET</key>
<string>wakatime-macos-desktop-app.appspot.com</string>
<key>IS_ADS_ENABLED</key>
<false></false>
<key>IS_ANALYTICS_ENABLED</key>
<false></false>
<key>IS_APPINVITE_ENABLED</key>
<true></true>
<key>IS_GCM_ENABLED</key>
<true></true>
<key>IS_SIGNIN_ENABLED</key>
<true></true>
<key>GOOGLE_APP_ID</key>
<string>1:473173879994:ios:c9a7680a9e365351282683</string>
</dict>
</plist>
11 changes: 11 additions & 0 deletions WakaTime/WakaTime.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Foundation
import AppKit
import Firebase

class WakaTime {
// MARK: Watcher
Expand Down Expand Up @@ -27,10 +28,20 @@ class WakaTime {
Dependencies.installDependencies()
if SettingsManager.shouldRegisterAsLoginItem() { SettingsManager.registerAsLoginItem() }
Accessibility.requestA11yPermission()

configureFirebase()
checkForApiKey()
watcher.eventHandler = handleEvent
}

private func configureFirebase() {
// Needed for uncaught exception reporting
UserDefaults.standard.register(
defaults: ["NSApplicationCrashOnExceptions": true]
)
FirebaseApp.configure()
}

private func checkForApiKey() {
let apiKey = ConfigFile.getSetting(section: "settings", key: "api_key")
if apiKey.isEmpty {
Expand Down
10 changes: 10 additions & 0 deletions project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ packages:
Sparkle:
url: https://github.com/sparkle-project/Sparkle
from: 2.0.0
Firebase:
url: https://github.com/firebase/firebase-ios-sdk
from: 10.0.0

targets:
WakaTime:
Expand All @@ -31,13 +34,20 @@ targets:
dependencies:
- target: WakaTime Helper
- package: Sparkle
- package: Firebase
product: FirebaseCrashlytics
postBuildScripts:
- script: |
LOGIN_ITEMS_DIR="$BUILT_PRODUCTS_DIR/$PRODUCT_NAME.app/Contents/Library/LoginItems"
rm -rf "$LOGIN_ITEMS_DIR"
mkdir -p "$LOGIN_ITEMS_DIR"
mv "$BUILT_PRODUCTS_DIR/$PRODUCT_NAME.app/Contents/Resources/WakaTime Helper.app" "$LOGIN_ITEMS_DIR/"
name: Move "WakaTime Helper.app" to LoginItems
- script: Scripts/Firebase/upload-dSYM.sh
name: Firebase
inputFiles:
- ${DWARF_DSYM_FOLDER_PATH}/${DWARF_DSYM_FILE_NAME}/Contents/Resources/DWARF/${TARGET_NAME}
- $(SRCROOT)/$(BUILT_PRODUCTS_DIR)/$(INFOPLIST_PATH)
WakaTime Helper:
type: application
platform: macOS
Expand Down

0 comments on commit 86041ce

Please sign in to comment.