Skip to content

Commit

Permalink
Add share extension (#156)
Browse files Browse the repository at this point in the history
Co-authored-by: Sindre Sorhus <sindresorhus@gmail.com>
  • Loading branch information
Koray Koska and sindresorhus committed Nov 10, 2019
1 parent c1739a1 commit 3771fc0
Show file tree
Hide file tree
Showing 10 changed files with 452 additions and 3 deletions.
174 changes: 173 additions & 1 deletion Gifski.xcodeproj/project.pbxproj
Expand Up @@ -7,6 +7,9 @@
objects = {

/* Begin PBXBuildFile section */
0E7925202329BDBE00058B94 /* ShareViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E79251F2329BDBE00058B94 /* ShareViewController.swift */; };
0E7925232329BDBE00058B94 /* ShareViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 0E7925212329BDBE00058B94 /* ShareViewController.xib */; };
0E7925282329BDBE00058B94 /* ShareExtension.appex in Embed App Extensions */ = {isa = PBXBuildFile; fileRef = 0E79251B2329BDBE00058B94 /* ShareExtension.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; };
6D86841721FD283B0044F6FE /* ConversionCompletedViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6D86841121FD283B0044F6FE /* ConversionCompletedViewController.swift */; };
6D86841821FD283B0044F6FE /* DraggableFile.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6D86841621FD283B0044F6FE /* DraggableFile.swift */; };
8548806522B78E8300E97401 /* IntTextField.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8548806422B78E8300E97401 /* IntTextField.swift */; };
Expand Down Expand Up @@ -46,6 +49,13 @@
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
0E7925262329BDBE00058B94 /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = E3AE627B1E5CD2F300035A2F /* Project object */;
proxyType = 1;
remoteGlobalIDString = 0E79251A2329BDBE00058B94;
remoteInfo = ShareExtension;
};
E3807B5A22BE315A00388F50 /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = 5A7524AD20D085FB00F12C99 /* gifski.xcodeproj */;
Expand All @@ -70,6 +80,17 @@
/* End PBXContainerItemProxy section */

/* Begin PBXCopyFilesBuildPhase section */
0E7925292329BDBE00058B94 /* Embed App Extensions */ = {
isa = PBXCopyFilesBuildPhase;
buildActionMask = 2147483647;
dstPath = "";
dstSubfolderSpec = 13;
files = (
0E7925282329BDBE00058B94 /* ShareExtension.appex in Embed App Extensions */,
);
name = "Embed App Extensions";
runOnlyForDeploymentPostprocessing = 0;
};
E34798D21F882FB3003F9142 /* Embed Frameworks */ = {
isa = PBXCopyFilesBuildPhase;
buildActionMask = 2147483647;
Expand All @@ -83,6 +104,11 @@
/* End PBXCopyFilesBuildPhase section */

/* Begin PBXFileReference section */
0E79251B2329BDBE00058B94 /* ShareExtension.appex */ = {isa = PBXFileReference; explicitFileType = "wrapper.app-extension"; includeInIndex = 0; path = ShareExtension.appex; sourceTree = BUILT_PRODUCTS_DIR; };
0E79251F2329BDBE00058B94 /* ShareViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = ShareViewController.swift; sourceTree = "<group>"; usesTabs = 1; };
0E7925222329BDBE00058B94 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/ShareViewController.xib; sourceTree = "<group>"; };
0E7925242329BDBE00058B94 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
0E7925252329BDBE00058B94 /* ShareExtension.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = ShareExtension.entitlements; sourceTree = "<group>"; };
5A7524AD20D085FB00F12C99 /* gifski.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = gifski.xcodeproj; path = "gifski-api/gifski.xcodeproj"; sourceTree = "<group>"; };
6D86841121FD283B0044F6FE /* ConversionCompletedViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = ConversionCompletedViewController.swift; sourceTree = "<group>"; usesTabs = 1; };
6D86841621FD283B0044F6FE /* DraggableFile.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = DraggableFile.swift; sourceTree = "<group>"; usesTabs = 1; };
Expand Down Expand Up @@ -127,6 +153,13 @@
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
0E7925182329BDBE00058B94 /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
E3AE62801E5CD2F300035A2F /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
Expand All @@ -140,6 +173,17 @@
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
0E79251C2329BDBE00058B94 /* ShareExtension */ = {
isa = PBXGroup;
children = (
0E79251F2329BDBE00058B94 /* ShareViewController.swift */,
0E7925212329BDBE00058B94 /* ShareViewController.xib */,
0E7925242329BDBE00058B94 /* Info.plist */,
0E7925252329BDBE00058B94 /* ShareExtension.entitlements */,
);
path = ShareExtension;
sourceTree = "<group>";
};
5A7524AE20D085FB00F12C99 /* Products */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -189,6 +233,7 @@
isa = PBXGroup;
children = (
E3AE62851E5CD2F300035A2F /* Gifski */,
0E79251C2329BDBE00058B94 /* ShareExtension */,
E3AE62841E5CD2F300035A2F /* Products */,
E317EE121F88305800359C57 /* Frameworks */,
5A7524AD20D085FB00F12C99 /* gifski.xcodeproj */,
Expand All @@ -200,6 +245,7 @@
isa = PBXGroup;
children = (
E3AE62831E5CD2F300035A2F /* Gifski.app */,
0E79251B2329BDBE00058B94 /* ShareExtension.appex */,
);
name = Products;
sourceTree = "<group>";
Expand Down Expand Up @@ -241,6 +287,23 @@
/* End PBXGroup section */

/* Begin PBXNativeTarget section */
0E79251A2329BDBE00058B94 /* ShareExtension */ = {
isa = PBXNativeTarget;
buildConfigurationList = 0E7925302329BDBE00058B94 /* Build configuration list for PBXNativeTarget "ShareExtension" */;
buildPhases = (
0E7925172329BDBE00058B94 /* Sources */,
0E7925182329BDBE00058B94 /* Frameworks */,
0E7925192329BDBE00058B94 /* Resources */,
);
buildRules = (
);
dependencies = (
);
name = ShareExtension;
productName = ShareExtension;
productReference = 0E79251B2329BDBE00058B94 /* ShareExtension.appex */;
productType = "com.apple.product-type.app-extension";
};
E3AE62821E5CD2F300035A2F /* Gifski */ = {
isa = PBXNativeTarget;
buildConfigurationList = E3AE62901E5CD2F300035A2F /* Build configuration list for PBXNativeTarget "Gifski" */;
Expand All @@ -251,10 +314,12 @@
E3AE62811E5CD2F300035A2F /* Resources */,
E34798D21F882FB3003F9142 /* Embed Frameworks */,
E3A9400C2182D718006981D5 /* Crashlytics */,
0E7925292329BDBE00058B94 /* Embed App Extensions */,
);
buildRules = (
);
dependencies = (
0E7925272329BDBE00058B94 /* PBXTargetDependency */,
);
name = Gifski;
productName = "HEIC Converter";
Expand All @@ -267,10 +332,13 @@
E3AE627B1E5CD2F300035A2F /* Project object */ = {
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0820;
LastSwiftUpdateCheck = 1100;
LastUpgradeCheck = 0930;
ORGANIZATIONNAME = "Sindre Sorhus";
TargetAttributes = {
0E79251A2329BDBE00058B94 = {
CreatedOnToolsVersion = 11.0;
};
E3AE62821E5CD2F300035A2F = {
CreatedOnToolsVersion = 8.2.1;
LastSwiftMigration = 1020;
Expand Down Expand Up @@ -305,6 +373,7 @@
projectRoot = "";
targets = (
E3AE62821E5CD2F300035A2F /* Gifski */,
0E79251A2329BDBE00058B94 /* ShareExtension */,
);
};
/* End PBXProject section */
Expand Down Expand Up @@ -334,6 +403,14 @@
/* End PBXReferenceProxy section */

/* Begin PBXResourcesBuildPhase section */
0E7925192329BDBE00058B94 /* Resources */ = {
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
0E7925232329BDBE00058B94 /* ShareViewController.xib in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
E3AE62811E5CD2F300035A2F /* Resources */ = {
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
Expand Down Expand Up @@ -387,6 +464,14 @@
/* End PBXShellScriptBuildPhase section */

/* Begin PBXSourcesBuildPhase section */
0E7925172329BDBE00058B94 /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
0E7925202329BDBE00058B94 /* ShareViewController.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
E3AE627F1E5CD2F300035A2F /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
Expand Down Expand Up @@ -424,7 +509,24 @@
};
/* End PBXSourcesBuildPhase section */

/* Begin PBXTargetDependency section */
0E7925272329BDBE00058B94 /* PBXTargetDependency */ = {
isa = PBXTargetDependency;
target = 0E79251A2329BDBE00058B94 /* ShareExtension */;
targetProxy = 0E7925262329BDBE00058B94 /* PBXContainerItemProxy */;
};
/* End PBXTargetDependency section */

/* Begin PBXVariantGroup section */
0E7925212329BDBE00058B94 /* ShareViewController.xib */ = {
isa = PBXVariantGroup;
children = (
0E7925222329BDBE00058B94 /* Base */,
);
name = ShareViewController.xib;
sourceTree = "<group>";
usesTabs = 1;
};
E3AE628A1E5CD2F300035A2F /* MainMenu.xib */ = {
isa = PBXVariantGroup;
children = (
Expand All @@ -436,6 +538,65 @@
/* End PBXVariantGroup section */

/* Begin XCBuildConfiguration section */
0E79252A2329BDBE00058B94 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++14";
CLANG_ENABLE_OBJC_WEAK = YES;
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
CODE_SIGN_ENTITLEMENTS = ShareExtension/ShareExtension.entitlements;
CODE_SIGN_IDENTITY = "Mac Developer";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = YG56YK5RN5;
ENABLE_HARDENED_RUNTIME = YES;
GCC_C_LANGUAGE_STANDARD = gnu11;
INFOPLIST_FILE = ShareExtension/Info.plist;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/../Frameworks",
"@executable_path/../../../../Frameworks",
);
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
PRODUCT_BUNDLE_IDENTIFIER = com.sindresorhus.Gifski.ShareExtension;
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_VERSION = 5.0;
};
name = Debug;
};
0E79252B2329BDBE00058B94 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++14";
CLANG_ENABLE_OBJC_WEAK = YES;
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
CODE_SIGN_ENTITLEMENTS = ShareExtension/ShareExtension.entitlements;
CODE_SIGN_IDENTITY = "Mac Developer";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = YG56YK5RN5;
ENABLE_HARDENED_RUNTIME = YES;
GCC_C_LANGUAGE_STANDARD = gnu11;
INFOPLIST_FILE = ShareExtension/Info.plist;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/../Frameworks",
"@executable_path/../../../../Frameworks",
);
MTL_FAST_MATH = YES;
PRODUCT_BUNDLE_IDENTIFIER = com.sindresorhus.Gifski.ShareExtension;
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_VERSION = 5.0;
};
name = Release;
};
E3AE628E1E5CD2F300035A2F /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
Expand Down Expand Up @@ -551,6 +712,7 @@
E3AE62911E5CD2F300035A2F /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = Gifski/Gifski.entitlements;
Expand Down Expand Up @@ -590,6 +752,7 @@
E3AE62921E5CD2F300035A2F /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = Gifski/Gifski.entitlements;
Expand Down Expand Up @@ -627,6 +790,15 @@
/* End XCBuildConfiguration section */

/* Begin XCConfigurationList section */
0E7925302329BDBE00058B94 /* Build configuration list for PBXNativeTarget "ShareExtension" */ = {
isa = XCConfigurationList;
buildConfigurations = (
0E79252A2329BDBE00058B94 /* Debug */,
0E79252B2329BDBE00058B94 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
E3AE627E1E5CD2F300035A2F /* Build configuration list for PBXProject "Gifski" */ = {
isa = XCConfigurationList;
buildConfigurations = (
Expand Down
21 changes: 19 additions & 2 deletions Gifski/AppDelegate.swift
Expand Up @@ -54,13 +54,30 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
return
}

var sharedVideoUrl = videoUrl

if videoUrl.host == "shareExtension" {
if let path = videoUrl.queryParameters["path"],
let appIdentifierPrefix = Bundle.main.infoDictionary?["AppIdentifierPrefix"] as? String,
let videoUrlString = path.removingPercentEncoding,
let appGroupShareVideoUrl = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: "\(appIdentifierPrefix).gifski_video_share_group")?.appendingPathComponent(videoUrlString) {
sharedVideoUrl = appGroupShareVideoUrl
} else {
NSAlert.showModal(
for: mainWindowController.window,
message: "Could not retrieve shared video"
)
return
}
}

// TODO: Simplify this. Make a function that calls the input when the app finished launching, or right away if it already has.
if hasFinishedLaunching {
mainWindowController.convert(videoUrl)
mainWindowController.convert(sharedVideoUrl.absoluteURL)
} else {
// This method is called before `applicationDidFinishLaunching`,
// so we buffer it up a video is "Open with" this app
urlToConvertOnLaunch = videoUrl
urlToConvertOnLaunch = sharedVideoUrl.absoluteURL
}
}

Expand Down
4 changes: 4 additions & 0 deletions Gifski/Gifski.entitlements
Expand Up @@ -4,6 +4,10 @@
<dict>
<key>com.apple.security.app-sandbox</key>
<true/>
<key>com.apple.security.application-groups</key>
<array>
<string>$(TeamIdentifierPrefix).gifski_video_share_group</string>
</array>
<key>com.apple.security.files.user-selected.read-write</key>
<true/>
<key>com.apple.security.network.client</key>
Expand Down
15 changes: 15 additions & 0 deletions Gifski/Info.plist
Expand Up @@ -2,6 +2,8 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>AppIdentifierPrefix</key>
<string>$(AppIdentifierPrefix)</string>
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleDocumentTypes</key>
Expand Down Expand Up @@ -37,6 +39,19 @@
<string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string>
<key>CFBundleShortVersionString</key>
<string>$(MARKETING_VERSION)</string>
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleTypeRole</key>
<string>Viewer</string>
<key>CFBundleURLName</key>
<string>com.sindresorhus.Gifski</string>
<key>CFBundleURLSchemes</key>
<array>
<string>gifski</string>
</array>
</dict>
</array>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>Fabric</key>
Expand Down

0 comments on commit 3771fc0

Please sign in to comment.