Skip to content

Commit

Permalink
Add Sparkle integration
Browse files Browse the repository at this point in the history
  • Loading branch information
gandarez committed Jun 14, 2023
1 parent 68a203e commit 89ca949
Show file tree
Hide file tree
Showing 12 changed files with 119 additions and 13 deletions.
39 changes: 37 additions & 2 deletions .github/workflows/on_push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ jobs:
with:
fetch-depth: 0
-
# Run only for main branch
# Run only for main branch (aka develop)
if: ${{ github.ref == 'refs/heads/main' }}
name: Changelog for main
uses: gandarez/[email protected]
Expand Down Expand Up @@ -201,6 +201,39 @@ jobs:
with:
name: app
path: ./
-
name: Prepare release folder
id: prepare
run: |
mkdir release
mv ./WakaTime.zip release/
-
name: Prepare Sparkle update creation
env:
SPARKLE_PRIVATE_KEY: ${{ secrets.SPARKLE_PRIVATE_KEY }}
run: |
echo -n "$SPARKLE_PRIVATE_KEY" > ./bin/sparkle/sparkle_private_key
-
name: Extract latest changes
id: latest_changes
run: |
python3 ./bin/sparkle/generate_latest_changes.py
echo "${{ needs.version.outputs.semver_tag }}" >> title
-
name: Generate Sparkle notes
run: |
pip3 install -r ./bin/sparkle/requirements.txt
python3 ./bin/sparkle/generate_html_for_sparkle_release.py
mv release/latest_changes.html release/WakaTime.html
-
name: Update appcast
run: |
./bin/sparkle/generate_appcast \
--ed-key-file ./bin/sparkle/sparkle_private_key \
--link https://github.com/${{ github.repository_owner }}/${{ github.event.repository.name }}/releases \
--download-url-prefix https://github.com/${{ github.repository_owner }}/${{ github.event.repository.name }}/releases/download/${{ needs.version.outputs.semver_tag }}/ \
-o release/appcast.xml \
release/
-
name: "Create release"
uses: softprops/action-gh-release@master
Expand All @@ -211,7 +244,9 @@ jobs:
prerelease: ${{ needs.version.outputs.is_prerelease }}
target_commitish: ${{ github.sha }}
draft: false
files: ./WakaTime.zip
files: |
./release/WakaTime.zip
./release/appcast.xml
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
-
Expand Down
6 changes: 6 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"lldb.library": "/Applications/Xcode.app/Contents/SharedFrameworks/LLDB.framework/Versions/A/LLDB",
"githubPullRequests.ignoredPullRequestBranches": [
"main"
]
}
3 changes: 1 addition & 2 deletions AUTHORS
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
WakaTime is written and maintained by Alan Hamlett and
various contributors:
WakaTime is written and maintained by Alan Hamlett and various contributors:

- Alan Hamlett <[email protected]>
- Carlos Henrique Gandarez <[email protected]>
Expand Down
8 changes: 8 additions & 0 deletions WakaTime/AppDelegate.swift
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import Cocoa
import Sparkle

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)

func applicationDidFinishLaunching(_ aNotification: Notification) {
wakaTime = WakaTime()
Expand All @@ -28,6 +30,8 @@ class AppDelegate: NSObject, NSApplicationDelegate {
menu.addItem(withTitle: "Settings", action: #selector(AppDelegate.settingsClicked(_:)), keyEquivalent: "")
menu.addItem(withTitle: "Monitored Apps", action: #selector(AppDelegate.monitoredAppsClicked(_:)), keyEquivalent: "")
menu.addItem(NSMenuItem.separator())
menu.addItem(withTitle: "Check for Updates", action: #selector(AppDelegate.checkForUpdatesClicked(_:)), keyEquivalent: "")
menu.addItem(NSMenuItem.separator())
menu.addItem(withTitle: "Quit", action: #selector(AppDelegate.quitClicked(_:)), keyEquivalent: "")

statusBarItem.menu = menu
Expand Down Expand Up @@ -59,6 +63,10 @@ class AppDelegate: NSObject, NSApplicationDelegate {
showMonitoredApps()
}

@objc func checkForUpdatesClicked(_ sender: AnyObject) {
updaterController.checkForUpdates(sender)
}

@objc func quitClicked(_ sender: AnyObject) {
NSApplication.shared.terminate(self)
}
Expand Down
8 changes: 8 additions & 0 deletions WakaTime/WakaTime-Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@
<dict>
<key>CFBundleIdentifier</key>
<string></string>
<key>SUFeedURL</key>
<string>https://github.com/wakatime/macos-wakatime/releases/latest/download/appcast.xml</string>
<key>SUPublicEDKey</key>
<string>xL55JUMUOE7xT2KzT5ZdCsD+DOgoEsLtYauz/u09rKE=</string>
<key>SUAllowsAutomaticUpdates</key>
<string>YES</string>
<key>SUEnableAutomaticChecks</key>
<string>YES</string>
<key>LSUIElement</key>
<true/>
<key>CFBundleURLTypes</key>
Expand Down
10 changes: 1 addition & 9 deletions WakaTime/WakaTime.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import SwiftUI
// swiftlint:disable force_unwrapping
// swiftlint:disable force_try
class WakaTime {
let watcher = Watcher()
var lastFile = ""
var lastTime = 0
let watcher = Watcher()

enum Constants {
static let settingsDeepLink: String = "wakatime://settings"
Expand Down Expand Up @@ -219,14 +219,6 @@ class WakaTime {
return "arm64"
}

private func dashboard() {
NSWorkspace.shared.open(URL(string: "https://wakatime.com/")!)
}

private func quit() {
NSApp.terminate(self)
}

private func shouldSendHeartbeat(file: URL, time: Int, isWrite: Bool) -> Bool {
guard
!isWrite,
Expand Down
5 changes: 5 additions & 0 deletions WakaTime/WakaTimeRelease.entitlements
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?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/>
</plist>
Binary file added bin/sparkle/generate_appcast
Binary file not shown.
23 changes: 23 additions & 0 deletions bin/sparkle/generate_html_for_sparkle_release.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

# Takes as input two files:
# 1. File "title" contains the title of the release
# 2. File "latest_changes" contains the latest changes in the release in markdown format

# The output is a file "release/latest_changes.html" which contains the latest changes in html format

import markdown

def generate_html_for_latest_changes():
with open('title', 'r') as f:
title = f.read()
with open('latest_changes', 'r') as f:
changes = f.read()

text = '# ' + title + '\n\n' + changes
html = markdown.markdown(text)

with open('release/latest_changes.html', 'w') as f:
f.write(html)

if __name__ == '__main__':
generate_html_for_latest_changes()
23 changes: 23 additions & 0 deletions bin/sparkle/generate_latest_changes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

# look at file changelog.txt, take all bullet points under the top header.

def get_changelog_notes():
with open('changelog.txt', 'r') as f:
lines = f.readlines()
lines = lines[1:]
latest_changes = ""
for line in lines:
line = line.strip()
if line == "":
continue
if not line.startswith('-'):
line = "- " + line
latest_changes += line + "\n"
return latest_changes

if __name__ == '__main__':
latest_changes = get_changelog_notes()
print(latest_changes)
# write value to a file
with open('latest_changes', 'w') as f:
f.write(latest_changes)
1 change: 1 addition & 0 deletions bin/sparkle/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
markdown
6 changes: 6 additions & 0 deletions project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ options:
bundleIdPrefix: macos-wakatime
createIntermediateGroups: true

packages:
Sparkle:
url: https://github.com/sparkle-project/Sparkle
from: 2.0.0

targets:
WakaTime:
type: application
Expand All @@ -24,6 +29,7 @@ targets:
name: Swiftlint
dependencies:
- target: WakaTime Helper
- package: Sparkle
postBuildScripts:
- script: |
LOGIN_ITEMS_DIR="$BUILT_PRODUCTS_DIR/$PRODUCT_NAME.app/Contents/Library/LoginItems"
Expand Down

0 comments on commit 89ca949

Please sign in to comment.