This commit is contained in:
SPRINX0\prochazka 2024-09-04 14:46:59 +02:00
parent faa186c1e4
commit d19c30d0b2
3 changed files with 55 additions and 13 deletions

View File

@ -16,7 +16,7 @@ const BrowserWindow = electron.BrowserWindow;
const path = require('path');
const url = require('url');
const mainMenuDefinition = require('./mainMenuDefinition');
const { isProApp, checkLicense } = require('./proTools');
const { isProApp } = require('./proTools');
let disableAutoUpgrade = false;
// require('@electron/remote/main').initialize();
@ -339,13 +339,11 @@ function createWindow() {
}
}
const licenseOk = !isProApp() || checkLicense(licenseKey) == 'premium';
let bounds = initialConfig['winBounds'];
if (bounds) {
bounds = ensureBoundsVisible(bounds);
}
useNativeMenu = settingsJson['app.useNativeMenu'] || !licenseOk;
useNativeMenu = settingsJson['app.useNativeMenu'];
mainWindow = new BrowserWindow({
width: 1200,

View File

@ -7,6 +7,7 @@ const { hasPermission } = require('../utility/hasPermission');
const socket = require('../utility/socket');
const _ = require('lodash');
const AsyncLock = require('async-lock');
const jwt = require('jsonwebtoken');
const currentVersion = require('../currentVersion');
const platformInfo = require('../utility/platformInfo');
@ -151,6 +152,22 @@ module.exports = {
saveLicenseKey_meta: true,
async saveLicenseKey({ licenseKey }) {
const decoded = jwt.decode(licenseKey);
if (!decoded) {
return {
status: 'error',
errorMessage: 'Invalid license key',
};
}
const { exp } = decoded;
if (exp * 1000 < Date.now()) {
return {
status: 'error',
errorMessage: 'License key is expired',
};
}
try {
if (process.env.STORAGE_DATABASE) {
await storage.writeConfig({ group: 'license', config: { licenseKey } });
@ -159,20 +176,32 @@ module.exports = {
await fs.writeFile(path.join(datadir(), 'license.key'), licenseKey);
}
socket.emitChanged(`config-changed`);
return { status: 'ok' };
} catch (err) {
return null;
return {
status: 'error',
errorMessage: err.message,
};
}
},
startTrial_meta: true,
async startTrial() {
try {
const resp = await axios.default.post(`${getAuthProxyUrl()}/trial-license`, { type: 'premium-trial', days: 30 });
return resp.data;
const ipResp = await axios.default.get('https://api.ipify.org?format=json');
const resp = await axios.default.post(`${getAuthProxyUrl()}/trial-license`, {
type: 'premium-trial',
days: 30,
publicIp: ipResp.data.ip,
});
const { token } = resp.data;
return await this.saveLicenseKey({ licenseKey: token });
} catch (err) {
return {
status: 'error',
message: err.messa,
errorMessage: err.message,
};
}
},

View File

@ -11,6 +11,7 @@
import FormSubmit from './forms/FormSubmit.svelte';
import { apiCall } from './utility/api';
import FormStyledButton from './buttons/FormStyledButton.svelte';
import getElectron from './utility/getElectron';
const config = useConfig();
const values = writable({ amoid: null, databaseServer: null });
@ -39,8 +40,12 @@
value="Save license"
on:click={async e => {
const { licenseKey } = e.detail;
await apiCall('config/save-license-key', { licenseKey });
internalRedirectTo('/index.html');
const resp = await apiCall('config/save-license-key', { licenseKey });
if (resp?.status == 'ok') {
internalRedirectTo('/index.html');
} else {
errorMessage = resp?.errorMessage || 'Error saving license key';
}
}}
/>
</div>
@ -51,16 +56,26 @@
on:click={async e => {
errorMessage = '';
const license = await apiCall('config/start-trial');
if (license?.token) {
await apiCall('config/save-license-key', { licenseKey: license.token });
if (license?.status == 'ok') {
internalRedirectTo('/index.html');
} else {
errorMessage = license?.message || 'Error starting trial';
errorMessage = license?.errorMessage || 'Error starting trial';
}
}}
/>
</div>
{#if getElectron()}
<div class="submit">
<FormStyledButton
value="Exit"
on:click={e => {
getElectron().send('quit-app');
}}
/>
</div>
{/if}
{#if errorMessage}
<div class="error">{errorMessage}</div>
{/if}