Skip to content

Fix: Webpack fallback release config #3232

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions RELEASE-NOTES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## [v2.22.1]

### Fixes

- The final release build of v2.22.0 was not correctly packaged, causing a crash on startup. Affected users will need to manually download this version, which properly includes a necessary configuration file during the build process [#3232](https://github.com/Automattic/simplenote-electron/pull/3232)

## [v2.22.0]

### Fixes
Expand Down
27 changes: 0 additions & 27 deletions get-config.js

This file was deleted.

3 changes: 0 additions & 3 deletions lib/auth/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import React, { Component, Fragment } from 'react';
import classNames from 'classnames';
import cryptoRandomString from '../utils/crypto-random-string';
import { get } from 'lodash';
import getConfig from '../../get-config';
import MailIcon from '../icons/mail';
import SimplenoteLogo from '../icons/simplenote';
import Spinner from '../components/spinner';
Expand Down Expand Up @@ -48,7 +47,6 @@ export class Auth extends Component<Props> {

render() {
// Don't render this component when running on the web
const config = getConfig();
if (config.is_app_engine) {
Comment on lines -51 to 50
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens here?

With my limited Electron + Webpack + TS understanding, I think at this point config would be undefined, making the if below unreachable. Unless... config is somehow injected?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's because config is actually set as a Webpack plugin, defined here:

config: JSON.stringify(config),

With my limited knowledge that is why it exists everywhere :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep exactly, as long as you don't define it inside the file, webpack will inject it. (If it IS defined in the file then webpack will assume you want a locally-defined version instead.)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the info @roundhill @codebykat

return null;
}
Expand Down Expand Up @@ -423,7 +421,6 @@ export class Auth extends Component<Props> {
};

onWPLogin = () => {
const config = getConfig();
const redirectUrl = encodeURIComponent(config.wpcc_redirect_url);
this.authState = `app-${cryptoRandomString(20)}`;
const authUrl = `https://public-api.wordpress.com/oauth2/authorize?client_id=${config.wpcc_client_id}&redirect_uri=${redirectUrl}&response_type=code&scope=global&state=${this.authState}`;
Expand Down
3 changes: 0 additions & 3 deletions lib/boot-with-auth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import React from 'react';
import App from './app';
import { ErrorBoundaryWithAnalytics } from './error-boundary';
import Modal from 'react-modal';
import getConfig from '../get-config';
import { makeStore } from './state';
import { render } from 'react-dom';
import { Provider } from 'react-redux';
Expand All @@ -16,8 +15,6 @@ import '../scss/style.scss';

import isDevConfig from './utils/is-dev-config';

const config = getConfig();

export const bootWithToken = (
logout: () => any,
token: string,
Expand Down
3 changes: 0 additions & 3 deletions lib/boot-without-auth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import classNames from 'classnames';
import AboutDialog from './dialogs/about';
import ErrorBoundary from './error-boundary';

import getConfig from '../get-config';

import '../scss/style.scss';

type Props = {
Expand All @@ -36,7 +34,6 @@ type User = {
access_token?: string;
};

const config = getConfig();
const auth = new SimperiumAuth(config.app_id, config.app_key);

class AppWithoutAuth extends Component<Props, State> {
Expand Down
3 changes: 0 additions & 3 deletions lib/boot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,10 @@ import 'setimmediate';

import { parse } from 'cookie';

import getConfig from '../get-config';
import { boot as bootWithoutAuth } from './boot-without-auth';
import { boot as bootLoggingOut } from './logging-out';
import { isElectron } from './utils/platform';

const config = getConfig();

const clearStorage = (): Promise<void> =>
new Promise((resolveStorage) => {
localStorage.removeItem('access_token');
Expand Down
10 changes: 10 additions & 0 deletions lib/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@ import * as S from './state';

declare global {
const __TEST__: boolean;
const config: {
app_engine_url: string;
app_id: string;
app_key: string;
development: boolean;
is_app_engine: string;
version: string;
wpcc_client_id: string;
wpcc_redirect_url: string;
};

interface Window {
__REDUX_DEVTOOLS_EXTENSION_COMPOSE__?: typeof compose;
Expand Down
3 changes: 0 additions & 3 deletions lib/state/analytics/middleware.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import { debounce } from 'lodash';

import analytics from '../../analytics';
import getConfig from '../../../get-config';
import isDevConfig from '../../utils/is-dev-config';

const config = getConfig();

import type * as A from '../action-types';
import type * as S from '../';
import type * as T from '../../types';
Expand Down
5 changes: 2 additions & 3 deletions lib/state/simperium/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { default as createClient } from 'simperium';

import debugFactory from 'debug';
import actions from '../actions';
import getConfig from '../../../get-config';
import { BucketQueue } from './functions/bucket-queue';
import { InMemoryBucket } from './functions/in-memory-bucket';
import { InMemoryGhost } from './functions/in-memory-ghost';
Expand Down Expand Up @@ -37,7 +36,7 @@ export const initSimperium =
(store) => {
const { dispatch, getState } = store;

const client = createClient<Buckets>(getConfig().app_id, token, {
const client = createClient<Buckets>(config.app_id, token, {
objectStoreProvider: (bucket) => {
switch (bucket.name) {
case 'account':
Expand Down Expand Up @@ -465,7 +464,7 @@ export const initSimperium =
return result;
}

case 'REALLY_LOGOUT':
case 'REALLY_LOG_OUT':
stopSyncing();
localStorage.setItem('simplenote_logout', Math.random().toString());
client.end();
Expand Down
Loading