Skip to content

Commit

Permalink
Changes after review
Browse files Browse the repository at this point in the history
  • Loading branch information
mup committed Dec 9, 2024
1 parent 277d6fe commit b7b13df
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ import android.Manifest
import android.content.ActivityNotFoundException
import android.content.ClipData
import android.content.Intent
import android.content.Intent.EXTRA_REFERRER
import android.net.Uri
import android.provider.Settings
import android.util.Log
import androidx.biometric.BiometricManager
import androidx.biometric.BiometricPrompt
import androidx.core.app.ActivityCompat.startActivityForResult
import androidx.core.content.ContextCompat.startActivity
import androidx.core.content.FileProvider
import androidx.fragment.app.FragmentActivity
Expand Down Expand Up @@ -173,9 +175,10 @@ class AndroidMobileSystemFacade(

private fun tryToLaunchStore() {
try {
val packageId = activity.getString(R.string.package_name).replace("tutanota", "calendar")
startActivity(
activity,
Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=de.tutao.calendar")),
Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=$packageId")),
null
)
} catch (e: Exception) {
Expand All @@ -188,10 +191,11 @@ class AndroidMobileSystemFacade(

val intent = Intent()
intent.setAction(Intent.ACTION_EDIT)
intent.putExtra(EXTRA_REFERRER, BuildConfig.APPLICATION_ID)
intent.setData(Uri.parse("tutacalendar://interop?${decodedQuery}"))

try {
startActivity(activity, intent, null)
startActivityForResult(activity, intent, 0, null)
} catch (e: Exception) {
Log.d(TAG, e.toString())
tryToLaunchStore()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import android.content.ClipData
import android.content.ClipboardManager
import android.content.ComponentName
import android.content.Intent
import android.content.Intent.EXTRA_REFERRER
import android.content.pm.PackageManager
import android.content.res.Configuration
import android.graphics.Color
Expand Down Expand Up @@ -454,7 +455,11 @@ class MainActivity : FragmentActivity() {
}

if (data != null && data.toString().startsWith("tutamail://") && data.host == "interop") {
openContactEditor(data)
val caller = intent.getStringExtra(EXTRA_REFERRER)

if (caller?.startsWith("de.tutao") == true) {
openContactEditor(data)
}
}

if (intent.action != null && !intent.getBooleanExtra(ALREADY_HANDLED_INTENT, false)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ import android.Manifest
import android.content.ActivityNotFoundException
import android.content.ClipData
import android.content.Intent
import android.content.Intent.EXTRA_REFERRER
import android.net.Uri
import android.provider.Settings
import android.util.Base64
import android.util.Log
import androidx.biometric.BiometricManager
import androidx.biometric.BiometricPrompt
import androidx.core.app.ActivityCompat.startActivityForResult
import androidx.core.content.ContextCompat.startActivity
import androidx.core.content.FileProvider
import androidx.fragment.app.FragmentActivity
Expand Down Expand Up @@ -172,9 +174,10 @@ class AndroidMobileSystemFacade(

private fun tryToLaunchStore() {
try {
val packageId = activity.getString(R.string.package_name).replace("calendar", "tutanota")
startActivity(
activity,
Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=de.tutao.tutanota")),
Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=$packageId")),
null
)
} catch (e: Exception) {
Expand All @@ -187,10 +190,11 @@ class AndroidMobileSystemFacade(

val intent = Intent()
intent.setAction(Intent.ACTION_EDIT)
intent.putExtra(EXTRA_REFERRER, BuildConfig.APPLICATION_ID)
intent.setData(Uri.parse("tutamail://interop?${decodedQuery}"))

try {
startActivity(activity, intent, null)
startActivityForResult(activity, intent, 0, null)
} catch (e: Exception) {
Log.d(TAG, e.toString())
tryToLaunchStore()
Expand Down
8 changes: 7 additions & 1 deletion app-ios/calendar/Sources/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,13 @@ public let TUTA_CALENDAR_INTEROP_SCHEME = "tutacalendar"
func application(_ application: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any] = [:]) -> Bool {
switch url.scheme {
case CALENDAR_SHARE_SCHEME: Task { try! await self.viewController.handleShare(url) }
case TUTA_CALENDAR_INTEROP_SCHEME: Task { try! await self.viewController.handleInterop(url) }
case TUTA_CALENDAR_INTEROP_SCHEME:
Task {
guard let sourceApp = options[UIApplication.OpenURLOptionsKey.sourceApplication] else { return }
if String(describing: sourceApp).starts(with: "de.tutao") { return try! await self.viewController.handleInterop(url) }

TUTSLog("Tried to open Mail App from an unknown source!")
}
case nil: TUTSLog("missing scheme!")
default: TUTSLog("unknown scheme? \(url.scheme!)")
}
Expand Down
8 changes: 7 additions & 1 deletion app-ios/tutanota/Sources/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,13 @@ public let TUTA_MAIL_INTEROP_SCHEME = "tutamail"
func application(_ application: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any] = [:]) -> Bool {
switch url.scheme {
case TUTANOTA_SHARE_SCHEME: Task { try! await self.viewController.handleShare(url) }
case TUTA_MAIL_INTEROP_SCHEME: Task { try! await self.viewController.handleInterop(url) }
case TUTA_MAIL_INTEROP_SCHEME:
Task {
guard let sourceApp = options[UIApplication.OpenURLOptionsKey.sourceApplication] else { return }
if String(describing: sourceApp).starts(with: "de.tutao") { return try! await self.viewController.handleInterop(url) }

TUTSLog("Tried to open Mail App from an unknown source!")
}
case nil: TUTSLog("missing scheme!")
default: TUTSLog("unknown scheme? \(url.scheme!)")
}
Expand Down
8 changes: 1 addition & 7 deletions src/common/native/main/OpenSettingsHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,6 @@ export class OpenSettingsHandler {

async openSettings(path: string): Promise<void> {
await this.logins.waitForFullLogin()

console.log("Trying to open settings page", path)
if (this.logins.isUserLoggedIn()) {
m.route.set(`/settings/${path}`)
} else {
m.route.set(`/login?noAutoLogin=false&userId=${this.logins.getUserController().user._id}&requestedPath=${encodeURIComponent(`/settings/${path}`)}`)
}
m.route.set(`/settings/:folder`, { folder: path })
}
}
2 changes: 1 addition & 1 deletion src/common/subscription/SignupForm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ function signup(
customerFacade.generateSignupKeys(operation.id).then((keyPairs) => {
return runCaptchaFlow(mailAddress, isBusinessUse, isPaidSubscription, campaign).then(async (regDataId) => {
if (regDataId) {
const app = client.isCalendarApp() ? SubscriptionApp.Calendar : SubscriptionApp.Calendar
const app = client.isCalendarApp() ? SubscriptionApp.Calendar : SubscriptionApp.Mail
return customerFacade
.signup(keyPairs, AccountType.FREE, regDataId, mailAddress, pw, registrationCode, lang.code, app)
.then((recoverCode) => {
Expand Down
13 changes: 5 additions & 8 deletions src/common/subscription/SubscriptionViewer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ import type { UpdatableSettingsViewer } from "../settings/Interfaces.js"
import { client } from "../misc/ClientDetector.js"
import { AppStoreSubscriptionService } from "../api/entities/sys/Services.js"
import { AppType } from "../misc/ClientConstants.js"
import { ProgrammingError } from "../api/common/error/ProgrammingError.js"

assertMainOrNode()
const DAY = 1000 * 60 * 60 * 24
Expand Down Expand Up @@ -155,7 +156,7 @@ export class SubscriptionViewer implements UpdatableSettingsViewer {
: !this._isCancelled
? m(IconButton, {
title: "subscription_label",
click: async () => await this.onSubscriptionClick(),
click: () => this.onSubscriptionClick(),
icon: Icons.Edit,
size: ButtonSize.Compact,
})
Expand Down Expand Up @@ -268,7 +269,7 @@ export class SubscriptionViewer implements UpdatableSettingsViewer {
this.updateBookings()
}

private async onSubscriptionClick() {
private onSubscriptionClick() {
const paymentMethod = this._accountingInfo ? getPaymentMethodType(this._accountingInfo) : null

if (isIOSApp() && (paymentMethod == null || paymentMethod == PaymentMethodType.AppStore)) {
Expand Down Expand Up @@ -395,21 +396,17 @@ export class SubscriptionViewer implements UpdatableSettingsViewer {
}

private async canManageAppStoreSubscriptionInApp(accountingInfo: AccountingInfo, ownership: MobilePaymentSubscriptionOwnership): Promise<boolean> {
if (!accountingInfo.appStoreSubscription) {
throw Error("Trying to manage an non-existing app store subscription")
}

if (ownership === MobilePaymentSubscriptionOwnership.NotOwner) {
return true
}

const appStoreSubscriptionData = await locator.serviceExecutor.get(
AppStoreSubscriptionService,
createAppStoreSubscriptionGetIn({ subscriptionId: elementIdPart(accountingInfo.appStoreSubscription) }),
createAppStoreSubscriptionGetIn({ subscriptionId: elementIdPart(assertNotNull(accountingInfo.appStoreSubscription)) }),
)

if (!appStoreSubscriptionData || appStoreSubscriptionData.app == null) {
throw new Error("Failed to determine subscription origin")
throw new ProgrammingError("Failed to determine subscription origin")
}

const isMailSubscription = appStoreSubscriptionData.app === SubscriptionApp.Mail
Expand Down

0 comments on commit b7b13df

Please sign in to comment.