Skip to content

Commit

Permalink
Merge branch 'master' into reload-app
Browse files Browse the repository at this point in the history
  • Loading branch information
TimQuelch authored Aug 31, 2024
2 parents 51a9b8b + 7738ea0 commit eed2101
Show file tree
Hide file tree
Showing 13 changed files with 145 additions and 17 deletions.
69 changes: 59 additions & 10 deletions packages/desktop-client/src/components/manager/ConfigServer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ import {
} from 'loot-core/src/shared/environment';

import { useActions } from '../../hooks/useActions';
import { useGlobalPref } from '../../hooks/useGlobalPref';
import { useNavigate } from '../../hooks/useNavigate';
import { useSetThemeColor } from '../../hooks/useSetThemeColor';
import { theme } from '../../style';
import { Button, ButtonWithLoading } from '../common/Button2';
import { BigInput } from '../common/Input';
import { Link } from '../common/Link';
import { Text } from '../common/Text';
import { View } from '../common/View';
import { useServerURL, useSetServerURL } from '../ServerContext';
Expand All @@ -32,6 +34,9 @@ export function ConfigServer() {
}, [currentUrl]);
const [loading, setLoading] = useState(false);
const [error, setError] = useState<string | null>(null);
const [_serverSelfSignedCert, setServerSelfSignedCert] = useGlobalPref(
'serverSelfSignedCert',
);

function getErrorMessage(error: string) {
switch (error) {
Expand Down Expand Up @@ -83,6 +88,23 @@ export function ConfigServer() {
setUrl(window.location.origin);
}

async function onSelectSelfSignedCertificate() {
const selfSignedCertificateLocation = await window.Actual?.openFileDialog({
properties: ['openFile'],
filters: [
{
name: 'Self Signed Certificate',
extensions: ['crt', 'pem'],
},
],
});

if (selfSignedCertificateLocation) {
setServerSelfSignedCert(selfSignedCertificateLocation[0]);
globalThis.window.Actual.relaunch(); // relaunch to use the certificate
}
}

async function onSkip() {
await setServerUrl(null);
await loggedIn();
Expand Down Expand Up @@ -121,16 +143,43 @@ export function ConfigServer() {
</Text>

{error && (
<Text
style={{
marginTop: 20,
color: theme.errorText,
borderRadius: 4,
fontSize: 15,
}}
>
{getErrorMessage(error)}
</Text>
<>
<Text
style={{
marginTop: 20,
color: theme.errorText,
borderRadius: 4,
fontSize: 15,
}}
>
{getErrorMessage(error)}
</Text>
{isElectron() && (
<View
style={{ display: 'flex', flexDirection: 'row', marginTop: 20 }}
>
<Text
style={{
color: theme.errorText,
borderRadius: 4,
fontSize: 15,
}}
>
<Trans>
If the server is using a self-signed certificate{' '}
<Link
variant="text"
style={{ fontSize: 15 }}
onClick={onSelectSelfSignedCertificate}
>
select it here
</Link>
.
</Trans>
</Text>
</View>
)}
</>
)}

<View style={{ display: 'flex', flexDirection: 'row', marginTop: 30 }}>
Expand Down
21 changes: 20 additions & 1 deletion packages/desktop-client/src/components/reports/Overview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,26 @@ export function Overview() {
const isDashboardsFeatureEnabled = useFeatureFlag('dashboards');
const spendingReportFeatureFlag = useFeatureFlag('spendingReport');

const layout = useWidgetLayout(widgets);
const baseLayout = useWidgetLayout(widgets);
const layout =
spendingReportFeatureFlag &&
!isDashboardsFeatureEnabled &&
!baseLayout.find(({ type }) => type === 'spending-card')
? [
...baseLayout,
{
i: 'spending',
type: 'spending-card' as const,
x: 0,
y: Math.max(...baseLayout.map(({ y }) => y), 0) + 2,
w: 4,
h: 2,
minW: 3,
minH: 2,
meta: null,
},
]
: baseLayout;

const closeNotifications = () => {
dispatch(removeNotification('import'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,8 @@ export function SelectedTransactionsButton({
]);
useHotkeys(
's',
() => (!types.trans || linked ? onViewSchedule() : onLinkSchedule()),
() =>
!types.trans || linked ? onViewSchedule() : onLinkSchedule(selectedIds),
{
scopes: ['app'],
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1240,7 +1240,9 @@ const Transaction = memo(function Transaction({
focused={focusedField === 'payee'}
/* Filter out the account we're currently in as it is not a valid transfer */
accounts={accounts.filter(account => account.id !== accountId)}
payees={payees.filter(payee => payee.transfer_acct !== accountId)}
payees={payees.filter(
payee => !payee.transfer_acct || payee.transfer_acct !== accountId,
)}
valueStyle={valueStyle}
transaction={transaction}
subtransactions={subtransactions}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// // @ts-strict-ignore
// @ts-strict-ignore
import nodeFetch from 'node-fetch';

export const fetch = (input: RequestInfo | URL, options?: RequestInit) => {
Expand Down
11 changes: 8 additions & 3 deletions packages/loot-core/src/server/db/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { v4 as uuidv4 } from 'uuid';

import * as fs from '../../platform/server/fs';
import * as sqlite from '../../platform/server/sqlite';
import * as monthUtils from '../../shared/months';
import { groupById } from '../../shared/util';
import {
CategoryEntity,
Expand All @@ -27,6 +28,7 @@ import {
convertFromSelect,
} from '../aql';
import {
toDateRepr,
accountModel,
categoryModel,
categoryGroupModel,
Expand Down Expand Up @@ -544,18 +546,21 @@ export function getPayees() {
}

export function getCommonPayees() {
const threeMonthsAgo = '20240201';
const twelveWeeksAgo = toDateRepr(
monthUtils.subWeeks(monthUtils.currentDate(), 12),
);
const limit = 10;
return all(`
SELECT p.id as id, p.name as name, p.favorite as favorite,
p.category as category, TRUE as common, NULL as transfer_acct,
count(*) as c,
max(t.date) as latest
FROM payees p
LEFT JOIN v_transactions t on t.payee == p.id
LEFT JOIN v_transactions_internal_alive t on t.payee == p.id
WHERE LENGTH(p.name) > 0
AND p.tombstone = 0
AND t.date > ${twelveWeeksAgo}
GROUP BY p.id
HAVING latest > ${threeMonthsAgo}
ORDER BY c DESC ,p.transfer_acct IS NULL DESC, p.name
COLLATE NOCASE
LIMIT ${limit}
Expand Down
26 changes: 26 additions & 0 deletions packages/loot-core/src/server/main.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
// @ts-strict-ignore
import './polyfills';
import https from 'https';
import tls from 'tls';

import * as injectAPI from '@actual-app/api/injected';
import * as CRDT from '@actual-app/crdt';
import { v4 as uuidv4 } from 'uuid';
Expand Down Expand Up @@ -1253,6 +1256,12 @@ handlers['save-global-prefs'] = async function (prefs) {
if ('theme' in prefs) {
await asyncStorage.setItem('theme', prefs.theme);
}
if ('serverSelfSignedCert' in prefs) {
await asyncStorage.setItem(
'server-self-signed-cert',
prefs.serverSelfSignedCert,
);
}
return 'ok';
};

Expand Down Expand Up @@ -2126,6 +2135,23 @@ export async function initApp(isDev, socketName) {
}
}

const selfSignedCertPath = await asyncStorage.getItem(
'server-self-signed-cert',
);

if (selfSignedCertPath) {
try {
const selfSignedCert = await fs.readFile(selfSignedCertPath);
https.globalAgent.options.ca = [...tls.rootCertificates, selfSignedCert];
} catch (error) {
console.error(
'Unable to add the self signed certificate, removing its reference',
error,
);
await asyncStorage.removeItem('server-self-signed-cert');
}
}

const url = await asyncStorage.getItem('server-url');

if (!url) {
Expand Down
1 change: 1 addition & 0 deletions packages/loot-core/src/types/prefs.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,5 @@ export type GlobalPrefs = Partial<{
keyId?: string;
theme: Theme;
documentDir: string; // Electron only
serverSelfSignedCert: string; // Electron only
}>;
1 change: 1 addition & 0 deletions packages/loot-core/webpack/webpack.browser.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ module.exports = {
process: require.resolve('process/browser'),
stream: require.resolve('stream-browserify'),
tls: false,
https: false,
// used by memfs in a check which we can ignore I think
url: false,
zlib: require.resolve('browserify-zlib'),
Expand Down
6 changes: 6 additions & 0 deletions upcoming-release-notes/3308.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
category: Maintenance
authors: [MikesGlitch]
---

Support servers with self signed certificates in the Desktop app
6 changes: 6 additions & 0 deletions upcoming-release-notes/3318.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
category: Bugfix
authors: [qedi-r]
---

Fix display of deleted payees in suggested payee list
6 changes: 6 additions & 0 deletions upcoming-release-notes/3323.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
category: Bugfix
authors: [MatissJanis]
---

Dashboards: add back spending report if dashboards are not enabled
6 changes: 6 additions & 0 deletions upcoming-release-notes/3324.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
category: Bugfix
authors: [MatissJanis]
---

Fix "s" hotkey breaking in transaction table.

0 comments on commit eed2101

Please sign in to comment.