chore: ugprade snjs deps (#898)

This commit is contained in:
Mo
2022-02-24 12:57:32 -06:00
committed by GitHub
parent 7fe0873bbb
commit c3d849d204
19 changed files with 163 additions and 182 deletions

View File

@@ -2,25 +2,18 @@
declare global {
interface Window {
// eslint-disable-next-line camelcase
_bugsnag_api_key?: string;
// eslint-disable-next-line camelcase
_purchase_url?: string;
// eslint-disable-next-line camelcase
_plans_url?: string;
// eslint-disable-next-line camelcase
_dashboard_url?: string;
// eslint-disable-next-line camelcase
_default_sync_server: string;
// eslint-disable-next-line camelcase
_enable_unfinished_features: boolean;
// eslint-disable-next-line camelcase
_websocket_url: string;
bugsnagApiKey?: string;
dashboardUrl?: string;
defaultFilesHost: string;
defaultSyncServer: string;
devAccountEmail?: string;
devAccountPassword?: string;
devAccountServer?: string;
enabledUnfinishedFeatures: boolean;
plansUrl?: string;
purchaseUrl?: string;
startApplication?: StartApplication;
_devAccountEmail?: string;
_devAccountPassword?: string;
_devAccountServer?: string;
websocketUrl: string;
}
}
@@ -37,6 +30,7 @@ import { isDev } from './utils';
const startApplication: StartApplication = async function startApplication(
defaultSyncServerHost: string,
defaultFilesHostHost: string,
bridge: Bridge,
enableUnfinishedFeatures: boolean,
webSocketUrl: string
@@ -46,6 +40,7 @@ const startApplication: StartApplication = async function startApplication(
const mainApplicationGroup = new ApplicationGroup(
defaultSyncServerHost,
defaultFilesHostHost,
bridge,
enableUnfinishedFeatures ? Runtime.Dev : Runtime.Prod,
webSocketUrl
@@ -79,10 +74,11 @@ const startApplication: StartApplication = async function startApplication(
if (IsWebPlatform) {
startApplication(
window._default_sync_server,
window.defaultSyncServer,
window.defaultFilesHost,
new BrowserBridge(WebAppVersion),
window._enable_unfinished_features,
window._websocket_url
window.enabledUnfinishedFeatures,
window.websocketUrl
);
} else {
window.startApplication = startApplication;

View File

@@ -37,9 +37,9 @@ export const SignInPane: FunctionComponent<Props> = observer(
if (emailInputRef?.current) {
emailInputRef.current?.focus();
}
if (isDev && window._devAccountEmail) {
setEmail(window._devAccountEmail);
setPassword(window._devAccountPassword as string);
if (isDev && window.devAccountEmail) {
setEmail(window.devAccountEmail);
setPassword(window.devAccountPassword as string);
}
}, []);

View File

@@ -30,8 +30,8 @@ export const PremiumFeaturesModal: FunctionalComponent<Props> = ({
const handleClick = () => {
if (hasSubscription) {
openSubscriptionDashboard(application);
} else if (window._plans_url) {
window.location.assign(window._plans_url);
} else if (window.plansUrl) {
window.location.assign(window.plansUrl);
}
};

View File

@@ -49,8 +49,8 @@ export const RevisionContentLocked: FunctionComponent<{
type="primary"
label="Discover plans"
onClick={() => {
if (window._plans_url) {
window.location.assign(window._plans_url);
if (window.plansUrl) {
window.location.assign(window.plansUrl);
}
}}
/>

View File

@@ -5,8 +5,6 @@ export function openSubscriptionDashboard(application: SNApplication): void {
if (!token) {
return;
}
window.open(
`${window._dashboard_url}?subscription_token=${token}`
);
window.open(`${window.dashboardUrl}?subscription_token=${token}`);
});
}

View File

@@ -1,21 +1,24 @@
import { FunctionalComponent } from "preact";
import { FunctionalComponent } from 'preact';
import { LinkButton, Text } from '@/preferences/components';
import { Button } from '@/components/Button';
import { WebApplication } from "@/ui_models/application";
import { useState } from "preact/hooks";
import { loadPurchaseFlowUrl } from "@/purchaseFlow/PurchaseFlowWrapper";
import { WebApplication } from '@/ui_models/application';
import { useState } from 'preact/hooks';
import { loadPurchaseFlowUrl } from '@/purchaseFlow/PurchaseFlowWrapper';
export const NoSubscription: FunctionalComponent<{
application: WebApplication;
}> = ({ application }) => {
const [isLoadingPurchaseFlow, setIsLoadingPurchaseFlow] = useState(false);
const [purchaseFlowError, setPurchaseFlowError] = useState<string | undefined>(undefined);
const [purchaseFlowError, setPurchaseFlowError] = useState<
string | undefined
>(undefined);
const onPurchaseClick = async () => {
const errorMessage = 'There was an error when attempting to redirect you to the subscription page.';
const errorMessage =
'There was an error when attempting to redirect you to the subscription page.';
setIsLoadingPurchaseFlow(true);
try {
if (!await loadPurchaseFlowUrl(application)) {
if (!(await loadPurchaseFlowUrl(application))) {
setPurchaseFlowError(errorMessage);
}
} catch (e) {
@@ -29,29 +32,25 @@ export const NoSubscription: FunctionalComponent<{
<>
<Text>You don't have a Standard Notes subscription yet.</Text>
{isLoadingPurchaseFlow && (
<Text>
Redirecting you to the subscription page...
</Text>
<Text>Redirecting you to the subscription page...</Text>
)}
{purchaseFlowError && (
<Text className="color-danger">
{purchaseFlowError}
</Text>
<Text className="color-danger">{purchaseFlowError}</Text>
)}
<div className="flex">
<LinkButton
className="min-w-20 mt-3 mr-3"
label="Learn More"
link={window._plans_url as string}
link={window.plansUrl as string}
/>
{application.hasAccount() &&
{application.hasAccount() && (
<Button
className="min-w-20 mt-3"
type="primary"
label="Subscribe"
onClick={onPurchaseClick}
/>
}
)}
</div>
</>
);

View File

@@ -16,11 +16,11 @@ export const getPurchaseFlowUrl = async (
const currentUrl = window.location.origin;
const successUrl = isDesktopApplication() ? `standardnotes://` : currentUrl;
if (application.noAccount()) {
return `${window._purchase_url}/offline?&success_url=${successUrl}`;
return `${window.purchaseUrl}/offline?&success_url=${successUrl}`;
}
const token = await application.getNewSubscriptionToken();
if (token) {
return `${window._purchase_url}?subscription_token=${token}&success_url=${successUrl}`;
return `${window.purchaseUrl}?subscription_token=${token}&success_url=${successUrl}`;
}
return undefined;
};

View File

@@ -25,7 +25,7 @@ export function startErrorReporting(): void {
*/
isNullOrUndefined(disableErrorReporting) ||
disableErrorReporting ||
!window._bugsnag_api_key
!window.bugsnagApiKey
) {
SNLog.onError = console.error;
return;
@@ -41,7 +41,7 @@ export function startErrorReporting(): void {
}
Bugsnag.start({
apiKey: window._bugsnag_api_key,
apiKey: window.bugsnagApiKey,
appType: isDesktopApplication() ? 'desktop' : 'web',
appVersion: getDesktopVersion() || WebAppVersion,
collectUserIp: false,

View File

@@ -1,8 +1,9 @@
import { Bridge } from "./services/bridge";
import { Bridge } from './services/bridge';
export type StartApplication = (
defaultSyncServerHost: string,
defaultFilesHostHost: string,
bridge: Bridge,
enableUnfinishedFeatures: boolean,
webSocketUrl: string,
webSocketUrl: string
) => Promise<void>;

View File

@@ -75,9 +75,9 @@ export class AccountMenuState {
this.appEventListeners.push(
this.application.addEventObserver(async () => {
runInAction(() => {
if (isDev && window._devAccountServer) {
this.setServer(window._devAccountServer);
this.application.setCustomHost(window._devAccountServer);
if (isDev && window.devAccountServer) {
this.setServer(window.devAccountServer);
this.application.setCustomHost(window.devAccountServer);
} else {
this.setServer(this.application.getHost());
}

View File

@@ -62,7 +62,7 @@ type ObserverCallback = (event: AppStateEvent, data?: any) => Promise<void>;
export class AppState {
readonly enableUnfinishedFeatures: boolean =
window?._enable_unfinished_features;
window?.enabledUnfinishedFeatures;
application: WebApplication;
observers: ObserverCallback[] = [];

View File

@@ -25,7 +25,7 @@ export const SMART_TAGS_FEATURE_NAME = 'Smart Tags';
*/
export class FeaturesState {
readonly enableUnfinishedFeatures: boolean =
window?._enable_unfinished_features;
window?.enabledUnfinishedFeatures;
_hasFolders = false;
_hasSmartTags = false;

View File

@@ -48,23 +48,24 @@ export class WebApplication extends SNApplication {
platform: Platform,
identifier: string,
defaultSyncServerHost: string,
defaultFilesHostHost: string,
public bridge: Bridge,
webSocketUrl: string,
runtime: Runtime
) {
super(
bridge.environment,
platform,
deviceInterface,
WebCrypto,
new AlertService(),
super({
environment: bridge.environment,
platform: platform,
deviceInterface: deviceInterface,
crypto: WebCrypto,
alertService: new AlertService(),
identifier,
[],
defaultSyncServerHost,
bridge.appVersion,
webSocketUrl,
runtime
);
defaultHost: defaultSyncServerHost,
defaultFilesHost: defaultFilesHostHost,
appVersion: bridge.appVersion,
webSocketUrl: webSocketUrl,
runtime,
});
deviceInterface.setApplication(this);
this.noteControllerGroup = new NoteGroupController(this);
this.iconsController = new IconsController();

View File

@@ -20,6 +20,7 @@ import { ThemeManager } from '@/services/themeManager';
export class ApplicationGroup extends SNApplicationGroup {
constructor(
private defaultSyncServerHost: string,
private defaultFilesHostHost: string,
private bridge: Bridge,
private runtime: Runtime,
private webSocketUrl: string
@@ -50,6 +51,7 @@ export class ApplicationGroup extends SNApplicationGroup {
platform,
descriptor.identifier,
this.defaultSyncServerHost,
this.defaultFilesHostHost,
this.bridge,
this.webSocketUrl,
this.runtime