Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
Screenshottr
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
broman
Screenshottr
Commits
480872ed
Commit
480872ed
authored
7 years ago
by
Spotlight
Browse files
Options
Downloads
Patches
Plain Diff
Fix duplication error
parent
18b979e3
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Screenshottr/UploadManager.swift
+28
-15
28 additions, 15 deletions
Screenshottr/UploadManager.swift
with
28 additions
and
15 deletions
Screenshottr/UploadManager.swift
+
28
−
15
View file @
480872ed
...
...
@@ -27,31 +27,41 @@ class UploadManager : NSObject {
#endif
}
else
{
defaults
.
set
(
true
,
forKey
:
uploadingKey
)
// This could probably be done better
// oh well lol
sleep
(
2
)
let
fileManager
=
FileManager
.
default
do
{
// Grab contents by predicate, convert to array, loop through array with paths
let
allFiles
=
try
fileManager
.
contentsOfDirectory
(
atPath
:
path
)
let
screenshotPredicate
=
NSPredicate
(
format
:
"self BEGINSWITH 'Screen Shot'"
)
let
screenshotFiles
=
(
allFiles
as
NSArray
)
.
filtered
(
using
:
screenshotPredicate
)
let
toUpload
:
[
String
]
=
screenshotFiles
.
flatMap
({
$0
as?
String
})
for
fileName
in
to
Upload
{
let
toSeach
:
[
String
]
=
(
allFiles
as
NSArray
)
.
flatMap
({
$0
as?
String
}
)
var
toUpload
:
[
URL
]
=
[]
for
fileName
in
to
Seach
{
let
filePath
=
NSURL
(
fileURLWithPath
:
path
)
.
appendingPathComponent
(
fileName
)
!
let
metadata
:
NSMetadataItem
?
=
NSMetadataItem
.
init
(
url
:
filePath
)
if
(
metadata
==
nil
)
{
// This file is no friend of mine.
return
}
// Check if tagged as screenshot
let
isScreenshot
:
Int
=
metadata
?
.
value
(
forAttribute
:
"kMDItemIsScreenCapture"
)
as!
Int
?
??
0
if
(
isScreenshot
==
1
)
{
switchForProvider
(
path
:
filePath
.
path
,
type
:
type
,
shouldDelete
:
true
)
// This file is no friend of mine
print
(
"That probably shouldn't have happened. File:
\(
filePath
)
"
)
}
else
{
// Check if tagged as screenshot
let
test
:
Bool
=
metadata
?
.
value
(
forAttribute
:
"kMDItemIsScreenCapture"
)
as!
Bool
?
??
false
if
(
test
)
{
toUpload
.
append
(
filePath
)
print
(
toUpload
)
}
}
}
print
(
"
\(
toUpload
)
topkek"
)
for
screenshot
in
toUpload
{
switchForProvider
(
path
:
screenshot
.
path
,
type
:
type
,
shouldDelete
:
true
)
}
defaults
.
set
(
false
,
forKey
:
uploadingKey
)
}
catch
let
error
as
NSError
{
print
(
"Ooops! Something went wrong:
\(
error
.
localizedDescription
)
"
)
showFailureNotification
(
errorText
:
error
.
localizedDescription
)
defaults
.
set
(
false
,
forKey
:
uploadingKey
)
}
defaults
.
set
(
false
,
forKey
:
uploadingKey
)
}
}
else
{
switchForProvider
(
path
:
path
,
type
:
type
,
shouldDelete
:
false
)
...
...
@@ -62,19 +72,21 @@ class UploadManager : NSObject {
switch
(
type
)
{
case
.
GoogleCloudPlatform
:
GCPAuthHandler
()
.
uploadFile
(
path
:
path
)
{
(
error
,
url
)
in
self
.
finishUp
(
path
:
path
,
possibleError
:
error
,
shouldDelete
:
shouldDelete
,
url
:
url
)
self
.
finishUp
(
path
:
path
,
possibleError
:
error
,
shouldDelete
:
shouldDelete
,
url
:
url
)
{}
}
break
case
.
Pomf
:
PomfManager
()
.
uploadFile
(
path
:
path
)
{
(
error
,
url
)
in
self
.
finishUp
(
path
:
path
,
possibleError
:
error
,
shouldDelete
:
shouldDelete
,
url
:
url
)
self
.
finishUp
(
path
:
path
,
possibleError
:
error
,
shouldDelete
:
shouldDelete
,
url
:
url
)
{}
}
break
}
}
func
finishUp
(
path
:
String
,
possibleError
:
NSError
?,
shouldDelete
:
Bool
,
url
:
String
)
{
func
finishUp
(
path
:
String
,
possibleError
:
NSError
?,
shouldDelete
:
Bool
,
url
:
String
,
handler
:
()
->
Void
)
{
if
(
possibleError
!=
nil
)
{
showFailureNotification
(
errorText
:
(
possibleError
?
.
localizedDescription
)
!
)
handler
()
}
else
{
NSPasteboard
.
general
()
.
clearContents
()
NSPasteboard
.
general
()
.
setString
(
url
,
forType
:
NSPasteboardTypeString
)
...
...
@@ -96,6 +108,7 @@ class UploadManager : NSObject {
notification
.
soundName
=
NSUserNotificationDefaultSoundName
NSUserNotificationCenter
.
default
.
deliver
(
notification
)
handler
()
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment