diff --git a/app/internal_packages/activity/package.json b/app/internal_packages/activity/package.json index b6dda0fa1..a9f04a6df 100644 --- a/app/internal_packages/activity/package.json +++ b/app/internal_packages/activity/package.json @@ -11,6 +11,7 @@ }, "isOptional": true, + "isIdentityRequired": true, "title":"Activity Notifications and Dashboard", "icon":"./assets/icon.png", diff --git a/app/internal_packages/link-tracking/package.json b/app/internal_packages/link-tracking/package.json index 1560929a4..37c4608d0 100644 --- a/app/internal_packages/link-tracking/package.json +++ b/app/internal_packages/link-tracking/package.json @@ -12,6 +12,7 @@ "description": "Track when links in an email have been clicked by recipients.", "icon": "./icon.png", "isOptional": true, + "isIdentityRequired": true, "supportedEnvs": ["development", "staging", "production"], "repository": { diff --git a/app/internal_packages/open-tracking/package.json b/app/internal_packages/open-tracking/package.json index cb64e7d83..f41bb694a 100644 --- a/app/internal_packages/open-tracking/package.json +++ b/app/internal_packages/open-tracking/package.json @@ -12,6 +12,7 @@ "description": "Track when email messages have been opened by recipients.", "icon": "./icon.png", "isOptional": true, + "isIdentityRequired": true, "supportedEnvs": ["development", "staging", "production"], "repository": { diff --git a/app/internal_packages/participant-profile/package.json b/app/internal_packages/participant-profile/package.json index 4480103b7..40c4617d1 100644 --- a/app/internal_packages/participant-profile/package.json +++ b/app/internal_packages/participant-profile/package.json @@ -4,7 +4,8 @@ "title": "Participant Profile", "description": "Information about a participant", - "isOptional": false, + "isOptional": true, + "isIdentityRequired": true, "main": "lib/main", "windowTypes": { diff --git a/app/internal_packages/send-reminders/package.json b/app/internal_packages/send-reminders/package.json index f0477af41..7a8e44055 100644 --- a/app/internal_packages/send-reminders/package.json +++ b/app/internal_packages/send-reminders/package.json @@ -3,10 +3,12 @@ "version": "1.0.0", "title": "Send Reminders", "description": "Get reminded if you don't receive a reply for a message within a specified time in the future", - "isHiddenOnPluginsPage": true, "icon": "./icon.png", "main": "lib/main", "supportedEnvs": ["development", "staging", "production"], + + "isOptional": true, + "isIdentityRequired": true, "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, @@ -14,7 +16,6 @@ "default": true, "composer": true }, - "isOptional": true, "engines": { "mailspring": "*" }, diff --git a/app/internal_packages/thread-sharing/package.json b/app/internal_packages/thread-sharing/package.json index bb378105e..774f0d9f8 100644 --- a/app/internal_packages/thread-sharing/package.json +++ b/app/internal_packages/thread-sharing/package.json @@ -7,6 +7,8 @@ "production": "https://share.getmailspring.com" }, + "isOptional": true, + "isIdentityRequired": true, "title": "Thread Sharing", "description": "Share a thread through the web.", "main": "./lib/main", diff --git a/app/internal_packages/thread-snooze/package.json b/app/internal_packages/thread-snooze/package.json index d8d67bb47..9caf4ad7b 100644 --- a/app/internal_packages/thread-snooze/package.json +++ b/app/internal_packages/thread-snooze/package.json @@ -4,6 +4,8 @@ "title": "Thread Snooze", "description": "Snooze mail!", "main": "lib/main", + "isOptional": true, + "isIdentityRequired": true, "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, diff --git a/app/src/package-manager.ts b/app/src/package-manager.ts index 833c97975..4b9ec6153 100644 --- a/app/src/package-manager.ts +++ b/app/src/package-manager.ts @@ -11,10 +11,12 @@ export default class PackageManager { active: { [packageName: string]: Package } = {}; resourcePath: string; configDirPath: string; + identityPresent: boolean; constructor({ configDirPath, devMode, safeMode, resourcePath, specMode }) { this.resourcePath = resourcePath; this.configDirPath = configDirPath; + this.identityPresent = !!AppEnv.config.get('identity'); if (specMode) { this.packageDirectories.push(path.join(resourcePath, 'spec', 'fixtures', 'packages')); @@ -29,6 +31,20 @@ export default class PackageManager { } this.discoverPackages(); + + // If the user starts without a Mailspring ID and then links one, immediately turn on the + // packages that require it. (Note: When you log OUT we currently just reboot the app, so + // this only goes one way, which is also convenient because unloading the built-in packages + // hasn't been tested much.) + + // Note: Ideally we'd use the IdentityStore here but we can't load it this early in app + // launch without introducing a circular import. + AppEnv.config.onDidChange('identity', () => { + if (!this.identityPresent && !!AppEnv.config.get('identity')) { + this.identityPresent = true; + this.activatePackages(AppEnv.getLoadSettings().windowType); + } + }); } discoverPackages() { @@ -58,7 +74,7 @@ export default class PackageManager { } } - activatePackages(windowType) { + activatePackages(windowType: string) { for (const name of Object.keys(this.available)) { const pkg = this.available[name]; @@ -79,7 +95,7 @@ export default class PackageManager { }, 2500); } - activatePackage(pkg) { + activatePackage(pkg: Package) { if (this.active[pkg.name]) { return; } @@ -93,7 +109,11 @@ export default class PackageManager { return; } - if (!pkg.json.engines.mailspring) { + if (pkg.isIdentityRequired() && !this.identityPresent) { + return; + } + + if (!pkg.isEngineSet()) { // don't use AppEnv.reportError, I don't want to know about these. console.error( localized( @@ -119,10 +139,14 @@ export default class PackageManager { return Object.values(this.active); } - getPackageNamed(packageName) { + getPackageNamed(packageName: string) { return this.available[packageName]; } + isPackageActive(packageName: string) { + return packageName in this.active; + } + // Installing and Creating Packages installPackageManually() { @@ -154,7 +178,7 @@ export default class PackageManager { ); } - installPackageFromPath(packagePath, callback) { + installPackageFromPath(packagePath: string, callback) { // check that the path contains a package.json file let json = null; try { diff --git a/app/src/package.ts b/app/src/package.ts index 24109342c..a3dcb1775 100644 --- a/app/src/package.ts +++ b/app/src/package.ts @@ -81,6 +81,14 @@ export default class Package { return !!this.json.isOptional; } + isEngineSet() { + return !!this.json.engines.mailspring; + } + + isIdentityRequired() { + return !!this.json.isIdentityRequired; + } + isDefault() { return !!this.json.isDefault; }