diff --git a/README.md b/README.md index 351b59a..cb98357 100644 --- a/README.md +++ b/README.md @@ -2,9 +2,9 @@ # Spotify Lyrics -Install Extension: [Chrome](https://chrome.google.com/webstore/detail/spotify-lyrics/mkjfooclbdgjdclepjeepbmmjaclipod) | [Firefox](https://addons.mozilla.org/en-US/firefox/addon/spotify-lyrics/) +Install Extension: [Chrome](https://chrome.google.com/webstore/detail/spotify-lyrics/mkjfooclbdgjdclepjeepbmmjaclipod) | [Firefox](https://addons.mozilla.org/en-US/firefox/addon/spotify-lyrics/) | [Safari](https://github.com/mantou132/Spotify-Lyrics/releases) -Add lyrics button, when activated, the lyrics are displayed in the picture-in-picture window. +Add lyrics button, when activated, the lyrics are displayed in the Picture-in-Picture window. If you have any questions, please submit an [issue](https://github.com/mantou132/Spotify-Lyrics/issues). @@ -15,13 +15,14 @@ If you have any questions, please submit an [issue](https://github.com/mantou132 1. [Listen](https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver) for track info element. 2. Search for songs and download lyrics using [`NeteaseCloudMusicApi`](https://github.com/Binaryify/NeteaseCloudMusicApi). 3. Rendering lyrics to `` using [SVG](https://developer.mozilla.org/en-US/docs/Web/SVG/Element/foreignObject). -4. [Capture](https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/captureStream) video stream from `` and merge cover stream. +4. [Capture](https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/captureStream) video stream from `` and merge cover image. 5. Update lyrics scroll position with a [loop](https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/setTimeout). ## Compatibility * Firefox does not currently support [PiP WebAPI](https://bugzilla.mozilla.org/show_bug.cgi?id=1463402) * Chrome [70+](https://caniuse.com/#feat=picture-in-picture) +* Safari [14+](https://developer.apple.com/documentation/safariservices/safari_web_extensions) ## Recommend diff --git a/safari/spotify-lyrics/spotify-lyrics Extension/Info.plist b/safari/spotify-lyrics/spotify-lyrics Extension/Info.plist new file mode 100644 index 0000000..564594a --- /dev/null +++ b/safari/spotify-lyrics/spotify-lyrics Extension/Info.plist @@ -0,0 +1,33 @@ + + + + + CFBundleDevelopmentRegion + $(DEVELOPMENT_LANGUAGE) + CFBundleDisplayName + spotify-lyrics Extension + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + $(PRODUCT_BUNDLE_PACKAGE_TYPE) + CFBundleShortVersionString + 1.0 + CFBundleVersion + 1 + LSMinimumSystemVersion + $(MACOSX_DEPLOYMENT_TARGET) + NSExtension + + NSExtensionPointIdentifier + com.apple.Safari.web-extension + NSExtensionPrincipalClass + $(PRODUCT_MODULE_NAME).SafariWebExtensionHandler + + + diff --git a/safari/spotify-lyrics/spotify-lyrics Extension/SafariWebExtensionHandler.swift b/safari/spotify-lyrics/spotify-lyrics Extension/SafariWebExtensionHandler.swift new file mode 100644 index 0000000..c626dcb --- /dev/null +++ b/safari/spotify-lyrics/spotify-lyrics Extension/SafariWebExtensionHandler.swift @@ -0,0 +1,24 @@ +// +// SafariWebExtensionHandler.swift +// spotify-lyrics Extension +// +// Created by Xianqiao Wang on 2020/6/26. +// + +import SafariServices +import os.log + +class SafariWebExtensionHandler: NSObject, NSExtensionRequestHandling { + + func beginRequest(with context: NSExtensionContext) { + let item = context.inputItems[0] as! NSExtensionItem + let message = item.userInfo?[SFExtensionMessageKey] + os_log(.default, "Received message from browser.runtime.sendNativeMessage: %@", message as! CVarArg) + + let response = NSExtensionItem() + response.userInfo = [ SFExtensionMessageKey: [ "Response to": message ] ] + + context.completeRequest(returningItems: [response], completionHandler: nil) + } + +} diff --git a/safari/spotify-lyrics/spotify-lyrics Extension/spotify_lyrics_Extension.entitlements b/safari/spotify-lyrics/spotify-lyrics Extension/spotify_lyrics_Extension.entitlements new file mode 100644 index 0000000..f2ef3ae --- /dev/null +++ b/safari/spotify-lyrics/spotify-lyrics Extension/spotify_lyrics_Extension.entitlements @@ -0,0 +1,10 @@ + + + + + com.apple.security.app-sandbox + + com.apple.security.files.user-selected.read-only + + + diff --git a/safari/spotify-lyrics/spotify-lyrics.xcodeproj/project.pbxproj b/safari/spotify-lyrics/spotify-lyrics.xcodeproj/project.pbxproj new file mode 100644 index 0000000..7b0bc4c --- /dev/null +++ b/safari/spotify-lyrics/spotify-lyrics.xcodeproj/project.pbxproj @@ -0,0 +1,539 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 50; + objects = { + +/* Begin PBXBuildFile section */ + 7926D58F24A5908E000C6B52 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7926D58E24A5908E000C6B52 /* AppDelegate.swift */; }; + 7926D59224A5908E000C6B52 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 7926D59024A5908E000C6B52 /* Main.storyboard */; }; + 7926D59424A5908E000C6B52 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7926D59324A5908E000C6B52 /* ViewController.swift */; }; + 7926D59624A59090000C6B52 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 7926D59524A59090000C6B52 /* Assets.xcassets */; }; + 7926D59D24A59090000C6B52 /* spotify-lyrics Extension.appex in Embed App Extensions */ = {isa = PBXBuildFile; fileRef = 7926D59C24A59090000C6B52 /* spotify-lyrics Extension.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; }; + 7926D5A224A59090000C6B52 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7926D5A124A59090000C6B52 /* Cocoa.framework */; }; + 7926D5A524A59090000C6B52 /* SafariWebExtensionHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7926D5A424A59090000C6B52 /* SafariWebExtensionHandler.swift */; }; + 7926D5C924A596DA000C6B52 /* manifest.json in Resources */ = {isa = PBXBuildFile; fileRef = 7926D5AB24A59090000C6B52 /* manifest.json */; }; + 7926D5CA24A596DA000C6B52 /* background.js in Resources */ = {isa = PBXBuildFile; fileRef = 7926D5AD24A59090000C6B52 /* background.js */; }; + 7926D5CB24A596DA000C6B52 /* content.js in Resources */ = {isa = PBXBuildFile; fileRef = 7926D5AF24A59090000C6B52 /* content.js */; }; + 7926D5CC24A596DA000C6B52 /* popup.html in Resources */ = {isa = PBXBuildFile; fileRef = 7926D5B124A59090000C6B52 /* popup.html */; }; + 7926D5CE24A596DA000C6B52 /* popup.js in Resources */ = {isa = PBXBuildFile; fileRef = 7926D5B524A59090000C6B52 /* popup.js */; }; + 7926D5D024A598D4000C6B52 /* page.js in Resources */ = {isa = PBXBuildFile; fileRef = 7926D5CF24A598D4000C6B52 /* page.js */; }; + 7926D5D224A59922000C6B52 /* icons in Resources */ = {isa = PBXBuildFile; fileRef = 7926D5D124A59921000C6B52 /* icons */; }; + 7926D5D524A59937000C6B52 /* options.js in Resources */ = {isa = PBXBuildFile; fileRef = 7926D5D324A59937000C6B52 /* options.js */; }; + 7926D5D624A59937000C6B52 /* options.html in Resources */ = {isa = PBXBuildFile; fileRef = 7926D5D424A59937000C6B52 /* options.html */; }; +/* End PBXBuildFile section */ + +/* Begin PBXContainerItemProxy section */ + 7926D59E24A59090000C6B52 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 7926D58224A5908E000C6B52 /* Project object */; + proxyType = 1; + remoteGlobalIDString = 7926D59B24A59090000C6B52; + remoteInfo = "spotify-lyrics Extension"; + }; +/* End PBXContainerItemProxy section */ + +/* Begin PBXCopyFilesBuildPhase section */ + 7926D5BE24A59090000C6B52 /* Embed App Extensions */ = { + isa = PBXCopyFilesBuildPhase; + buildActionMask = 2147483647; + dstPath = ""; + dstSubfolderSpec = 13; + files = ( + 7926D59D24A59090000C6B52 /* spotify-lyrics Extension.appex in Embed App Extensions */, + ); + name = "Embed App Extensions"; + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXCopyFilesBuildPhase section */ + +/* Begin PBXFileReference section */ + 7926D58A24A5908E000C6B52 /* spotify-lyrics.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "spotify-lyrics.app"; sourceTree = BUILT_PRODUCTS_DIR; }; + 7926D58D24A5908E000C6B52 /* spotify_lyrics.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = spotify_lyrics.entitlements; sourceTree = ""; }; + 7926D58E24A5908E000C6B52 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; + 7926D59124A5908E000C6B52 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; + 7926D59324A5908E000C6B52 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; + 7926D59524A59090000C6B52 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; + 7926D59724A59090000C6B52 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + 7926D59C24A59090000C6B52 /* spotify-lyrics Extension.appex */ = {isa = PBXFileReference; explicitFileType = "wrapper.app-extension"; includeInIndex = 0; path = "spotify-lyrics Extension.appex"; sourceTree = BUILT_PRODUCTS_DIR; }; + 7926D5A124A59090000C6B52 /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = System/Library/Frameworks/Cocoa.framework; sourceTree = SDKROOT; }; + 7926D5A424A59090000C6B52 /* SafariWebExtensionHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SafariWebExtensionHandler.swift; sourceTree = ""; }; + 7926D5AB24A59090000C6B52 /* manifest.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = manifest.json; sourceTree = ""; }; + 7926D5AD24A59090000C6B52 /* background.js */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.javascript; path = background.js; sourceTree = ""; }; + 7926D5AF24A59090000C6B52 /* content.js */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.javascript; path = content.js; sourceTree = ""; }; + 7926D5B124A59090000C6B52 /* popup.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; path = popup.html; sourceTree = ""; }; + 7926D5B524A59090000C6B52 /* popup.js */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.javascript; path = popup.js; sourceTree = ""; }; + 7926D5B724A59090000C6B52 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + 7926D5B824A59090000C6B52 /* spotify_lyrics_Extension.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = spotify_lyrics_Extension.entitlements; sourceTree = ""; }; + 7926D5CF24A598D4000C6B52 /* page.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = page.js; sourceTree = ""; }; + 7926D5D124A59921000C6B52 /* icons */ = {isa = PBXFileReference; lastKnownFileType = folder; path = icons; sourceTree = ""; }; + 7926D5D324A59937000C6B52 /* options.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = options.js; sourceTree = ""; }; + 7926D5D424A59937000C6B52 /* options.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = options.html; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + 7926D58724A5908E000C6B52 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 7926D59924A59090000C6B52 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + 7926D5A224A59090000C6B52 /* Cocoa.framework in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 7926D58124A5908E000C6B52 = { + isa = PBXGroup; + children = ( + 7926D58C24A5908E000C6B52 /* spotify-lyrics */, + 7926D5A324A59090000C6B52 /* spotify-lyrics Extension */, + 7926D5A024A59090000C6B52 /* Frameworks */, + 7926D58B24A5908E000C6B52 /* Products */, + ); + sourceTree = ""; + }; + 7926D58B24A5908E000C6B52 /* Products */ = { + isa = PBXGroup; + children = ( + 7926D58A24A5908E000C6B52 /* spotify-lyrics.app */, + 7926D59C24A59090000C6B52 /* spotify-lyrics Extension.appex */, + ); + name = Products; + sourceTree = ""; + }; + 7926D58C24A5908E000C6B52 /* spotify-lyrics */ = { + isa = PBXGroup; + children = ( + 7926D58D24A5908E000C6B52 /* spotify_lyrics.entitlements */, + 7926D58E24A5908E000C6B52 /* AppDelegate.swift */, + 7926D59024A5908E000C6B52 /* Main.storyboard */, + 7926D59324A5908E000C6B52 /* ViewController.swift */, + 7926D59524A59090000C6B52 /* Assets.xcassets */, + 7926D59724A59090000C6B52 /* Info.plist */, + ); + path = "spotify-lyrics"; + sourceTree = ""; + }; + 7926D5A024A59090000C6B52 /* Frameworks */ = { + isa = PBXGroup; + children = ( + 7926D5A124A59090000C6B52 /* Cocoa.framework */, + ); + name = Frameworks; + sourceTree = ""; + }; + 7926D5A324A59090000C6B52 /* spotify-lyrics Extension */ = { + isa = PBXGroup; + children = ( + 7926D5A424A59090000C6B52 /* SafariWebExtensionHandler.swift */, + 7926D5B724A59090000C6B52 /* Info.plist */, + 7926D5B824A59090000C6B52 /* spotify_lyrics_Extension.entitlements */, + 7926D5A624A59090000C6B52 /* Resources */, + ); + path = "spotify-lyrics Extension"; + sourceTree = ""; + }; + 7926D5A624A59090000C6B52 /* Resources */ = { + isa = PBXGroup; + children = ( + 7926D5D424A59937000C6B52 /* options.html */, + 7926D5D324A59937000C6B52 /* options.js */, + 7926D5D124A59921000C6B52 /* icons */, + 7926D5CF24A598D4000C6B52 /* page.js */, + 7926D5AB24A59090000C6B52 /* manifest.json */, + 7926D5AD24A59090000C6B52 /* background.js */, + 7926D5AF24A59090000C6B52 /* content.js */, + 7926D5B124A59090000C6B52 /* popup.html */, + 7926D5B524A59090000C6B52 /* popup.js */, + ); + name = Resources; + path = ../../../extension; + sourceTree = ""; + usesTabs = 0; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + 7926D58924A5908E000C6B52 /* spotify-lyrics */ = { + isa = PBXNativeTarget; + buildConfigurationList = 7926D5BF24A59090000C6B52 /* Build configuration list for PBXNativeTarget "spotify-lyrics" */; + buildPhases = ( + 7926D58624A5908E000C6B52 /* Sources */, + 7926D58724A5908E000C6B52 /* Frameworks */, + 7926D58824A5908E000C6B52 /* Resources */, + 7926D5BE24A59090000C6B52 /* Embed App Extensions */, + ); + buildRules = ( + ); + dependencies = ( + 7926D59F24A59090000C6B52 /* PBXTargetDependency */, + ); + name = "spotify-lyrics"; + productName = "spotify-lyrics"; + productReference = 7926D58A24A5908E000C6B52 /* spotify-lyrics.app */; + productType = "com.apple.product-type.application"; + }; + 7926D59B24A59090000C6B52 /* spotify-lyrics Extension */ = { + isa = PBXNativeTarget; + buildConfigurationList = 7926D5BB24A59090000C6B52 /* Build configuration list for PBXNativeTarget "spotify-lyrics Extension" */; + buildPhases = ( + 7926D59824A59090000C6B52 /* Sources */, + 7926D59924A59090000C6B52 /* Frameworks */, + 7926D5C624A596CD000C6B52 /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = "spotify-lyrics Extension"; + productName = "spotify-lyrics Extension"; + productReference = 7926D59C24A59090000C6B52 /* spotify-lyrics Extension.appex */; + productType = "com.apple.product-type.app-extension"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 7926D58224A5908E000C6B52 /* Project object */ = { + isa = PBXProject; + attributes = { + LastSwiftUpdateCheck = 1200; + LastUpgradeCheck = 1200; + TargetAttributes = { + 7926D58924A5908E000C6B52 = { + CreatedOnToolsVersion = 12.0; + }; + 7926D59B24A59090000C6B52 = { + CreatedOnToolsVersion = 12.0; + }; + }; + }; + buildConfigurationList = 7926D58524A5908E000C6B52 /* Build configuration list for PBXProject "spotify-lyrics" */; + compatibilityVersion = "Xcode 9.3"; + developmentRegion = en; + hasScannedForEncodings = 0; + knownRegions = ( + en, + Base, + ); + mainGroup = 7926D58124A5908E000C6B52; + productRefGroup = 7926D58B24A5908E000C6B52 /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + 7926D58924A5908E000C6B52 /* spotify-lyrics */, + 7926D59B24A59090000C6B52 /* spotify-lyrics Extension */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXResourcesBuildPhase section */ + 7926D58824A5908E000C6B52 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 7926D59624A59090000C6B52 /* Assets.xcassets in Resources */, + 7926D59224A5908E000C6B52 /* Main.storyboard in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 7926D5C624A596CD000C6B52 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 7926D5C924A596DA000C6B52 /* manifest.json in Resources */, + 7926D5D524A59937000C6B52 /* options.js in Resources */, + 7926D5CB24A596DA000C6B52 /* content.js in Resources */, + 7926D5CA24A596DA000C6B52 /* background.js in Resources */, + 7926D5D024A598D4000C6B52 /* page.js in Resources */, + 7926D5CC24A596DA000C6B52 /* popup.html in Resources */, + 7926D5D224A59922000C6B52 /* icons in Resources */, + 7926D5CE24A596DA000C6B52 /* popup.js in Resources */, + 7926D5D624A59937000C6B52 /* options.html in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + 7926D58624A5908E000C6B52 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 7926D59424A5908E000C6B52 /* ViewController.swift in Sources */, + 7926D58F24A5908E000C6B52 /* AppDelegate.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 7926D59824A59090000C6B52 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 7926D5A524A59090000C6B52 /* SafariWebExtensionHandler.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin PBXTargetDependency section */ + 7926D59F24A59090000C6B52 /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = 7926D59B24A59090000C6B52 /* spotify-lyrics Extension */; + targetProxy = 7926D59E24A59090000C6B52 /* PBXContainerItemProxy */; + }; +/* End PBXTargetDependency section */ + +/* Begin PBXVariantGroup section */ + 7926D59024A5908E000C6B52 /* Main.storyboard */ = { + isa = PBXVariantGroup; + children = ( + 7926D59124A5908E000C6B52 /* Base */, + ); + name = Main.storyboard; + sourceTree = ""; + }; +/* End PBXVariantGroup section */ + +/* Begin XCBuildConfiguration section */ + 7926D5B924A59090000C6B52 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = dwarf; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; + GCC_C_LANGUAGE_STANDARD = gnu11; + GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + MACOSX_DEPLOYMENT_TARGET = 10.15; + MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; + MTL_FAST_MATH = YES; + ONLY_ACTIVE_ARCH = YES; + SDKROOT = macosx; + SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + }; + name = Debug; + }; + 7926D5BA24A59090000C6B52 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu11; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + MACOSX_DEPLOYMENT_TARGET = 10.15; + MTL_ENABLE_DEBUG_INFO = NO; + MTL_FAST_MATH = YES; + SDKROOT = macosx; + SWIFT_COMPILATION_MODE = wholemodule; + SWIFT_OPTIMIZATION_LEVEL = "-O"; + }; + name = Release; + }; + 7926D5BC24A59090000C6B52 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + CODE_SIGN_ENTITLEMENTS = "spotify-lyrics Extension/spotify_lyrics_Extension.entitlements"; + CODE_SIGN_STYLE = Automatic; + DEVELOPMENT_TEAM = 862Y7Q872C; + INFOPLIST_FILE = "spotify-lyrics Extension/Info.plist"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/../Frameworks", + "@executable_path/../../../../Frameworks", + ); + MACOSX_DEPLOYMENT_TARGET = 10.14; + PRODUCT_BUNDLE_IDENTIFIER = "xianqiao.wang.spotify-lyrics-Extension"; + PRODUCT_NAME = "$(TARGET_NAME)"; + SKIP_INSTALL = YES; + SWIFT_VERSION = 5.0; + }; + name = Debug; + }; + 7926D5BD24A59090000C6B52 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + CODE_SIGN_ENTITLEMENTS = "spotify-lyrics Extension/spotify_lyrics_Extension.entitlements"; + CODE_SIGN_STYLE = Automatic; + DEVELOPMENT_TEAM = 862Y7Q872C; + INFOPLIST_FILE = "spotify-lyrics Extension/Info.plist"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/../Frameworks", + "@executable_path/../../../../Frameworks", + ); + MACOSX_DEPLOYMENT_TARGET = 10.14; + PRODUCT_BUNDLE_IDENTIFIER = "xianqiao.wang.spotify-lyrics-Extension"; + PRODUCT_NAME = "$(TARGET_NAME)"; + SKIP_INSTALL = YES; + SWIFT_VERSION = 5.0; + }; + name = Release; + }; + 7926D5C024A59090000C6B52 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; + CODE_SIGN_ENTITLEMENTS = "spotify-lyrics/spotify_lyrics.entitlements"; + CODE_SIGN_STYLE = Automatic; + COMBINE_HIDPI_IMAGES = YES; + DEVELOPMENT_TEAM = 862Y7Q872C; + INFOPLIST_FILE = "spotify-lyrics/Info.plist"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/../Frameworks", + ); + MACOSX_DEPLOYMENT_TARGET = 10.14; + PRODUCT_BUNDLE_IDENTIFIER = "xianqiao.wang.spotify-lyrics"; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 5.0; + }; + name = Debug; + }; + 7926D5C124A59090000C6B52 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; + CODE_SIGN_ENTITLEMENTS = "spotify-lyrics/spotify_lyrics.entitlements"; + CODE_SIGN_STYLE = Automatic; + COMBINE_HIDPI_IMAGES = YES; + DEVELOPMENT_TEAM = 862Y7Q872C; + INFOPLIST_FILE = "spotify-lyrics/Info.plist"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/../Frameworks", + ); + MACOSX_DEPLOYMENT_TARGET = 10.14; + PRODUCT_BUNDLE_IDENTIFIER = "xianqiao.wang.spotify-lyrics"; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 5.0; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 7926D58524A5908E000C6B52 /* Build configuration list for PBXProject "spotify-lyrics" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 7926D5B924A59090000C6B52 /* Debug */, + 7926D5BA24A59090000C6B52 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 7926D5BB24A59090000C6B52 /* Build configuration list for PBXNativeTarget "spotify-lyrics Extension" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 7926D5BC24A59090000C6B52 /* Debug */, + 7926D5BD24A59090000C6B52 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 7926D5BF24A59090000C6B52 /* Build configuration list for PBXNativeTarget "spotify-lyrics" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 7926D5C024A59090000C6B52 /* Debug */, + 7926D5C124A59090000C6B52 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = 7926D58224A5908E000C6B52 /* Project object */; +} diff --git a/safari/spotify-lyrics/spotify-lyrics.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/safari/spotify-lyrics/spotify-lyrics.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..919434a --- /dev/null +++ b/safari/spotify-lyrics/spotify-lyrics.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/safari/spotify-lyrics/spotify-lyrics.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/safari/spotify-lyrics/spotify-lyrics.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 0000000..18d9810 --- /dev/null +++ b/safari/spotify-lyrics/spotify-lyrics.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/safari/spotify-lyrics/spotify-lyrics.xcodeproj/project.xcworkspace/xcuserdata/mantou.xcuserdatad/UserInterfaceState.xcuserstate b/safari/spotify-lyrics/spotify-lyrics.xcodeproj/project.xcworkspace/xcuserdata/mantou.xcuserdatad/UserInterfaceState.xcuserstate new file mode 100644 index 0000000..9c4c548 Binary files /dev/null and b/safari/spotify-lyrics/spotify-lyrics.xcodeproj/project.xcworkspace/xcuserdata/mantou.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/safari/spotify-lyrics/spotify-lyrics.xcodeproj/xcuserdata/mantou.xcuserdatad/xcschemes/xcschememanagement.plist b/safari/spotify-lyrics/spotify-lyrics.xcodeproj/xcuserdata/mantou.xcuserdatad/xcschemes/xcschememanagement.plist new file mode 100644 index 0000000..e2f923a --- /dev/null +++ b/safari/spotify-lyrics/spotify-lyrics.xcodeproj/xcuserdata/mantou.xcuserdatad/xcschemes/xcschememanagement.plist @@ -0,0 +1,14 @@ + + + + + SchemeUserState + + spotify-lyrics.xcscheme_^#shared#^_ + + orderHint + 0 + + + + diff --git a/safari/spotify-lyrics/spotify-lyrics/AppDelegate.swift b/safari/spotify-lyrics/spotify-lyrics/AppDelegate.swift new file mode 100644 index 0000000..6c0e8b6 --- /dev/null +++ b/safari/spotify-lyrics/spotify-lyrics/AppDelegate.swift @@ -0,0 +1,21 @@ +// +// AppDelegate.swift +// spotify-lyrics +// +// Created by Xianqiao Wang on 2020/6/26. +// + +import Cocoa + +@NSApplicationMain +class AppDelegate: NSObject, NSApplicationDelegate { + + func applicationDidFinishLaunching(_ aNotification: Notification) { + // Insert code here to initialize your application + } + + func applicationWillTerminate(_ aNotification: Notification) { + // Insert code here to tear down your application + } + +} diff --git a/safari/spotify-lyrics/spotify-lyrics/Assets.xcassets/AccentColor.colorset/Contents.json b/safari/spotify-lyrics/spotify-lyrics/Assets.xcassets/AccentColor.colorset/Contents.json new file mode 100644 index 0000000..eb87897 --- /dev/null +++ b/safari/spotify-lyrics/spotify-lyrics/Assets.xcassets/AccentColor.colorset/Contents.json @@ -0,0 +1,11 @@ +{ + "colors" : [ + { + "idiom" : "universal" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/safari/spotify-lyrics/spotify-lyrics/Assets.xcassets/AppIcon.appiconset/Contents.json b/safari/spotify-lyrics/spotify-lyrics/Assets.xcassets/AppIcon.appiconset/Contents.json new file mode 100644 index 0000000..d85c95a --- /dev/null +++ b/safari/spotify-lyrics/spotify-lyrics/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -0,0 +1,68 @@ +{ + "images" : [ + { + "filename" : "Icon-16.png", + "idiom" : "mac", + "scale" : "1x", + "size" : "16x16" + }, + { + "filename" : "Icon-32.png", + "idiom" : "mac", + "scale" : "2x", + "size" : "16x16" + }, + { + "filename" : "Icon-33.png", + "idiom" : "mac", + "scale" : "1x", + "size" : "32x32" + }, + { + "filename" : "Icon-64.png", + "idiom" : "mac", + "scale" : "2x", + "size" : "32x32" + }, + { + "filename" : "Icon-128.png", + "idiom" : "mac", + "scale" : "1x", + "size" : "128x128" + }, + { + "filename" : "Icon-256.png", + "idiom" : "mac", + "scale" : "2x", + "size" : "128x128" + }, + { + "filename" : "Icon-257.png", + "idiom" : "mac", + "scale" : "1x", + "size" : "256x256" + }, + { + "filename" : "Icon-512.png", + "idiom" : "mac", + "scale" : "2x", + "size" : "256x256" + }, + { + "filename" : "Icon-513.png", + "idiom" : "mac", + "scale" : "1x", + "size" : "512x512" + }, + { + "filename" : "Icon-1024.png", + "idiom" : "mac", + "scale" : "2x", + "size" : "512x512" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/safari/spotify-lyrics/spotify-lyrics/Assets.xcassets/AppIcon.appiconset/Icon-1024.png b/safari/spotify-lyrics/spotify-lyrics/Assets.xcassets/AppIcon.appiconset/Icon-1024.png new file mode 100644 index 0000000..d9205e1 Binary files /dev/null and b/safari/spotify-lyrics/spotify-lyrics/Assets.xcassets/AppIcon.appiconset/Icon-1024.png differ diff --git a/safari/spotify-lyrics/spotify-lyrics/Assets.xcassets/AppIcon.appiconset/Icon-128.png b/safari/spotify-lyrics/spotify-lyrics/Assets.xcassets/AppIcon.appiconset/Icon-128.png new file mode 100644 index 0000000..467b650 Binary files /dev/null and b/safari/spotify-lyrics/spotify-lyrics/Assets.xcassets/AppIcon.appiconset/Icon-128.png differ diff --git a/safari/spotify-lyrics/spotify-lyrics/Assets.xcassets/AppIcon.appiconset/Icon-16.png b/safari/spotify-lyrics/spotify-lyrics/Assets.xcassets/AppIcon.appiconset/Icon-16.png new file mode 100644 index 0000000..5f601f9 Binary files /dev/null and b/safari/spotify-lyrics/spotify-lyrics/Assets.xcassets/AppIcon.appiconset/Icon-16.png differ diff --git a/safari/spotify-lyrics/spotify-lyrics/Assets.xcassets/AppIcon.appiconset/Icon-256.png b/safari/spotify-lyrics/spotify-lyrics/Assets.xcassets/AppIcon.appiconset/Icon-256.png new file mode 100644 index 0000000..773dc7e Binary files /dev/null and b/safari/spotify-lyrics/spotify-lyrics/Assets.xcassets/AppIcon.appiconset/Icon-256.png differ diff --git a/safari/spotify-lyrics/spotify-lyrics/Assets.xcassets/AppIcon.appiconset/Icon-257.png b/safari/spotify-lyrics/spotify-lyrics/Assets.xcassets/AppIcon.appiconset/Icon-257.png new file mode 100644 index 0000000..773dc7e Binary files /dev/null and b/safari/spotify-lyrics/spotify-lyrics/Assets.xcassets/AppIcon.appiconset/Icon-257.png differ diff --git a/safari/spotify-lyrics/spotify-lyrics/Assets.xcassets/AppIcon.appiconset/Icon-32.png b/safari/spotify-lyrics/spotify-lyrics/Assets.xcassets/AppIcon.appiconset/Icon-32.png new file mode 100644 index 0000000..291c758 Binary files /dev/null and b/safari/spotify-lyrics/spotify-lyrics/Assets.xcassets/AppIcon.appiconset/Icon-32.png differ diff --git a/safari/spotify-lyrics/spotify-lyrics/Assets.xcassets/AppIcon.appiconset/Icon-33.png b/safari/spotify-lyrics/spotify-lyrics/Assets.xcassets/AppIcon.appiconset/Icon-33.png new file mode 100644 index 0000000..291c758 Binary files /dev/null and b/safari/spotify-lyrics/spotify-lyrics/Assets.xcassets/AppIcon.appiconset/Icon-33.png differ diff --git a/safari/spotify-lyrics/spotify-lyrics/Assets.xcassets/AppIcon.appiconset/Icon-512.png b/safari/spotify-lyrics/spotify-lyrics/Assets.xcassets/AppIcon.appiconset/Icon-512.png new file mode 100644 index 0000000..f69718a Binary files /dev/null and b/safari/spotify-lyrics/spotify-lyrics/Assets.xcassets/AppIcon.appiconset/Icon-512.png differ diff --git a/safari/spotify-lyrics/spotify-lyrics/Assets.xcassets/AppIcon.appiconset/Icon-513.png b/safari/spotify-lyrics/spotify-lyrics/Assets.xcassets/AppIcon.appiconset/Icon-513.png new file mode 100644 index 0000000..f69718a Binary files /dev/null and b/safari/spotify-lyrics/spotify-lyrics/Assets.xcassets/AppIcon.appiconset/Icon-513.png differ diff --git a/safari/spotify-lyrics/spotify-lyrics/Assets.xcassets/AppIcon.appiconset/Icon-64.png b/safari/spotify-lyrics/spotify-lyrics/Assets.xcassets/AppIcon.appiconset/Icon-64.png new file mode 100644 index 0000000..3e9a57a Binary files /dev/null and b/safari/spotify-lyrics/spotify-lyrics/Assets.xcassets/AppIcon.appiconset/Icon-64.png differ diff --git a/safari/spotify-lyrics/spotify-lyrics/Assets.xcassets/Contents.json b/safari/spotify-lyrics/spotify-lyrics/Assets.xcassets/Contents.json new file mode 100644 index 0000000..73c0059 --- /dev/null +++ b/safari/spotify-lyrics/spotify-lyrics/Assets.xcassets/Contents.json @@ -0,0 +1,6 @@ +{ + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/safari/spotify-lyrics/spotify-lyrics/Base.lproj/Main.storyboard b/safari/spotify-lyrics/spotify-lyrics/Base.lproj/Main.storyboard new file mode 100644 index 0000000..6e64f92 --- /dev/null +++ b/safari/spotify-lyrics/spotify-lyrics/Base.lproj/Main.storyboard @@ -0,0 +1,168 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/safari/spotify-lyrics/spotify-lyrics/Info.plist b/safari/spotify-lyrics/spotify-lyrics/Info.plist new file mode 100644 index 0000000..cfbbdb7 --- /dev/null +++ b/safari/spotify-lyrics/spotify-lyrics/Info.plist @@ -0,0 +1,30 @@ + + + + + CFBundleDevelopmentRegion + $(DEVELOPMENT_LANGUAGE) + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIconFile + + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + $(PRODUCT_BUNDLE_PACKAGE_TYPE) + CFBundleShortVersionString + 1.0 + CFBundleVersion + 1 + LSMinimumSystemVersion + $(MACOSX_DEPLOYMENT_TARGET) + NSMainStoryboardFile + Main + NSPrincipalClass + NSApplication + + diff --git a/safari/spotify-lyrics/spotify-lyrics/ViewController.swift b/safari/spotify-lyrics/spotify-lyrics/ViewController.swift new file mode 100644 index 0000000..bac03a5 --- /dev/null +++ b/safari/spotify-lyrics/spotify-lyrics/ViewController.swift @@ -0,0 +1,51 @@ +// +// ViewController.swift +// spotify-lyrics +// +// Created by Xianqiao Wang on 2020/6/26. +// + +import Cocoa +import SafariServices.SFSafariApplication +import SafariServices.SFSafariExtensionManager + +let appName = "spotify-lyrics" +let extensionBundleIdentifier = "xianqiao.wang.spotify-lyrics-Extension" + +class ViewController: NSViewController { + + @IBOutlet var appNameLabel: NSTextField! + + override func viewDidLoad() { + super.viewDidLoad() + self.appNameLabel.stringValue = appName + SFSafariExtensionManager.getStateOfSafariExtension(withIdentifier: extensionBundleIdentifier) { (state, error) in + guard let state = state, error == nil else { + // Insert code to inform the user that something went wrong. + return + } + + DispatchQueue.main.async { + if (state.isEnabled) { + self.appNameLabel.stringValue = "\(appName)'s extension is currently on." + } else { + self.appNameLabel.stringValue = "\(appName)'s extension is currently off. You can turn it on in Safari Extensions preferences." + } + } + } + } + + @IBAction func openSafariExtensionPreferences(_ sender: AnyObject?) { + SFSafariApplication.showPreferencesForExtension(withIdentifier: extensionBundleIdentifier) { error in + guard error == nil else { + // Insert code to inform the user that something went wrong. + return + } + + DispatchQueue.main.async { + NSApplication.shared.terminate(nil) + } + } + } + +} diff --git a/safari/spotify-lyrics/spotify-lyrics/spotify_lyrics.entitlements b/safari/spotify-lyrics/spotify-lyrics/spotify_lyrics.entitlements new file mode 100644 index 0000000..f2ef3ae --- /dev/null +++ b/safari/spotify-lyrics/spotify-lyrics/spotify_lyrics.entitlements @@ -0,0 +1,10 @@ + + + + + com.apple.security.app-sandbox + + com.apple.security.files.user-selected.read-only + + + diff --git a/screenshot/safari-screenshot.png b/screenshot/safari-screenshot.png new file mode 100644 index 0000000..3fa4e57 Binary files /dev/null and b/screenshot/safari-screenshot.png differ diff --git a/screenshot/safari.png b/screenshot/safari.png new file mode 100644 index 0000000..f4e89cc Binary files /dev/null and b/screenshot/safari.png differ diff --git a/src/page/element.ts b/src/page/element.ts index 0990433..0cd4235 100644 --- a/src/page/element.ts +++ b/src/page/element.ts @@ -4,6 +4,15 @@ video.muted = true; const createElement: typeof document.createElement = document.createElement.bind(document); let audio: HTMLAudioElement | null = null; + +// safari not support media session, pip contorl video +video.addEventListener('play', () => { + audio?.play(); +}); +video.addEventListener('pause', () => { + audio?.pause(); +}); + document.createElement = function(tagName: K, options: ElementCreationOptions) { const element = createElement(tagName, options); if (tagName === 'video') { diff --git a/src/page/index.ts b/src/page/index.ts index 1f1c403..1a667be 100644 --- a/src/page/index.ts +++ b/src/page/index.ts @@ -28,7 +28,9 @@ let options: Options; if (ctx) { const update = () => { - if (!video || !audio || !(video.srcObject instanceof MediaStream) || !document.pictureInPictureElement) { + // Do not check `document.pictureInPictureElement` + // safari enters pip needs a video that is playing + if (!video || !audio || !(video.srcObject instanceof MediaStream)) { return setTimeout(update, INTERVAL); } if (!weakMap.get(video.srcObject)) { diff --git a/src/popup/elements/root.ts b/src/popup/elements/root.ts index bd8ab78..f09d818 100644 --- a/src/popup/elements/root.ts +++ b/src/popup/elements/root.ts @@ -53,6 +53,7 @@ export class SongList extends GemElement { } .footer { display: flex; + flex-shrink: 0; justify-content: center; align-items: center; padding: 0.75rem 0;