Skip to content

Commit 5010eea

Browse files
committed
More cleanup and formatting
1 parent 84936db commit 5010eea

File tree

6 files changed

+119
-112
lines changed

6 files changed

+119
-112
lines changed

Akedo/Akedo.xcodeproj/project.pbxproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -673,7 +673,7 @@
673673
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
674674
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
675675
CODE_SIGN_ENTITLEMENTS = "";
676-
CODE_SIGN_IDENTITY = "-";
676+
CODE_SIGN_IDENTITY = "";
677677
COMBINE_HIDPI_IMAGES = YES;
678678
INFOPLIST_FILE = Akedo/Info.plist;
679679
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks";
@@ -691,7 +691,7 @@
691691
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
692692
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
693693
CODE_SIGN_ENTITLEMENTS = "";
694-
CODE_SIGN_IDENTITY = "-";
694+
CODE_SIGN_IDENTITY = "";
695695
COMBINE_HIDPI_IMAGES = YES;
696696
INFOPLIST_FILE = Akedo/Info.plist;
697697
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks";

Akedo/Akedo/AppDelegate.swift

Lines changed: 39 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import Cocoa
1010
@NSApplicationMain
1111
class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDelegate {
1212

13+
// MARK: - Properties
14+
1315
/// The main status item for Akedo
1416
var uploadStatusItem : NSStatusItem = NSStatusItem();
1517

@@ -20,9 +22,17 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele
2022
AKPomf(name: "Fuwa fuwa~", url: "https://p.fuwafuwa.moe/", maxFileSize: 256),
2123
AKPomf(name: "Kyaa", url: "https://kyaa.sg/", maxFileSize: 100, uploadUrlPrefix: "r.")];
2224
// AKPomf(name: "Fluntcaps", url: "https://fluntcaps.me/", maxFileSize: 500, uploadUrlPrefix: "a.")];
23-
25+
26+
/// The last files that were sent to be uploaded
27+
var lastUploadFiles : [String] = [];
28+
29+
/// The last pomf host the user selected
30+
var lastUploadHost : AKPomf? = nil;
31+
32+
33+
// MARK: - Functions
34+
2435
func applicationDidFinishLaunching(_ aNotification: Notification) {
25-
// Insert code here to initialize your application
2636
// Create the status bar item
2737
createStatusItem();
2838

@@ -35,7 +45,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele
3545
return true;
3646
}
3747

38-
/// Creates uploadStatusBarItem
48+
/// Creates `uploadStatusBarItem`
3949
func createStatusItem() {
4050
// Create uploadStatusItem
4151
uploadStatusItem = NSStatusBar.system().statusItem(withLength: -1);
@@ -51,24 +61,25 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele
5161
uploadStatusItem.button!.action = #selector(AppDelegate.uploadStatusItemPressed);
5262
}
5363

54-
/// Called when the user presses uploadStatusItem
64+
/// Called when the user presses `uploadStatusItem`
5565
func uploadStatusItemPressed() {
56-
/// The open panel for prompting for file(s) to upload
66+
/// The open panel for prompting for files to upload
5767
let openPanel : NSOpenPanel = NSOpenPanel();
5868

5969
// Setup the open panel
6070
openPanel.canChooseDirectories = false;
6171
openPanel.prompt = "Upload";
6272
openPanel.allowsMultipleSelection = true;
6373

74+
// Activate Akedo
6475
NSApplication.shared().activate(ignoringOtherApps: true);
6576

6677
// Run the open panel, and if the user selects "Upload"...
6778
if(Bool(openPanel.runModal() as NSNumber)) {
6879
/// The list of files to upload
6980
var fileList : [String] = [];
7081

71-
// For every file URL selected in the openPanel...
82+
// For every file URL selected in the open panel...
7283
for(_, currentFileUrl) in openPanel.urls.enumerated() {
7384
// Add the current file URL to fileList
7485
fileList.append(currentFileUrl.absoluteString.removingPercentEncoding!.replacingOccurrences(of: "file://", with: ""));
@@ -84,56 +95,54 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele
8495
}
8596
}
8697

87-
/// The last files that were sent to be uploaded
88-
var lastUploadFiles : [String] = [];
89-
90-
/// The last pomf host the user selected
91-
var lastUploadHost : AKPomf? = nil;
92-
93-
// Prompts the user to select a pomf host and then uploads the given files to that host
98+
/// Prompts the user to select a pomf host and then uploads the given files to that host
99+
///
100+
/// - Parameter filePaths: The paths of the files to upload
94101
func uploadFiles(_ filePaths : [String]) {
95-
// Set lastUploadFiles
102+
// Store `lastUploadFiles` in `filePaths`
96103
lastUploadFiles = filePaths;
97104

98-
/// The combined size of all the files in filePaths, in megabytes
105+
/// The combined size of all the files in `filePaths`, in megabytes
99106
let combinedSize : Float = FileManager.default.sizeOfFiles(filePaths);
100107

101108
print("AppDelegate: Trying to upload \(combinedSize)MB of files");
102-
103-
// Print that we are prompting the user for a pomf host
104109
print("AppDelegate: Asking the user to select a pomf host");
105110

106-
// Create the new pomf selection window
111+
/// The window controller for the new pomf selection window
107112
let pomfSelectionWindowController : NSWindowController = NSStoryboard(name: "Main", bundle: Bundle.main).instantiateController(withIdentifier: "PomfSelectionWindowController") as! NSWindowController;
108113

109114
// Load the window
110115
pomfSelectionWindowController.loadWindow();
111116

112-
/// The AKPomfSelectionViewController of pomfSelectionWindowController
117+
/// The `AKPomfSelectionViewController` of `pomfSelectionWindowController`
113118
let pomfSelectionViewController : AKPomfSelectionViewController = (pomfSelectionWindowController.contentViewController as! AKPomfSelectionViewController);
114119

115-
// Set filesSize
120+
// Set `filesSize`
116121
pomfSelectionViewController.filesSize = combinedSize;
117122

118123
// Set the pomf host selected target and action
119124
pomfSelectionViewController.pomfSelectedTarget = self;
120125
pomfSelectionViewController.pomfSelectedAction = #selector(AppDelegate.pomfHostSelected(_:));
121126

127+
// If there is at least one pomf host in `pomfListItems`...
122128
if(pomfSelectionViewController.pomfListItems.count != 0) {
123129
// Present the pomf host selection window
124130
pomfSelectionWindowController.window!.makeKeyAndOrderFront(self);
125131
}
132+
// If there are no pomf hosts in `pomfListItems`...
126133
else {
134+
// Stop trying to upload and close the window
127135
pomfSelectionWindowController.window!.close();
128136
}
129137
}
130138

131-
/// Called when the user selects a pomf host presented by uploadFiles
139+
/// Called when the user selects a pomf host presented by `uploadFiles`
140+
///
141+
/// - Parameter pomf: The `AKPomf` that was selected
132142
func pomfHostSelected(_ pomf : AKPomf) {
133-
// Print the pomf host we will upload to
134143
print("AppDelegate: Uploading \(lastUploadFiles) to \"\(pomf.name)\"");
135144

136-
// Set lastUploadHost
145+
// Set `lastUploadHost`
137146
lastUploadHost = pomf;
138147

139148
// Post the notification saying we are uploading files and how many
@@ -142,22 +151,18 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele
142151

143152
// Setup the notification
144153
uploadingNotification.title = "Akedo";
145-
146-
if(lastUploadFiles.count > 1) {
147-
uploadingNotification.informativeText = "Uploading \(lastUploadFiles.count) files to \(pomf.name)";
148-
}
149-
else {
150-
uploadingNotification.informativeText = "Uploading \(lastUploadFiles.count) file to \(pomf.name)";
151-
}
154+
uploadingNotification.informativeText = "Uploading \(lastUploadFiles.count) file\((lastUploadFiles.count == 1) ? "" : "s") to \(pomf.name)";
152155

153156
// Deliver the notification
154157
NSUserNotificationCenter.default.deliver(uploadingNotification);
155158

156159
// Upload the files
157-
pomf.uploadFiles(lastUploadFiles, completionHandler: pomfUploadCompleted)
160+
pomf.upload(files: lastUploadFiles, completionHandler: pomfUploadCompleted);
158161
}
159162

160-
/// Called when the pomf upload from pomfHostSelected is completed
163+
/// Called when the pomf upload from `pomfHostSelected` is completed
164+
///
165+
/// - Parameter response: The response from the upload
161166
func pomfUploadCompleted(_ response : ([String], Bool)) {
162167
// If the upload was succesful...
163168
if(response.1) {
@@ -190,11 +195,8 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele
190195
// Setup the notification
191196
uploadFailedNotification.title = "Akedo";
192197

193-
if(response.0.count > 1) {
194-
uploadFailedNotification.informativeText = "Failed to upload \(response.0.count) files to \(lastUploadHost!.name)";
195-
}
196-
else if(response.0.count == 1) {
197-
uploadFailedNotification.informativeText = "Failed to upload \(response.0.count) file to \(lastUploadHost!.name)";
198+
if(response.0.count > 0) {
199+
uploadFailedNotification.informativeText = "Failed to upload \(response.0.count) file\((response.0.count == 1) ? "" : "s") to \(lastUploadHost!.name)";
198200
}
199201
else {
200202
uploadFailedNotification.informativeText = "Failed to connect to \(lastUploadHost!.name)";
@@ -203,7 +205,6 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele
203205
// Deliver the notification
204206
NSUserNotificationCenter.default.deliver(uploadFailedNotification);
205207

206-
// Print that we failed to upload the files
207208
print("AppDelegate: Failed to upload \(lastUploadFiles) to \(lastUploadHost!.name)");
208209
}
209210

@@ -230,8 +231,4 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele
230231
NSPasteboard.general().setString(urlsString, forType: NSStringPboardType);
231232
}
232233
}
233-
234-
func applicationWillTerminate(_ aNotification: Notification) {
235-
// Insert code here to tear down your application
236-
}
237234
}

0 commit comments

Comments
 (0)