Skip to content

Commit

Permalink
new app icon, fix for issue #1
Browse files Browse the repository at this point in the history
  • Loading branch information
PKBeam committed Feb 12, 2021
1 parent d17e785 commit cb446d1
Show file tree
Hide file tree
Showing 16 changed files with 76 additions and 54 deletions.
4 changes: 2 additions & 2 deletions RPFX.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@
"$(inherited)",
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 10.15;
MACOSX_DEPLOYMENT_TARGET = 11.1;
PRODUCT_BUNDLE_IDENTIFIER = com.PKBeam.RPFX;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0;
Expand All @@ -328,7 +328,7 @@
"$(inherited)",
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 10.15;
MACOSX_DEPLOYMENT_TARGET = 11.1;
PRODUCT_BUNDLE_IDENTIFIER = com.PKBeam.RPFX;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0;
Expand Down
53 changes: 28 additions & 25 deletions RPFX/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@ class AppDelegate: NSObject, NSApplicationDelegate {
var startDate: Date?

func beginTimer() {
statusUpdateTimer = Timer.scheduledTimer(withTimeInterval: TimeInterval(refreshInterval), repeats: true, block: { _ in
statusUpdateTimer = Timer.init(timeInterval: refreshInterval, repeats: true, block: { _ in
debugPrint("presence updating")
self.updateStatus()
// print("presence updating")
})
RunLoop.main.add(statusUpdateTimer!, forMode: .common)
statusUpdateTimer!.fire()
}

Expand Down Expand Up @@ -62,69 +63,77 @@ class AppDelegate: NSObject, NSApplicationDelegate {
p.timestamps.start = startDate!
p.timestamps.end = nil
rpc!.setPresence(p)
// print("updating RP")
debugPrint("updating RP")
}

func initRPC() {
debugPrint("init RPC")
// init discord stuff
rpc = SwordRPC.init(appId: discordClientId)
rpc!.delegate = self
// the API doesnt seem to like it if we try to connect too often?
discordConnectTimer = Timer.scheduledTimer(withTimeInterval: 5, repeats: true, block: { timer in
discordConnectTimer = Timer.scheduledTimer(withTimeInterval: discordRPCconnectInterval, repeats: true, block: { timer in
debugPrint("trying RPC connect...")
if self.rpc!.connect() {
// print("connected")
debugPrint("RPC connected")
timer.invalidate()
} else {
debugPrint("RPC connect failed")
}
})
DispatchQueue.main.asyncAfter(deadline: .now() + 5, execute: {
DispatchQueue.main.asyncAfter(deadline: .now() + discordRPCconnectInterval, execute: {
self.discordConnectTimer!.fire()
})
}

func deinitRPC() {
debugPrint("deinit RPC")
self.rpc!.setPresence(RichPresence())
// self.rpc!.disconnect()
discordConnectTimer?.invalidate()
self.rpc = nil
}

func applicationDidFinishLaunching(_ aNotification: Notification) {
// print("app launched")
let openApps = NSWorkspace.shared.runningApplications
var xcodeOpen = openApps.filter({$0.bundleIdentifier == xcodeBundleId}).count > 0
var discordOpen = openApps.filter({$0.bundleIdentifier == discordBundleId}).count > 0
// keep track of whether discord or xcode are running
var xcodeOpen = NSWorkspace.shared.runningApplications.filter({$0.bundleIdentifier == xcodeBundleId}).count > 0
var discordOpen = NSWorkspace.shared.runningApplications.filter({$0.bundleIdentifier == discordBundleId}).count > 0

// one time check on startup
if xcodeOpen && discordOpen {
initRPC()
}

let notifCenter = NSWorkspace.shared.notificationCenter

// run on Discord/Xcode launch
notifCenter.addObserver(forName: NSWorkspace.didLaunchApplicationNotification, object: nil, queue: nil, using: { notif in
// run on application launch
NSWorkspace.shared.notificationCenter.addObserver(forName: NSWorkspace.didLaunchApplicationNotification, object: nil, queue: nil, using: { notif in
if let app = notif.userInfo?[NSWorkspace.applicationUserInfoKey] as? NSRunningApplication {
let appName = app.bundleIdentifier
if appName == xcodeBundleId {
debugPrint("xcode open")
xcodeOpen = true
}
if appName == discordBundleId {
debugPrint("discord open")
discordOpen = true
}

if xcodeOpen && discordOpen {
self.initRPC()
}
}
})

// run on Discord/Xcode close
notifCenter.addObserver(forName: NSWorkspace.didTerminateApplicationNotification, object: nil, queue: nil, using: { notif in
// run on application close
NSWorkspace.shared.notificationCenter.addObserver(forName: NSWorkspace.didTerminateApplicationNotification, object: nil, queue: nil, using: { notif in
if let app = notif.userInfo?[NSWorkspace.applicationUserInfoKey] as? NSRunningApplication {
let appName = app.bundleIdentifier
if appName == xcodeBundleId {
debugPrint("xcode closed")
xcodeOpen = false
self.deinitRPC()
}
if appName == discordBundleId {
debugPrint("discord closed")
discordOpen = false
self.deinitRPC()
}
Expand All @@ -136,7 +145,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {

func applicationWillTerminate(_ aNotification: Notification) {
// Insert code here to tear down your application
// print("app closing")
debugPrint("RPFX shutting down...")
deinitRPC()
statusUpdateTimer?.invalidate()
discordConnectTimer?.invalidate()
Expand All @@ -147,23 +156,17 @@ class AppDelegate: NSObject, NSApplicationDelegate {

extension AppDelegate: SwordRPCDelegate {
func swordRPCDidConnect(_ rpc: SwordRPC) {
// print("SwordRPC connected")
debugPrint("SwordRPC connected")
startDate = Date()
beginTimer()
}

func swordRPCDidDisconnect(_ rpc: SwordRPC, code: Int?, message msg: String?) {
// print("disconnected")
debugPrint("disconnected")
statusUpdateTimer?.invalidate()
}

func swordRPCDidReceiveError(_ rpc: SwordRPC, code: Int, message msg: String) {

}
}

struct AppDelegate_Previews: PreviewProvider {
static var previews: some View {
/*@START_MENU_TOKEN@*/Text("Hello, World!")/*@END_MENU_TOKEN@*/
}
}
56 changes: 33 additions & 23 deletions RPFX/Assets.xcassets/AppIcon.appiconset/Contents.json
Original file line number Diff line number Diff line change
@@ -1,58 +1,68 @@
{
"images" : [
{
"filename" : "RPFX-1033.png",
"idiom" : "mac",
"size" : "16x16",
"scale" : "1x"
"scale" : "1x",
"size" : "16x16"
},
{
"filename" : "RPFX-1032.png",
"idiom" : "mac",
"size" : "16x16",
"scale" : "2x"
"scale" : "2x",
"size" : "16x16"
},
{
"filename" : "RPFX-1031.png",
"idiom" : "mac",
"size" : "32x32",
"scale" : "1x"
"scale" : "1x",
"size" : "32x32"
},
{
"filename" : "RPFX-1030.png",
"idiom" : "mac",
"size" : "32x32",
"scale" : "2x"
"scale" : "2x",
"size" : "32x32"
},
{
"filename" : "RPFX-1029.png",
"idiom" : "mac",
"size" : "128x128",
"scale" : "1x"
"scale" : "1x",
"size" : "128x128"
},
{
"filename" : "RPFX-1028.png",
"idiom" : "mac",
"size" : "128x128",
"scale" : "2x"
"scale" : "2x",
"size" : "128x128"
},
{
"filename" : "RPFX-1027.png",
"idiom" : "mac",
"size" : "256x256",
"scale" : "1x"
"scale" : "1x",
"size" : "256x256"
},
{
"filename" : "RPFX-1025.png",
"idiom" : "mac",
"size" : "256x256",
"scale" : "2x"
"scale" : "2x",
"size" : "256x256"
},
{
"filename" : "RPFX-1026.png",
"idiom" : "mac",
"size" : "512x512",
"scale" : "1x"
"scale" : "1x",
"size" : "512x512"
},
{
"filename" : "RPFX-1024.png",
"idiom" : "mac",
"size" : "512x512",
"scale" : "2x"
"scale" : "2x",
"size" : "512x512"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
"author" : "xcode",
"version" : 1
}
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions RPFX/Assets.xcassets/Contents.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"info" : {
"version" : 1,
"author" : "xcode"
"author" : "xcode",
"version" : 1
}
}
}
5 changes: 4 additions & 1 deletion RPFX/Constants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@

import Foundation

let debug = false

// used to register for notifs when Xcode opens/closes
let xcodeBundleId = "com.apple.dt.Xcode"
let discordBundleId = "com.hnc.Discord"

// how often we check Xcode for a status update
let refreshInterval = 5 // seconds
let refreshInterval = 5.0 // seconds
// how long to wait between attempts to connect to discord RPC
let discordRPCconnectInterval = 5.0 // seconds

// some other window names of Xcode
// Can we tell if the user is browsing Developer Docs?
Expand Down
6 changes: 6 additions & 0 deletions RPFX/HelperFunctions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@

import Foundation

func debugPrint(_ msg: String) {
if debug {
print(msg)
}
}

func getFileExt(_ file: String) -> String? {
if let ext = file.split(separator: ".").last {
return String(ext)
Expand Down

0 comments on commit cb446d1

Please sign in to comment.