Skip to content

Commit

Permalink
Merge branch 'laurent22:dev' into csdn_clipper
Browse files Browse the repository at this point in the history
  • Loading branch information
wljince007 committed Apr 13, 2024
2 parents 3aaef30 + 89dfbe3 commit 7c9f9cd
Show file tree
Hide file tree
Showing 67 changed files with 1,177 additions and 580 deletions.
8 changes: 7 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,10 @@ packages/app-mobile/components/NoteList.js
packages/app-mobile/components/ProfileSwitcher/ProfileEditor.js
packages/app-mobile/components/ProfileSwitcher/ProfileSwitcher.js
packages/app-mobile/components/ProfileSwitcher/useProfileConfig.js
packages/app-mobile/components/ScreenHeader.js
packages/app-mobile/components/ScreenHeader/WarningBanner.test.js
packages/app-mobile/components/ScreenHeader/WarningBanner.js
packages/app-mobile/components/ScreenHeader/WarningBox.js
packages/app-mobile/components/ScreenHeader/index.js
packages/app-mobile/components/SelectDateTimeDialog.js
packages/app-mobile/components/SideMenu.js
packages/app-mobile/components/TextInput.js
Expand All @@ -567,9 +570,12 @@ packages/app-mobile/components/screens/ConfigScreen/NoteExportSection/ExportDebu
packages/app-mobile/components/screens/ConfigScreen/NoteExportSection/ExportProfileButton.js
packages/app-mobile/components/screens/ConfigScreen/NoteExportSection/NoteExportButton.test.js
packages/app-mobile/components/screens/ConfigScreen/NoteExportSection/NoteExportButton.js
packages/app-mobile/components/screens/ConfigScreen/NoteExportSection/NoteImportButton.js
packages/app-mobile/components/screens/ConfigScreen/NoteExportSection/TaskButton.js
packages/app-mobile/components/screens/ConfigScreen/NoteExportSection/utils/exportAllFolders.js
packages/app-mobile/components/screens/ConfigScreen/NoteExportSection/utils/exportDebugReport.js
packages/app-mobile/components/screens/ConfigScreen/NoteExportSection/utils/exportProfile.js
packages/app-mobile/components/screens/ConfigScreen/NoteExportSection/utils/makeImportExportCacheDirectory.js
packages/app-mobile/components/screens/ConfigScreen/SectionHeader.js
packages/app-mobile/components/screens/ConfigScreen/SectionSelector.js
packages/app-mobile/components/screens/ConfigScreen/SettingComponent.js
Expand Down
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,10 @@ packages/app-mobile/components/NoteList.js
packages/app-mobile/components/ProfileSwitcher/ProfileEditor.js
packages/app-mobile/components/ProfileSwitcher/ProfileSwitcher.js
packages/app-mobile/components/ProfileSwitcher/useProfileConfig.js
packages/app-mobile/components/ScreenHeader.js
packages/app-mobile/components/ScreenHeader/WarningBanner.test.js
packages/app-mobile/components/ScreenHeader/WarningBanner.js
packages/app-mobile/components/ScreenHeader/WarningBox.js
packages/app-mobile/components/ScreenHeader/index.js
packages/app-mobile/components/SelectDateTimeDialog.js
packages/app-mobile/components/SideMenu.js
packages/app-mobile/components/TextInput.js
Expand All @@ -547,9 +550,12 @@ packages/app-mobile/components/screens/ConfigScreen/NoteExportSection/ExportDebu
packages/app-mobile/components/screens/ConfigScreen/NoteExportSection/ExportProfileButton.js
packages/app-mobile/components/screens/ConfigScreen/NoteExportSection/NoteExportButton.test.js
packages/app-mobile/components/screens/ConfigScreen/NoteExportSection/NoteExportButton.js
packages/app-mobile/components/screens/ConfigScreen/NoteExportSection/NoteImportButton.js
packages/app-mobile/components/screens/ConfigScreen/NoteExportSection/TaskButton.js
packages/app-mobile/components/screens/ConfigScreen/NoteExportSection/utils/exportAllFolders.js
packages/app-mobile/components/screens/ConfigScreen/NoteExportSection/utils/exportDebugReport.js
packages/app-mobile/components/screens/ConfigScreen/NoteExportSection/utils/exportProfile.js
packages/app-mobile/components/screens/ConfigScreen/NoteExportSection/utils/makeImportExportCacheDirectory.js
packages/app-mobile/components/screens/ConfigScreen/SectionHeader.js
packages/app-mobile/components/screens/ConfigScreen/SectionSelector.js
packages/app-mobile/components/screens/ConfigScreen/SettingComponent.js
Expand Down
33 changes: 33 additions & 0 deletions packages/app-cli/tests/services/plugins/api/JoplinSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import Setting from '@joplin/lib/models/Setting';
import { waitForFolderCount, setupDatabaseAndSynchronizer, switchClient, afterEachCleanUp } from '@joplin/lib/testing/test-utils';
import Folder from '@joplin/lib/models/Folder';
import { newPluginScript, newPluginService } from '../../../testUtils';
import eventManager, { EventName } from '@joplin/lib/eventManager';

describe('JoplinSettings', () => {

Expand Down Expand Up @@ -66,6 +67,38 @@ describe('JoplinSettings', () => {
await service.destroy();
});

test('should de-register settings change listeners when a plugin is unloaded', async () => {
const service = newPluginService();

const pluginScript = newPluginScript(`
joplin.plugins.register({
onStart: async function() {
await joplin.settings.registerSettings({
'test-setting': {
value: 1234,
type: 1,
public: false,
label: 'Test',
}
});
// Register 8 listeners to improve test reliability in the case
// where listeners are added/removed from other sources.
for (let i = 0; i < 8; i++) {
await joplin.settings.onChange((event) => { });
}
},
});
`);

const plugin = await service.loadPluginFromJsBundle('', pluginScript);
await service.runPlugin(plugin);

const listenerCounter = eventManager.listenerCounter_(EventName.SettingsChange);
plugin.onUnload();
expect(listenerCounter.getCountRemoved()).toBeGreaterThanOrEqual(8);
});

test('should allow registering multiple settings', async () => {
const service = newPluginService();

Expand Down
30 changes: 30 additions & 0 deletions packages/app-cli/tests/services/plugins/api/JoplinWorkspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import Note from '@joplin/lib/models/Note';
import Folder from '@joplin/lib/models/Folder';
import ItemChange from '@joplin/lib/models/ItemChange';
import { newPluginScript, newPluginService } from '../../../testUtils';
import eventManager, { EventName } from '@joplin/lib/eventManager';

describe('JoplinWorkspace', () => {

Expand Down Expand Up @@ -81,4 +82,33 @@ describe('JoplinWorkspace', () => {
expect(modFolder.title).toBe('changedtitle');
});

test('should remove event listeners when plugins are unloaded', async () => {
const service = newPluginService();

const pluginScript = newPluginScript(`
joplin.plugins.register({
onStart: async () => {
// Register each listener 8 times to improve test reliability -- it's possible
// for listeners for the same events to be added/removed by other sources.
for (let i = 0; i < 8; i++) {
await joplin.workspace.onNoteChange(async (event) => { });
await joplin.workspace.onResourceChange(async (event) => { });
await joplin.workspace.filterEditorContextMenu(async (event) => { });
}
}
})
`);
const plugin = await service.loadPluginFromJsBundle('', pluginScript);
await service.runPlugin(plugin);

const itemChangeListenerCounter = eventManager.listenerCounter_(EventName.ItemChange);
const resourceChangeListenerCounter = eventManager.listenerCounter_(EventName.ResourceChange);

plugin.onUnload();

expect(itemChangeListenerCounter.getCountRemoved()).toBeGreaterThanOrEqual(8);
expect(resourceChangeListenerCounter.getCountRemoved()).toBeGreaterThanOrEqual(8);

await service.destroy();
});
});
2 changes: 1 addition & 1 deletion packages/app-desktop/bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ export class Bridge {
if (await pathExists(fullPath)) {
const fileExtension = extname(fullPath);
const userAllowedExtension = this.extraAllowedOpenExtensions.includes(fileExtension);
if (userAllowedExtension || isSafeToOpen(fullPath)) {
if (userAllowedExtension || await isSafeToOpen(fullPath)) {
return shell.openPath(fullPath);
} else {
const allowOpenId = 2;
Expand Down
7 changes: 5 additions & 2 deletions packages/app-desktop/gui/ClipperConfigScreen.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const React = require('react');
import { CSSProperties } from 'react';
const { connect } = require('react-redux');
const { clipboard } = require('electron');
import ExtensionBadge from './ExtensionBadge';
Expand Down Expand Up @@ -46,7 +47,8 @@ class ClipperConfigScreenComponent extends React.Component {
public render() {
const theme = themeStyle(this.props.themeId);

const containerStyle = { ...theme.containerStyle, overflowY: 'scroll',
const containerStyle: CSSProperties = { ...theme.containerStyle,
overflowY: 'scroll',
// padding: theme.configScreenPadding,
backgroundColor: theme.backgroundColor3 };

Expand Down Expand Up @@ -104,7 +106,8 @@ class ClipperConfigScreenComponent extends React.Component {
);
}

const apiTokenStyle = { ...theme.textStyle, color: theme.colorFaded,
const apiTokenStyle: CSSProperties = { ...theme.textStyle,
color: theme.colorFaded,
wordBreak: 'break-all',
paddingTop: 10,
paddingBottom: 10 };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import * as React from 'react';
import shim from '@joplin/lib/shim';
import bridge from '../../../services/bridge';
import StyledLink from '../../style/StyledLink';
import { ThemeStyle } from '@joplin/lib/theme';

interface Props {
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
theme: any;
theme: ThemeStyle;
text: string;
}

Expand All @@ -19,7 +19,7 @@ const MacOSMissingPasswordHelpLink: React.FunctionComponent<Props> = props => {
const macInfoLink = (
<StyledLink href="#"
onClick={openMissingPasswordFAQ}
style={props.theme.linkStyle}
style={props.theme.urlStyle}
>
{props.text}
</StyledLink>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ interface Props {
const EncryptionConfigScreen = (props: Props) => {
const { inputPasswords, onInputPasswordChange } = useInputPasswords(props.passwords);

// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
const theme: any = useMemo(() => {
const theme = useMemo(() => {
return themeStyle(props.themeId);
}, [props.themeId]);

Expand Down
5 changes: 2 additions & 3 deletions packages/app-desktop/gui/ExtensionBadge.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from 'react';
import bridge from '../services/bridge';
import { _ } from '@joplin/lib/locale';
import { themeStyle } from '@joplin/lib/theme';
import { ThemeStyle, themeStyle } from '@joplin/lib/theme';
const { createSelector } = require('reselect');

interface Props {
Expand All @@ -17,8 +17,7 @@ const themeSelector = (_state: any, props: any) => themeStyle(props.themeId);

const styleSelector = createSelector(
themeSelector,
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
(theme: any) => {
(theme: ThemeStyle) => {
const output = {
root: {
width: 220,
Expand Down
5 changes: 3 additions & 2 deletions packages/app-desktop/gui/KeymapConfig/styles/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { ThemeStyle } from '@joplin/lib/theme';

const { buildStyle } = require('@joplin/lib/theme');

export default function styles(themeId: number) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
return buildStyle('KeymapConfigScreen', themeId, (theme: any) => {
return buildStyle('KeymapConfigScreen', themeId, (theme: ThemeStyle) => {
return {
container: {
...theme.containerStyle,
Expand Down
4 changes: 2 additions & 2 deletions packages/app-desktop/gui/MainScreen/MainScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import shim from '@joplin/lib/shim';
import bridge from '../../services/bridge';
import time from '@joplin/lib/time';
import styled from 'styled-components';
import { themeStyle } from '@joplin/lib/theme';
import { themeStyle, ThemeStyle } from '@joplin/lib/theme';
import validateLayout from '../ResizableLayout/utils/validateLayout';
import iterateItems from '../ResizableLayout/utils/iterateItems';
import removeItem from '../ResizableLayout/utils/removeItem';
Expand Down Expand Up @@ -572,7 +572,7 @@ class MainScreenComponent extends React.Component<Props, State> {
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
public renderNotification(theme: any, styles: any) {
public renderNotification(theme: ThemeStyle, styles: any) {
if (!this.messageBoxVisible()) return null;

const onViewStatusScreen = () => {
Expand Down
6 changes: 3 additions & 3 deletions packages/app-desktop/gui/MultiNoteActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import { PluginStates } from '@joplin/lib/services/plugins/reducer';
import * as React from 'react';
import NoteListUtils from './utils/NoteListUtils';
import { Dispatch } from 'redux';
import { ThemeStyle } from '@joplin/lib/theme';

const { buildStyle } = require('@joplin/lib/theme');
import { buildStyle } from '@joplin/lib/theme';
const bridge = require('@electron/remote').require('./bridge').default;

interface MultiNoteActionsProps {
Expand All @@ -19,8 +20,7 @@ interface MultiNoteActionsProps {
}

function styles_(props: MultiNoteActionsProps) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
return buildStyle('MultiNoteActions', props.themeId, (theme: any) => {
return buildStyle('MultiNoteActions', props.themeId, (theme: ThemeStyle) => {
return {
root: {
display: 'inline-flex',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { ThemeAppearance } from '@joplin/lib/themes/type';
import { NoteBodyEditorProps } from '../../../utils/types';
const { buildStyle } = require('@joplin/lib/theme');
import { buildStyle } from '@joplin/lib/theme';

export default function styles(props: NoteBodyEditorProps) {
const leftExtraToolbarContainerWidth = props.watchedNoteFiles.length > 0 ? 120 : 80;
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
return buildStyle(['TinyMCE', props.style.width, props.style.height, leftExtraToolbarContainerWidth], props.themeId, (theme: any) => {
return buildStyle(['TinyMCE', props.style.width, props.style.height, leftExtraToolbarContainerWidth], props.themeId, theme => {
const extraToolbarContainer = {
boxSizing: 'content-box',
backgroundColor: theme.backgroundColor3,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ interface Props {
}

function styles_(props: Props) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
return buildStyle(['NoteEditorTitleBar'], props.themeId, (theme: any) => {
return buildStyle(['NoteEditorTitleBar'], props.themeId, theme => {
return {
titleInput: {
flex: 1,
Expand Down
5 changes: 2 additions & 3 deletions packages/app-desktop/gui/NoteEditor/styles/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { NoteEditorProps } from '../utils/types';

const { buildStyle } = require('@joplin/lib/theme');
import { buildStyle } from '@joplin/lib/theme';

export default function styles(props: NoteEditorProps) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
return buildStyle(['NoteEditor'], props.themeId, (theme: any) => {
return buildStyle(['NoteEditor'], props.themeId, theme => {
return {
root: {
boxSizing: 'border-box',
Expand Down
2 changes: 1 addition & 1 deletion packages/app-desktop/gui/NotePropertiesDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ class NotePropertiesDialog extends React.Component<Props, State> {
const ll = this.latLongFromLocation(value);
url = Note.geoLocationUrlFromLatLong(ll.latitude, ll.longitude);
}
const urlStyle = { ...theme.urlStyle, maxWidth: '180px', overflow: 'hidden', whiteSpace: 'nowrap', textOverflow: 'ellipsis' };
const urlStyle: React.CSSProperties = { ...theme.urlStyle, maxWidth: '180px', overflow: 'hidden', whiteSpace: 'nowrap', textOverflow: 'ellipsis' };
controlComp = (
<a href="#" onClick={() => bridge().openExternal(url)} style={urlStyle}>
{displayedValue}
Expand Down
5 changes: 2 additions & 3 deletions packages/app-desktop/gui/NoteToolbar/NoteToolbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { utils as pluginUtils } from '@joplin/lib/services/plugins/reducer';
import ToolbarButtonUtils, { ToolbarButtonInfo } from '@joplin/lib/services/commands/ToolbarButtonUtils';
import stateToWhenClauseContext from '../../services/commands/stateToWhenClauseContext';
const { connect } = require('react-redux');
const { buildStyle } = require('@joplin/lib/theme');
import { buildStyle } from '@joplin/lib/theme';

interface NoteToolbarProps {
themeId: number;
Expand All @@ -16,8 +16,7 @@ interface NoteToolbarProps {
}

function styles_(props: NoteToolbarProps) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
return buildStyle('NoteToolbar', props.themeId, (theme: any) => {
return buildStyle('NoteToolbar', props.themeId, theme => {
return {
root: {
...props.style,
Expand Down
3 changes: 1 addition & 2 deletions packages/app-desktop/gui/ShareNoteDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ interface Props {
}

function styles_(props: Props) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
return buildStyle('ShareNoteDialog', props.themeId, (theme: any) => {
return buildStyle('ShareNoteDialog', props.themeId, theme => {
return {
root: {
minWidth: 500,
Expand Down
13 changes: 6 additions & 7 deletions packages/app-desktop/gui/Sidebar/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,12 @@ import PerFolderSortOrderService from '../../services/sortOrder/PerFolderSortOrd
import { getFolderCallbackUrl, getTagCallbackUrl } from '@joplin/lib/callbackUrlUtils';
import FolderIconBox from '../FolderIconBox';
import onFolderDrop from '@joplin/lib/models/utils/onFolderDrop';
import { Theme } from '@joplin/lib/themes/type';
import { RuntimeProps } from './commands/focusElementSideBar';
const { connect } = require('react-redux');
import { renderFolders, renderTags } from '@joplin/lib/components/shared/side-menu-shared';
import { getTrashFolderIcon, getTrashFolderId } from '@joplin/lib/services/trash';
import { focus } from '@joplin/lib/utils/focusHandler';
const { themeStyle } = require('@joplin/lib/theme');
import { ThemeStyle, themeStyle } from '@joplin/lib/theme';
const bridge = require('@electron/remote').require('./bridge').default;
const Menu = bridge().Menu;
const MenuItem = bridge().MenuItem;
Expand Down Expand Up @@ -505,10 +504,10 @@ const SidebarComponent = (props: Props) => {
return count ? <StyledNoteCount className="note-count-label">{count}</StyledNoteCount> : null;
};

// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
const renderExpandIcon = (theme: any, isExpanded: boolean, isVisible: boolean) => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
const style: any = { width: 16, maxWidth: 16, opacity: 0.5, fontSize: Math.round(theme.toolbarIconSize * 0.8), display: 'flex', justifyContent: 'center' };
const renderExpandIcon = (theme: ThemeStyle, isExpanded: boolean, isVisible: boolean) => {
const style: React.CSSProperties = {
width: 16, maxWidth: 16, opacity: 0.5, fontSize: Math.round(theme.toolbarIconSize * 0.8), display: 'flex', justifyContent: 'center',
};
if (!isVisible) style.visibility = 'hidden';
return <i className={isExpanded ? 'fas fa-caret-down' : 'fas fa-caret-right'} style={style}></i>;
};
Expand All @@ -527,7 +526,7 @@ const SidebarComponent = (props: Props) => {
menu.popup({ window: bridge().window() });
}, []);

const renderAllNotesItem = (theme: Theme, selected: boolean) => {
const renderAllNotesItem = (theme: ThemeStyle, selected: boolean) => {
return (
<StyledListItem key="allNotesHeader" selected={selected} className={'list-item-container list-item-depth-0 all-notes'} isSpecialItem={true}>
<StyledExpandLink>{renderExpandIcon(theme, false, false)}</StyledExpandLink>
Expand Down
Loading

0 comments on commit 7c9f9cd

Please sign in to comment.