Skip to content

Commit

Permalink
feat: translations for incompatible license key
Browse files Browse the repository at this point in the history
  • Loading branch information
johannschopplich committed Jun 27, 2024
1 parent 09f5c0e commit 835bad5
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
3 changes: 3 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export const TRANSLATIONS: Record<Locale, Messages> = {
'modal.fields.orderId.help': '<a href="https://app.lemonsqueezy.com/my-orders" target="_blank">Get your order number</a> from Lemon Squeezy or <a href="mailto:hello@kirby.tools">contact us</a> if you cannot find it.',
'modal.error.required.fields': 'Email address and order ID are required',
'modal.error.invalid.licenseKey': 'License key invalid for this plugin',
'modal.error.incompatible.licenseKey': 'License key invalid for this plugin version',
'modal.error.registered': 'License key already registered',
'activate': 'Activate',
'activated': 'Plugin activated',
Expand All @@ -17,6 +18,7 @@ export const TRANSLATIONS: Record<Locale, Messages> = {
'modal.fields.orderId.help': 'Rufe die <a href="https://app.lemonsqueezy.com/my-orders" target="_blank">Bestellnummer von Lemon Squeezy ab</a> oder <a href="mailto:hello@kirby.tools">kontaktiere uns</a>, wenn du sie nicht finden kannst.',
'modal.error.required.fields': 'E-Mail-Adresse und Bestellnummer sind notwendig',
'modal.error.invalid.licenseKey': 'Lizenzschlüssel ungültig für dieses Plugin',
'modal.error.incompatible.licenseKey': 'Lizenzschlüssel ungültig für diese Plugin-Version',
'modal.error.registered': 'Lizenzschlüssel bereits registriert',
'activate': 'Aktivieren',
'activated': 'Plugin aktiviert',
Expand All @@ -26,6 +28,7 @@ export const TRANSLATIONS: Record<Locale, Messages> = {
'modal.fields.orderId.help': 'Obtenez votre numéro de commande sur <a href="https://app.lemonsqueezy.com/my-orders" target="_blank">Lemon Squeezy</a> ou <a href="mailto:hello@kirby.tools">contactez-nous</a> si vous ne le trouvez pas.',
'modal.error.required.fields': 'Adresse e-mail et numéro de commande requis',
'modal.error.invalid.licenseKey': 'Clé de licence invalide pour ce plugin',
'modal.error.incompatible.licenseKey': 'Clé de licence invalide pour cette version du plugin',
'modal.error.registered': 'Clé de licence déjà enregistrée',
'activate': 'Activer',
'activated': 'Plugin activé',
Expand Down
16 changes: 9 additions & 7 deletions src/license.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { nextTick, unref, useApi, usePanel } from 'kirbyuse'
import type { ComponentPublicInstance } from 'vue'
import { t } from './utils'
import type { License, MaybeRef } from './types'
import type { LicenseStatus, MaybeRef } from './types'

const LOCALHOST_HOSTNAMES = ['localhost', '127.0.0.1', '[::1]']
const LOCAL_DOMAINS = ['local', 'test', 'ddev.site']
Expand Down Expand Up @@ -84,6 +84,9 @@ export function useLicense({
if (message === 'License key not valid for this plugin') {
message = t('modal.error.invalid.licenseKey')!
}
else if (message === 'License key not valid for this plugin version') {
message = t('modal.error.incompatible.licenseKey')!
}
else if (message === 'License key already registered') {
message = t('modal.error.registered')!
}
Expand All @@ -100,23 +103,22 @@ export function useLicense({
})
}

const assertActivationIntegrity = async ({ component, license }: {
const assertActivationIntegrity = async ({ component, licenseStatus }: {
component: MaybeRef<ComponentPublicInstance | null | undefined>
license: MaybeRef<boolean | string | License>
licenseStatus: MaybeRef<LicenseStatus>
}) => {
const _component = unref(component)
const _license = unref(license)

if (_license !== false) {
if (unref(licenseStatus) === 'active') {
return
}

await nextTick()
const _component = unref(component)

if (
!_component?.$el
|| window.getComputedStyle(_component.$el).display === 'none'
|| window.getComputedStyle(_component.$el).visibility === 'hidden'
|| window.getComputedStyle(_component.$el).opacity === '0'
) {
throw new Error('Are you trying to hide the activation buttons? Please buy a license.')
}
Expand Down
6 changes: 4 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ import type { Ref } from 'vue'
export type MaybeRef<T = any> = T | Ref<T>

export type LicenseKey = string
export type LicenseStatus = 'active' | 'inactive' | 'invalid' | 'incompatible'

export interface License {
licenseKey: LicenseKey
[key: string]: string
key: LicenseKey
version: number
compatibility: string
}

0 comments on commit 835bad5

Please sign in to comment.