Skip to content

Commit

Permalink
SwiftLint: fix line lengths + trailing whitespace
Browse files Browse the repository at this point in the history
  • Loading branch information
sitomani committed Oct 7, 2023
1 parent dc3b049 commit 539c40f
Show file tree
Hide file tree
Showing 60 changed files with 860 additions and 799 deletions.
3 changes: 0 additions & 3 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@ included: # paths to include during linting. `--path` is ignored if present.
- 4champ
excluded: # paths to ignore during linting. Takes precedence over `included`.
disabled_rules:
- trailing_whitespace
- line_length
- type_body_length
- file_length
- function_body_length
- nesting
identifier_name:
min_length: 2
Expand Down
59 changes: 28 additions & 31 deletions 4champ/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ let shareUtil = ShareUtility()

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

private var _bgFetchCallback: ((UIBackgroundFetchResult) -> Void)?

private var sharedMod: MMD?

private lazy var dlController: DownloadController = DownloadController()

var window: UIWindow?

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
Appearance.setup()
Expand All @@ -39,7 +39,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
// UNCOMMENT BELOW TWO LINES TO TEST LOCAL NOTIFICATIONS
// settings.prevCollectionSize = 0
// settings.newestPlayed = 152890

updateLatest()
UIApplication.shared.beginReceivingRemoteControlEvents()

Expand All @@ -50,7 +50,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
application.setMinimumBackgroundFetchInterval(UIApplication.backgroundFetchIntervalMinimum)
return true
}

func setupAVSession() {
let sess = AVAudioSession.sharedInstance()
do {
Expand All @@ -60,50 +60,47 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
log.error(error)
}
}

func applicationWillResignActive(_ application: UIApplication) {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
}

func applicationDidEnterBackground(_ application: UIApplication) {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

func applicationWillEnterForeground(_ application: UIApplication) {
}

func applicationDidBecomeActive(_ application: UIApplication) {
}

func applicationWillTerminate(_ application: UIApplication) {
modulePlayer.cleanup()
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

func application(_ application: UIApplication, performFetchWithCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
log.debug("performFetch")
_bgFetchCallback = completionHandler
updateLatest()
}

func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {


func application(_ application: UIApplication,
continue userActivity: NSUserActivity,
restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {

guard userActivity.activityType == NSUserActivityTypeBrowsingWeb,
let url = userActivity.webpageURL,
let components = URLComponents(url: url, resolvingAgainstBaseURL: true) else {
return false
}

if components.path == "/mod", let idString = components.queryItems?.first?.value, let modId = Int(idString) {
dlController.rootViewController = UIApplication.shared.windows[0].rootViewController
dlController.show(modId: modId)
}

return true
}

func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any] = [:]) -> Bool {
if url.scheme == "fourchamp" && url.host == "modules" {
if let idString = url.path.split(separator: "/").first, let modId = Int(idString) {
Expand All @@ -114,11 +111,11 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
}
return true
}

func application(_ application: UIApplication, handleOpen url: URL) -> Bool {
return true
}

/// Set up SwiftyBeaver logging
func setupLogging() {
let console = ConsoleDestination() // log to Xcode Console
Expand All @@ -130,14 +127,14 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
console.levelString.debug = "◾️"
console.levelString.verbose = "◽️"
log.addDestination(console)

console.minLevel = .warning
#if DEBUG
console.minLevel = .debug
#endif
log.info("Logger initialized")
}

func cleanupFiles() {
let fileManager = FileManager.default
let documentsURL = fileManager.urls(for: .documentDirectory, in: .userDomainMask)[0]
Expand All @@ -151,7 +148,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
log.error("Error while enumerating files \(documentsURL.path): \(error.localizedDescription)")
}
}

func updateLatest() {
log.debug("")
let req = RESTRoutes.latestId
Expand All @@ -167,12 +164,12 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
}
}
}

func updateCollectionSize(size: Int) {
log.debug("")
settings.collectionSize = size
let prevSize = settings.prevCollectionSize

// Only fire the request once per a given collectionSize/diff
if prevSize < size && settings.badgeCount < Constants.maxBadgeValue {
let fmt = "Radio_Notification".l13n()
Expand Down
2 changes: 1 addition & 1 deletion 4champ/Data/ModuleInfo+CoreDataProperties.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ extension ModuleInfo: Identifiable {
@NSManaged public var playlists: NSSet?
@NSManaged public var serviceId: NSNumber?
@NSManaged public var serviceKey: String?

public var id: Int {
return modId?.intValue ?? 0
}
Expand Down
2 changes: 1 addition & 1 deletion 4champ/Data/Playlist+CoreDataProperties.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ extension Playlist: Identifiable {
@nonobjc public class func fetchRequest() -> NSFetchRequest<Playlist> {
return NSFetchRequest<Playlist>(entityName: "Playlist")
}

@NSManaged public var locked: NSNumber?
@NSManaged public var playhead: NSNumber?
@NSManaged public var playmode: NSNumber?
Expand Down
14 changes: 7 additions & 7 deletions 4champ/Data/Structs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ struct Notifications {
struct MMD: Identifiable {
init() {
}

static let supportedTypes: [String] = Replay.supportedFormats

init(cdi: ModuleInfo) {
self.init()
self.composer = cdi.modAuthor
Expand All @@ -51,7 +51,7 @@ struct MMD: Identifiable {
self.serviceKey = cdi.serviceKey
self.favorite = cdi.modFavorite?.boolValue ?? false
}

init(path: String, modId: Int) {
self.init()
downloadPath = URL.init(string: path)
Expand All @@ -69,7 +69,7 @@ struct MMD: Identifiable {
}
}
}

var id: Int?
var name: String?
var type: String?
Expand All @@ -87,22 +87,22 @@ struct MMD: Identifiable {
}
return false
}

func hasBeenSaved() -> Bool {
guard let modId = self.id else {
return false
}
let saved = moduleStorage.getModuleById(modId)
return saved != nil
}

func queueIndex() -> Int? {
if let queueIndex = modulePlayer.playQueue.firstIndex(of: self) {
return queueIndex
}
return nil
}

func supported() -> Bool {
if MMD.supportedTypes.contains(self.type ?? "") && (self.note?.count ?? 0) == 0 {
return true
Expand Down
24 changes: 13 additions & 11 deletions 4champ/Networking/ModuleFetcher.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,16 @@ class ModuleFetcher {
delegate?.fetcherStateChanged(self, state: state)
}
}

convenience init(delegate: ModuleFetcherDelegate) {
self.init()
self.delegate = delegate
}

deinit {
log.debug("")
}

/**
Fetches a module based on Amiga Music Preservation module id. In case the module
is available in local storage, will complete immediately through state change to `FetcherState.done`.
Expand All @@ -76,7 +76,7 @@ class ModuleFetcher {
state = .done(mmd: mmd)
return
}

let req = RESTRoutes.modulePath(id: ampId)
currentRequest = AF.request(req).validate().responseString { resp in
switch resp.result {
Expand All @@ -90,7 +90,7 @@ class ModuleFetcher {
}
}
}

/**
Cancels current fetch request if any.
*/
Expand All @@ -99,7 +99,7 @@ class ModuleFetcher {
req.cancel()
currentRequest = nil
}

/**
private function that fetches the module from the identified download link,
unpacks it and saves to disk. After completion, reports the module metadata on the
Expand All @@ -118,7 +118,7 @@ class ModuleFetcher {
self.state = .failed(err: error)
return
}

if case let .success(moduleData) = resp.result {
self.state = .unpacking
if let moduleDataUnzipped = self.gzipInflate(data: moduleData) {
Expand All @@ -133,11 +133,13 @@ class ModuleFetcher {
do {
// store to file and make sure it's not writing over an existing mod
var numberExt = 0
var localPath = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).last!.appendingPathComponent(mmd.name!).appendingPathExtension(mmd.type!)
var localPath = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)
.last!.appendingPathComponent(mmd.name!).appendingPathExtension(mmd.type!)
while FileManager.default.fileExists(atPath: localPath.path) {
numberExt += 1
let filename = mmd.name! + "_\(numberExt)"
localPath = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).last!.appendingPathComponent(filename).appendingPathExtension(mmd.type!)
localPath = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)
.last!.appendingPathComponent(filename).appendingPathExtension(mmd.type!)
}
mmd.localPath = localPath
try moduleDataUnzipped.write(to: mmd.localPath!, options: .atomic)
Expand All @@ -158,7 +160,7 @@ class ModuleFetcher {
self.delegate?.fetcherStateChanged(self, state: FetcherState.downloading(progress: currentProg))
}
}

/**
Unzips the module data using GzipSwift
- parameters:
Expand All @@ -181,7 +183,7 @@ extension ModuleFetcher: Hashable {
static func == (left: ModuleFetcher, right: ModuleFetcher) -> Bool {
return left === right
}

func hash(into hasher: inout Hasher) {
hasher.combine(ObjectIdentifier(self).hashValue)
}
Expand Down
10 changes: 5 additions & 5 deletions 4champ/Networking/RESTRoutes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ enum SearchType: String {
case group
case composer
case meta

/**
Returns the localized name for the search type (shown on search view)
*/
Expand All @@ -45,7 +45,7 @@ enum RESTRoutes: URLRequestConvertible {
case search(type: SearchType, text: String, position: Int)
case listComposers(groupId: Int)
case listModules(composerId: Int)

/// network route tuple variable
var route: (path: String, parameters: [String: Any]?) {
switch self {
Expand All @@ -61,17 +61,17 @@ enum RESTRoutes: URLRequestConvertible {
return("list_modules", ["t": composerId])
}
}

// URLRequestConvertible protocol implementation
func asURLRequest() throws -> URLRequest {
guard let url = URL.init(string: self.route.path, relativeTo: URL.init(string: "https://4champ.net")) else {
// guard let url = URL.init(string: self.route.path, relativeTo: URL.init(string: "http:https://localhost:8081")) else {
throw NSError.init()
}

var request = URLRequest(url: url)
request.httpMethod = HTTPMethod.get.rawValue

let urlRequest = try Alamofire.URLEncoding.default.encode(request, with: route.parameters)
return urlRequest
}
Expand Down
Loading

0 comments on commit 539c40f

Please sign in to comment.