From 17393c02aa6805f404e4aac5c206b0d1a153450a Mon Sep 17 00:00:00 2001 From: Pierre Berger Date: Thu, 19 Aug 2021 14:15:28 +0200 Subject: [PATCH] Fix update system --- LivecamWallpaper.xcodeproj/project.pbxproj | 158 +----------------- LivecamWallpaper/AppDelegate.swift | 48 ++++-- .../LivecamWallpaper.entitlements | 4 +- .../LivecamWallpaperRelease.entitlements | 4 +- LivecamWallpaper/Updater/updater.swift | 55 +++--- LivecamWallpaper/Utils/Utilities.swift | 25 +++ LivecamWallpaper/Views/Update.swift | 4 +- LivecamWallpaper/helpers.swift | 26 +++ LivecamWallpaperUpdaterService/Info.plist | 29 ---- ...ivecamWallpaperUpdaterService.entitlements | 5 - .../LivecamWallpaperUpdaterService.swift | 30 ---- ...vecamWallpaperUpdaterServiceDelegate.swift | 11 -- ...vecamWallpaperUpdaterServiceProtocol.swift | 5 - LivecamWallpaperUpdaterService/Utils.swift | 26 --- LivecamWallpaperUpdaterService/main.swift | 6 - 15 files changed, 119 insertions(+), 317 deletions(-) create mode 100644 LivecamWallpaper/helpers.swift delete mode 100644 LivecamWallpaperUpdaterService/Info.plist delete mode 100644 LivecamWallpaperUpdaterService/LivecamWallpaperUpdaterService.entitlements delete mode 100644 LivecamWallpaperUpdaterService/LivecamWallpaperUpdaterService.swift delete mode 100644 LivecamWallpaperUpdaterService/LivecamWallpaperUpdaterServiceDelegate.swift delete mode 100644 LivecamWallpaperUpdaterService/LivecamWallpaperUpdaterServiceProtocol.swift delete mode 100644 LivecamWallpaperUpdaterService/Utils.swift delete mode 100644 LivecamWallpaperUpdaterService/main.swift diff --git a/LivecamWallpaper.xcodeproj/project.pbxproj b/LivecamWallpaper.xcodeproj/project.pbxproj index b3e25e5..d4e503d 100644 --- a/LivecamWallpaper.xcodeproj/project.pbxproj +++ b/LivecamWallpaper.xcodeproj/project.pbxproj @@ -7,6 +7,7 @@ objects = { /* Begin PBXBuildFile section */ + 8F2C968E26CE7CD200855B12 /* helpers.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8F2C968D26CE7CD200855B12 /* helpers.swift */; }; 8F39DD882627A77800F0C010 /* Defaults in Frameworks */ = {isa = PBXBuildFile; productRef = 8F39DD872627A77800F0C010 /* Defaults */; }; 8F39DDAC2628EE2B00F0C010 /* SkapingController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8F39DDAB2628EE2B00F0C010 /* SkapingController.swift */; }; 8F39DDB92628F90100F0C010 /* Utilities.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8F39DDB82628F90100F0C010 /* Utilities.swift */; }; @@ -14,12 +15,6 @@ 8F5390B3263F47CB00EA6B2E /* updater.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8F5390B2263F47CB00EA6B2E /* updater.swift */; }; 8F5390B52641EB8D00EA6B2E /* Update.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8F5390B42641EB8D00EA6B2E /* Update.swift */; }; 8F5CEDA3263B5296009481E4 /* Bugsnag in Frameworks */ = {isa = PBXBuildFile; productRef = 8F5CEDA2263B5296009481E4 /* Bugsnag */; }; - 8F70246926CA7AD100B63440 /* LivecamWallpaperUpdaterService.xpc in Embed XPC Services */ = {isa = PBXBuildFile; fileRef = 8F70245D26CA7AD100B63440 /* LivecamWallpaperUpdaterService.xpc */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; }; - 8F70246D26CA7AE600B63440 /* LivecamWallpaperUpdaterService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8F70245326CA76BA00B63440 /* LivecamWallpaperUpdaterService.swift */; }; - 8F70246E26CA7AE600B63440 /* LivecamWallpaperUpdaterServiceDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8F70245526CA76D800B63440 /* LivecamWallpaperUpdaterServiceDelegate.swift */; }; - 8F70246F26CA7AE600B63440 /* LivecamWallpaperUpdaterServiceProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8F70245726CA76EA00B63440 /* LivecamWallpaperUpdaterServiceProtocol.swift */; }; - 8F70247026CA7AE600B63440 /* main.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8F70245126CA768F00B63440 /* main.swift */; }; - 8F70247226CA7DC700B63440 /* Utils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8F70247126CA7DC700B63440 /* Utils.swift */; }; 8F9AFE04261FA93C0086DCCA /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8F9AFE03261FA93C0086DCCA /* AppDelegate.swift */; }; 8F9AFE09261FA93C0086DCCA /* LivecamWallpaper.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = 8F9AFE07261FA93C0086DCCA /* LivecamWallpaper.xcdatamodeld */; }; 8F9AFE0B261FA93F0086DCCA /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 8F9AFE0A261FA93F0086DCCA /* Assets.xcassets */; }; @@ -30,16 +25,6 @@ 8F9AFE9F26279B200086DCCA /* Defaults.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8F9AFE9E26279B200086DCCA /* Defaults.swift */; }; /* End PBXBuildFile section */ -/* Begin PBXContainerItemProxy section */ - 8F70246626CA7AD100B63440 /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = 8F9AFDF8261FA93B0086DCCA /* Project object */; - proxyType = 1; - remoteGlobalIDString = 8F70245C26CA7AD100B63440; - remoteInfo = LivecamWallpaperUpdaterService; - }; -/* End PBXContainerItemProxy section */ - /* Begin PBXCopyFilesBuildPhase section */ 8F70246826CA7AD100B63440 /* Embed XPC Services */ = { isa = PBXCopyFilesBuildPhase; @@ -47,7 +32,6 @@ dstPath = "$(CONTENTS_FOLDER_PATH)/XPCServices"; dstSubfolderSpec = 16; files = ( - 8F70246926CA7AD100B63440 /* LivecamWallpaperUpdaterService.xpc in Embed XPC Services */, ); name = "Embed XPC Services"; runOnlyForDeploymentPostprocessing = 0; @@ -65,19 +49,12 @@ /* End PBXCopyFilesBuildPhase section */ /* Begin PBXFileReference section */ - 8F2C968C26CD2AF600855B12 /* LivecamWallpaperUpdaterService.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = LivecamWallpaperUpdaterService.entitlements; sourceTree = ""; }; + 8F2C968D26CE7CD200855B12 /* helpers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = helpers.swift; sourceTree = ""; }; 8F39DDAB2628EE2B00F0C010 /* SkapingController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SkapingController.swift; sourceTree = ""; }; 8F39DDB82628F90100F0C010 /* Utilities.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Utilities.swift; sourceTree = ""; }; 8F5390B2263F47CB00EA6B2E /* updater.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = updater.swift; sourceTree = ""; }; 8F5390B42641EB8D00EA6B2E /* Update.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Update.swift; sourceTree = ""; }; 8F648C5526C7DF310027BA10 /* updater.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = updater.sh; sourceTree = ""; }; - 8F70245126CA768F00B63440 /* main.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = main.swift; sourceTree = ""; }; - 8F70245326CA76BA00B63440 /* LivecamWallpaperUpdaterService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LivecamWallpaperUpdaterService.swift; sourceTree = ""; }; - 8F70245526CA76D800B63440 /* LivecamWallpaperUpdaterServiceDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LivecamWallpaperUpdaterServiceDelegate.swift; sourceTree = ""; }; - 8F70245726CA76EA00B63440 /* LivecamWallpaperUpdaterServiceProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LivecamWallpaperUpdaterServiceProtocol.swift; sourceTree = ""; }; - 8F70245D26CA7AD100B63440 /* LivecamWallpaperUpdaterService.xpc */ = {isa = PBXFileReference; explicitFileType = "wrapper.xpc-service"; includeInIndex = 0; path = LivecamWallpaperUpdaterService.xpc; sourceTree = BUILT_PRODUCTS_DIR; }; - 8F70246526CA7AD100B63440 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; - 8F70247126CA7DC700B63440 /* Utils.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Utils.swift; sourceTree = ""; }; 8F9AFE00261FA93C0086DCCA /* LivecamWallpaper.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = LivecamWallpaper.app; sourceTree = BUILT_PRODUCTS_DIR; }; 8F9AFE03261FA93C0086DCCA /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 8F9AFE08261FA93C0086DCCA /* LivecamWallpaper.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = LivecamWallpaper.xcdatamodel; sourceTree = ""; }; @@ -93,13 +70,6 @@ /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ - 8F70245A26CA7AD100B63440 /* Frameworks */ = { - isa = PBXFrameworksBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - runOnlyForDeploymentPostprocessing = 0; - }; 8F9AFDFD261FA93C0086DCCA /* Frameworks */ = { isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; @@ -137,25 +107,10 @@ path = Utils; sourceTree = ""; }; - 8F70245E26CA7AD100B63440 /* LivecamWallpaperUpdaterService */ = { - isa = PBXGroup; - children = ( - 8F2C968C26CD2AF600855B12 /* LivecamWallpaperUpdaterService.entitlements */, - 8F70245126CA768F00B63440 /* main.swift */, - 8F70245326CA76BA00B63440 /* LivecamWallpaperUpdaterService.swift */, - 8F70245526CA76D800B63440 /* LivecamWallpaperUpdaterServiceDelegate.swift */, - 8F70245726CA76EA00B63440 /* LivecamWallpaperUpdaterServiceProtocol.swift */, - 8F70246526CA7AD100B63440 /* Info.plist */, - 8F70247126CA7DC700B63440 /* Utils.swift */, - ); - path = LivecamWallpaperUpdaterService; - sourceTree = ""; - }; 8F9AFDF7261FA93B0086DCCA = { isa = PBXGroup; children = ( 8F9AFE02261FA93C0086DCCA /* LivecamWallpaper */, - 8F70245E26CA7AD100B63440 /* LivecamWallpaperUpdaterService */, 8F9AFE01261FA93C0086DCCA /* Products */, ); sourceTree = ""; @@ -164,7 +119,6 @@ isa = PBXGroup; children = ( 8F9AFE00261FA93C0086DCCA /* LivecamWallpaper.app */, - 8F70245D26CA7AD100B63440 /* LivecamWallpaperUpdaterService.xpc */, ); name = Products; sourceTree = ""; @@ -186,6 +140,7 @@ 8F9AFE07261FA93C0086DCCA /* LivecamWallpaper.xcdatamodeld */, 8F9AFE0C261FA93F0086DCCA /* Preview Content */, 8F9AFE9E26279B200086DCCA /* Defaults.swift */, + 8F2C968D26CE7CD200855B12 /* helpers.swift */, ); path = LivecamWallpaper; sourceTree = ""; @@ -218,23 +173,6 @@ /* End PBXGroup section */ /* Begin PBXNativeTarget section */ - 8F70245C26CA7AD100B63440 /* LivecamWallpaperUpdaterService */ = { - isa = PBXNativeTarget; - buildConfigurationList = 8F70246A26CA7AD100B63440 /* Build configuration list for PBXNativeTarget "LivecamWallpaperUpdaterService" */; - buildPhases = ( - 8F70245926CA7AD100B63440 /* Sources */, - 8F70245A26CA7AD100B63440 /* Frameworks */, - 8F70245B26CA7AD100B63440 /* Resources */, - ); - buildRules = ( - ); - dependencies = ( - ); - name = LivecamWallpaperUpdaterService; - productName = LivecamWallpaperUpdaterService; - productReference = 8F70245D26CA7AD100B63440 /* LivecamWallpaperUpdaterService.xpc */; - productType = "com.apple.product-type.xpc-service"; - }; 8F9AFDFF261FA93C0086DCCA /* LivecamWallpaper */ = { isa = PBXNativeTarget; buildConfigurationList = 8F9AFE2C261FA9400086DCCA /* Build configuration list for PBXNativeTarget "LivecamWallpaper" */; @@ -249,7 +187,6 @@ buildRules = ( ); dependencies = ( - 8F70246726CA7AD100B63440 /* PBXTargetDependency */, ); name = LivecamWallpaper; packageProductDependencies = ( @@ -269,9 +206,6 @@ LastSwiftUpdateCheck = 1240; LastUpgradeCheck = 1240; TargetAttributes = { - 8F70245C26CA7AD100B63440 = { - CreatedOnToolsVersion = 12.5; - }; 8F9AFDFF261FA93C0086DCCA = { CreatedOnToolsVersion = 12.4; }; @@ -295,19 +229,11 @@ projectRoot = ""; targets = ( 8F9AFDFF261FA93C0086DCCA /* LivecamWallpaper */, - 8F70245C26CA7AD100B63440 /* LivecamWallpaperUpdaterService */, ); }; /* End PBXProject section */ /* Begin PBXResourcesBuildPhase section */ - 8F70245B26CA7AD100B63440 /* Resources */ = { - isa = PBXResourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - runOnlyForDeploymentPostprocessing = 0; - }; 8F9AFDFE261FA93C0086DCCA /* Resources */ = { isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; @@ -341,18 +267,6 @@ /* End PBXShellScriptBuildPhase section */ /* Begin PBXSourcesBuildPhase section */ - 8F70245926CA7AD100B63440 /* Sources */ = { - isa = PBXSourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - 8F70247226CA7DC700B63440 /* Utils.swift in Sources */, - 8F70246E26CA7AE600B63440 /* LivecamWallpaperUpdaterServiceDelegate.swift in Sources */, - 8F70247026CA7AE600B63440 /* main.swift in Sources */, - 8F70246F26CA7AE600B63440 /* LivecamWallpaperUpdaterServiceProtocol.swift in Sources */, - 8F70246D26CA7AE600B63440 /* LivecamWallpaperUpdaterService.swift in Sources */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; 8F9AFDFC261FA93C0086DCCA /* Sources */ = { isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; @@ -366,19 +280,12 @@ 8F5390B3263F47CB00EA6B2E /* updater.swift in Sources */, 8F39DDB92628F90100F0C010 /* Utilities.swift in Sources */, 8F9AFE04261FA93C0086DCCA /* AppDelegate.swift in Sources */, + 8F2C968E26CE7CD200855B12 /* helpers.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; /* End PBXSourcesBuildPhase section */ -/* Begin PBXTargetDependency section */ - 8F70246726CA7AD100B63440 /* PBXTargetDependency */ = { - isa = PBXTargetDependency; - target = 8F70245C26CA7AD100B63440 /* LivecamWallpaperUpdaterService */; - targetProxy = 8F70246626CA7AD100B63440 /* PBXContainerItemProxy */; - }; -/* End PBXTargetDependency section */ - /* Begin PBXVariantGroup section */ 8F9AFE0F261FA93F0086DCCA /* Main.storyboard */ = { isa = PBXVariantGroup; @@ -391,48 +298,6 @@ /* End PBXVariantGroup section */ /* Begin XCBuildConfiguration section */ - 8F70246B26CA7AD100B63440 /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - CODE_SIGN_ENTITLEMENTS = LivecamWallpaperUpdaterService/LivecamWallpaperUpdaterService.entitlements; - CODE_SIGN_IDENTITY = "-"; - CODE_SIGN_STYLE = Automatic; - COMBINE_HIDPI_IMAGES = YES; - DEVELOPMENT_TEAM = ""; - ENABLE_HARDENED_RUNTIME = YES; - INFOPLIST_FILE = LivecamWallpaperUpdaterService/Info.plist; - LD_RUNPATH_SEARCH_PATHS = "@loader_path/../../../../Frameworks"; - MACOSX_DEPLOYMENT_TARGET = 10.15; - PRODUCT_BUNDLE_IDENTIFIER = fr.pierreberger.LivecamWallpaperUpdaterService; - PRODUCT_NAME = "$(TARGET_NAME)"; - SKIP_INSTALL = YES; - SWIFT_INSTALL_OBJC_HEADER = NO; - SWIFT_OBJC_INTERFACE_HEADER_NAME = ""; - SWIFT_VERSION = 5.0; - }; - name = Debug; - }; - 8F70246C26CA7AD100B63440 /* Release */ = { - isa = XCBuildConfiguration; - buildSettings = { - CODE_SIGN_ENTITLEMENTS = LivecamWallpaperUpdaterService/LivecamWallpaperUpdaterService.entitlements; - CODE_SIGN_IDENTITY = "-"; - CODE_SIGN_STYLE = Automatic; - COMBINE_HIDPI_IMAGES = YES; - DEVELOPMENT_TEAM = ""; - ENABLE_HARDENED_RUNTIME = YES; - INFOPLIST_FILE = LivecamWallpaperUpdaterService/Info.plist; - LD_RUNPATH_SEARCH_PATHS = "@loader_path/../../../../Frameworks"; - MACOSX_DEPLOYMENT_TARGET = 10.15; - PRODUCT_BUNDLE_IDENTIFIER = fr.pierreberger.LivecamWallpaperUpdaterService; - PRODUCT_NAME = "$(TARGET_NAME)"; - SKIP_INSTALL = YES; - SWIFT_INSTALL_OBJC_HEADER = NO; - SWIFT_OBJC_INTERFACE_HEADER_NAME = ""; - SWIFT_VERSION = 5.0; - }; - name = Release; - }; 8F9AFE2A261FA9400086DCCA /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { @@ -551,7 +416,6 @@ 8F9AFE2D261FA9400086DCCA /* 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 = LivecamWallpaper/LivecamWallpaper.entitlements; @@ -569,7 +433,7 @@ "@executable_path/../Frameworks", ); MACOSX_DEPLOYMENT_TARGET = 10.15; - MARKETING_VERSION = 0.1.1; + MARKETING_VERSION = 0.2.0; PRODUCT_BUNDLE_IDENTIFIER = fr.pierreberger.LivecamWallpaper; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE_SPECIFIER = ""; @@ -581,7 +445,6 @@ 8F9AFE2E261FA9400086DCCA /* 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 = LivecamWallpaper/LivecamWallpaperRelease.entitlements; @@ -599,7 +462,7 @@ "@executable_path/../Frameworks", ); MACOSX_DEPLOYMENT_TARGET = 10.15; - MARKETING_VERSION = 0.1.1; + MARKETING_VERSION = 0.2.0; PRODUCT_BUNDLE_IDENTIFIER = fr.pierreberger.LivecamWallpaper; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE_SPECIFIER = ""; @@ -611,15 +474,6 @@ /* End XCBuildConfiguration section */ /* Begin XCConfigurationList section */ - 8F70246A26CA7AD100B63440 /* Build configuration list for PBXNativeTarget "LivecamWallpaperUpdaterService" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - 8F70246B26CA7AD100B63440 /* Debug */, - 8F70246C26CA7AD100B63440 /* Release */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = Release; - }; 8F9AFDFB261FA93B0086DCCA /* Build configuration list for PBXProject "LivecamWallpaper" */ = { isa = XCConfigurationList; buildConfigurations = ( diff --git a/LivecamWallpaper/AppDelegate.swift b/LivecamWallpaper/AppDelegate.swift index 1b3a9b4..5b1f2df 100644 --- a/LivecamWallpaper/AppDelegate.swift +++ b/LivecamWallpaper/AppDelegate.swift @@ -17,10 +17,13 @@ class AppDelegate: NSObject, NSApplicationDelegate { func applicationDidFinishLaunching(_: Notification) { Bugsnag.start() + parseArguments() + setup() if MyApp.isFirstLaunch { openPreferences() + } else { + resetInterval() } - setup() } func changeWallpaper(savedUrl: URL) { @@ -36,25 +39,30 @@ class AppDelegate: NSObject, NSApplicationDelegate { } } + func createDirectories() -> URL? { + let wallpaperFolder = FileManager.default.homeDirectoryForCurrentUser + .appendingPathComponent(".livecamWallpaper") + .appendingPathComponent("wallpapers") + + if !FileManager.default.fileExists(atPath: wallpaperFolder.path) { + do { + try FileManager.default.createDirectory(atPath: wallpaperFolder.path, withIntermediateDirectories: true, attributes: nil) + + return wallpaperFolder + } catch { + print(error.localizedDescription) + return nil + } + } + return wallpaperFolder + } + func downloadImage(url: URL) { URLSession.shared.downloadTask(with: url) { urlOrNil, _, _ in guard let fileURL = urlOrNil else { return } - do { + guard let dataPath = self.createDirectories() else { return } - let documentsURL = try - FileManager.default.url(for: .documentDirectory, - in: .userDomainMask, - appropriateFor: nil, - create: false) - - let dataPath = documentsURL.appendingPathComponent("wallpaper") - if !FileManager.default.fileExists(atPath: dataPath.path) { - do { - try FileManager.default.createDirectory(atPath: dataPath.path, withIntermediateDirectories: true, attributes: nil) - } catch { - print(error.localizedDescription) - } - } + do { let savedURL = dataPath.appendingPathComponent(String(NSDate().timeIntervalSince1970)) try FileManager.default.moveItem(at: fileURL, to: savedURL) @@ -88,8 +96,10 @@ class AppDelegate: NSObject, NSApplicationDelegate { func clearFolder() { let fileManager = FileManager.default - let documentsUrl = fileManager.urls(for: .documentDirectory, in: .userDomainMask).first! - let wallpaperDir = documentsUrl.appendingPathComponent("wallpaper") + let wallpaperDir = FileManager.default.homeDirectoryForCurrentUser + .appendingPathComponent(".livecamWallpaper") + .appendingPathComponent("wallpapers") + guard var filePaths = try? fileManager.contentsOfDirectory(at: wallpaperDir, includingPropertiesForKeys: nil, options: []) else { return } @@ -193,6 +203,8 @@ class AppDelegate: NSObject, NSApplicationDelegate { } func setup() { + _ = createDirectories() + menu = NSMenu() setupMenu() statusBarItem = NSStatusBar.system.statusItem(withLength: CGFloat(NSStatusItem.variableLength)) diff --git a/LivecamWallpaper/LivecamWallpaper.entitlements b/LivecamWallpaper/LivecamWallpaper.entitlements index 625af03..08ba3a3 100644 --- a/LivecamWallpaper/LivecamWallpaper.entitlements +++ b/LivecamWallpaper/LivecamWallpaper.entitlements @@ -3,9 +3,7 @@ com.apple.security.app-sandbox - - com.apple.security.files.user-selected.read-only - + com.apple.security.network.client diff --git a/LivecamWallpaper/LivecamWallpaperRelease.entitlements b/LivecamWallpaper/LivecamWallpaperRelease.entitlements index a046386..08ba3a3 100644 --- a/LivecamWallpaper/LivecamWallpaperRelease.entitlements +++ b/LivecamWallpaper/LivecamWallpaperRelease.entitlements @@ -3,9 +3,7 @@ com.apple.security.app-sandbox - - com.apple.security.files.user-selected.read-write - + com.apple.security.network.client diff --git a/LivecamWallpaper/Updater/updater.swift b/LivecamWallpaper/Updater/updater.swift index 78702cd..1dc1910 100644 --- a/LivecamWallpaper/Updater/updater.swift +++ b/LivecamWallpaper/Updater/updater.swift @@ -1,6 +1,5 @@ import Cocoa import SystemConfiguration -import LivecamWallpaperUpdaterService // see https://github.com/exelban/stats/blob/4351d25a222d00bfe8d74b5a169998c9aa6d4dfc/Kit/plugins/Updater.swift @@ -82,21 +81,11 @@ public class Updater { NSLog(fileURL.debugDescription) do { let downloadsURL = try - FileManager.default.url(for: .documentDirectory, + FileManager.default.url(for: .downloadsDirectory, in: .userDomainMask, appropriateFor: nil, create: false) - let updateFolder = downloadsURL.appendingPathComponent("updates") - - if !FileManager.default.fileExists(atPath: updateFolder.path) { - do { - try FileManager.default.createDirectory(atPath: updateFolder.path, withIntermediateDirectories: true, attributes: nil) - } catch { - print(error.localizedDescription) - } - } - - let destinationURL = updateFolder.appendingPathComponent(url.lastPathComponent) + let destinationURL = downloadsURL.appendingPathComponent(url.lastPathComponent) self.copyFile(from: fileURL, to: destinationURL) { (path, error) in if error != nil { @@ -150,22 +139,32 @@ public class Updater { .replacingOccurrences(of: "LivecamWallpaper.app", with: "") .replacingOccurrences(of: "//", with: "/") - let connection = NSXPCConnection(serviceName: "fr.pierreberger.LivecamWallpaperUpdaterService") - connection.remoteObjectInterface = NSXPCInterface(with: LivecamWallpaperUpdaterServiceProtocol.self) - connection.resume() - - let service = connection.remoteObjectProxyWithErrorHandler { error in - print("Received error:", error) - } as? LivecamWallpaperUpdaterServiceProtocol - - service?.installNewVersion( - path, - tmpDir: NSTemporaryDirectory(), - pwd: pwd - ) { response in - print("Response from XPC service:", response) - guard response != "OK" else { exit(0) } + NSLog("Started new version installation...") + + _ = syncShell("mkdir /tmp/LivecamWallpaper") // make sure that directory exist + let res = syncShell("/usr/bin/hdiutil attach \(path) -mountpoint /tmp/LivecamWallpaper -noverify -nobrowse -noautoopen") // mount the dmg + + NSLog("DMG is mounted") + + let tmpDir = NSTemporaryDirectory() + + if res.contains("is busy") { // dmg can be busy, if yes, unmount it and mount again + print("DMG is busy, remounting") + + _ = syncShell("/usr/bin/hdiutil detach \(tmpDir)/LivecamWallpaper") + _ = syncShell("/usr/bin/hdiutil attach \(path) -mountpoint /tmp/LivecamWallpaper -noverify -nobrowse -noautoopen") } + _ = syncShell("cp -rf /tmp/LivecamWallpaper/LivecamWallpaper.app/Contents/Resources/Scripts/updater.sh \(tmpDir)/updater.sh") + + NSLog("Script is copied to $TMPDIR/updater.sh") + + let dmg = path.replacingOccurrences(of: "file://", with: "") + + asyncShell("sh \(tmpDir)/updater.sh --app \(pwd) --dmg \(dmg) >/dev/null &") // run updater script in in background + + NSLog("Run updater.sh with app: \(pwd) and dmg: \(dmg)") + + exit(0) } } diff --git a/LivecamWallpaper/Utils/Utilities.swift b/LivecamWallpaper/Utils/Utilities.swift index 285f652..ef682c3 100644 --- a/LivecamWallpaper/Utils/Utilities.swift +++ b/LivecamWallpaper/Utils/Utilities.swift @@ -72,3 +72,28 @@ enum MyApp { extension AppDelegate { static let shared = NSApp.delegate as! AppDelegate } + +public func asyncShell(_ args: String) { + let task = Process() + let pipe = Pipe() + task.launchPath = "/bin/sh" + task.arguments = ["-c", args] + task.standardOutput = pipe + task.launch() +} + +public func syncShell(_ args: String) -> String { + let task = Process() + let pipe = Pipe() + task.standardOutput = pipe +// task.standardError = pipe + task.arguments = ["-c", args] + task.launchPath = "/bin/sh" + task.launch() + task.waitUntilExit() + + let data = pipe.fileHandleForReading.readDataToEndOfFile() + + let output = String(data: data, encoding: .utf8)! + return output +} diff --git a/LivecamWallpaper/Views/Update.swift b/LivecamWallpaper/Views/Update.swift index 265ca08..4d9660c 100644 --- a/LivecamWallpaper/Views/Update.swift +++ b/LivecamWallpaper/Views/Update.swift @@ -1,6 +1,8 @@ import SwiftUI import Cocoa +// see https://github.com/exelban/stats/blob/bf5b4c406e86e8ddf301e7b2c25d557c6e97c842/Stats/Views/Update.swift + class UpdateWindow: NSWindow, NSWindowDelegate { private let viewController: UpdateViewController = UpdateViewController() init() { @@ -106,7 +108,7 @@ private class UpdateView: NSView { let latestVersion: NSTextView = NSTextView(frame: NSRect( x: (view.frame.width-currentVersionWidth)/2, y: currentVersion.frame.origin.y - 22, - width: latestVersionWidth, + width: latestVersionWidth + 5, height: 16 )) latestVersion.string = latestVersionString diff --git a/LivecamWallpaper/helpers.swift b/LivecamWallpaper/helpers.swift new file mode 100644 index 0000000..1aeabf1 --- /dev/null +++ b/LivecamWallpaper/helpers.swift @@ -0,0 +1,26 @@ +import Foundation +import os.log + +extension AppDelegate { + internal func parseArguments() { + let args = CommandLine.arguments + + if let mountIndex = args.firstIndex(of: "--mount-path") { + if args.indices.contains(mountIndex+1) { + let mountPath = args[mountIndex+1] + asyncShell("/usr/bin/hdiutil detach \(mountPath)") + asyncShell("/bin/rm -rf \(mountPath)") + + os_log(.debug, log: log, "DMG was unmounted and mountPath deleted") + } + } + + if let dmgIndex = args.firstIndex(of: "--dmg-path") { + if args.indices.contains(dmgIndex+1) { + asyncShell("/bin/rm -rf \(args[dmgIndex+1])") + + os_log(.debug, log: log, "DMG was deleted") + } + } + } +} diff --git a/LivecamWallpaperUpdaterService/Info.plist b/LivecamWallpaperUpdaterService/Info.plist deleted file mode 100644 index a06e9df..0000000 --- a/LivecamWallpaperUpdaterService/Info.plist +++ /dev/null @@ -1,29 +0,0 @@ - - - - - CFBundleDevelopmentRegion - $(DEVELOPMENT_LANGUAGE) - CFBundleDisplayName - LivecamWallpaperUpdaterService - CFBundleExecutable - $(EXECUTABLE_NAME) - CFBundleIdentifier - $(PRODUCT_BUNDLE_IDENTIFIER) - CFBundleInfoDictionaryVersion - 6.0 - CFBundleName - $(PRODUCT_NAME) - CFBundlePackageType - $(PRODUCT_BUNDLE_PACKAGE_TYPE) - CFBundleShortVersionString - 1.0 - CFBundleVersion - 1 - XPCService - - ServiceType - Application - - - diff --git a/LivecamWallpaperUpdaterService/LivecamWallpaperUpdaterService.entitlements b/LivecamWallpaperUpdaterService/LivecamWallpaperUpdaterService.entitlements deleted file mode 100644 index 0c67376..0000000 --- a/LivecamWallpaperUpdaterService/LivecamWallpaperUpdaterService.entitlements +++ /dev/null @@ -1,5 +0,0 @@ - - - - - diff --git a/LivecamWallpaperUpdaterService/LivecamWallpaperUpdaterService.swift b/LivecamWallpaperUpdaterService/LivecamWallpaperUpdaterService.swift deleted file mode 100644 index 55a1ae9..0000000 --- a/LivecamWallpaperUpdaterService/LivecamWallpaperUpdaterService.swift +++ /dev/null @@ -1,30 +0,0 @@ -import Foundation - -class LivecamWallpaperUpdaterService: NSObject, LivecamWallpaperUpdaterServiceProtocol { - func installNewVersion(_ path: String, tmpDir: String, pwd: String, withReply reply: @escaping (String) -> Void) { - NSLog("Started new version installation...") - - _ = syncShell("mkdir /tmp/LivecamWallpaper") // make sure that directory exist - let res = syncShell("/usr/bin/hdiutil attach \(path) -mountpoint /tmp/LivecamWallpaper -noverify -nobrowse -noautoopen") // mount the dmg - - NSLog("DMG is mounted") - - if res.contains("is busy") { // dmg can be busy, if yes, unmount it and mount again - print("DMG is busy, remounting") - - _ = syncShell("/usr/bin/hdiutil detach \(tmpDir)/LivecamWallpaper") - _ = syncShell("/usr/bin/hdiutil attach \(path) -mountpoint /tmp/LivecamWallpaper -noverify -nobrowse -noautoopen") - } - - _ = syncShell("cp -rf /tmp/LivecamWallpaper/LivecamWallpaper.app/Contents/Resources/Scripts/updater.sh \(tmpDir)/updater.sh") - - NSLog("Script is copied to $TMPDIR/updater.sh") - - let dmg = path.replacingOccurrences(of: "file://", with: "") - - asyncShell("sh \(tmpDir)/updater.sh --app \(pwd) --dmg \(dmg) >>$TMPDIR/log &") // run updater script in in background - - NSLog("Run updater.sh with app: \(pwd) and dmg: \(dmg)") - reply("OK") - } -} diff --git a/LivecamWallpaperUpdaterService/LivecamWallpaperUpdaterServiceDelegate.swift b/LivecamWallpaperUpdaterService/LivecamWallpaperUpdaterServiceDelegate.swift deleted file mode 100644 index ba9e7a6..0000000 --- a/LivecamWallpaperUpdaterService/LivecamWallpaperUpdaterServiceDelegate.swift +++ /dev/null @@ -1,11 +0,0 @@ -import Foundation - -class LivecamWallpaperUpdaterServiceDelegate: NSObject, NSXPCListenerDelegate { - func listener(_ listener: NSXPCListener, shouldAcceptNewConnection newConnection: NSXPCConnection) -> Bool { - let exportedObject = LivecamWallpaperUpdaterService() - newConnection.exportedInterface = NSXPCInterface(with: LivecamWallpaperUpdaterServiceProtocol.self) - newConnection.exportedObject = exportedObject - newConnection.resume() - return true - } -} diff --git a/LivecamWallpaperUpdaterService/LivecamWallpaperUpdaterServiceProtocol.swift b/LivecamWallpaperUpdaterService/LivecamWallpaperUpdaterServiceProtocol.swift deleted file mode 100644 index 21af5f0..0000000 --- a/LivecamWallpaperUpdaterService/LivecamWallpaperUpdaterServiceProtocol.swift +++ /dev/null @@ -1,5 +0,0 @@ -import Foundation - -@objc public protocol LivecamWallpaperUpdaterServiceProtocol { - func installNewVersion(_ path: String, tmpDir: String, pwd: String, withReply reply: @escaping (String) -> Void) -} diff --git a/LivecamWallpaperUpdaterService/Utils.swift b/LivecamWallpaperUpdaterService/Utils.swift deleted file mode 100644 index 9496986..0000000 --- a/LivecamWallpaperUpdaterService/Utils.swift +++ /dev/null @@ -1,26 +0,0 @@ -import Foundation - -public func asyncShell(_ args: String) { - let task = Process() - let pipe = Pipe() - task.launchPath = "/bin/sh" - task.arguments = ["-c", args] - task.standardOutput = pipe - task.launch() -} - -public func syncShell(_ args: String) -> String { - let task = Process() - let pipe = Pipe() - task.standardOutput = pipe -// task.standardError = pipe - task.arguments = ["-c", args] - task.launchPath = "/bin/sh" - task.launch() - task.waitUntilExit() - - let data = pipe.fileHandleForReading.readDataToEndOfFile() - - let output = String(data: data, encoding: .utf8)! - return output -} diff --git a/LivecamWallpaperUpdaterService/main.swift b/LivecamWallpaperUpdaterService/main.swift deleted file mode 100644 index e6310e6..0000000 --- a/LivecamWallpaperUpdaterService/main.swift +++ /dev/null @@ -1,6 +0,0 @@ -import Foundation - -let delegate = LivecamWallpaperUpdaterServiceDelegate() -let listener = NSXPCListener.service() -listener.delegate = delegate -listener.resume()