Skip to content

Commit

Permalink
Desktop: Fix keyboard can't add text after certain error/info dialogs…
Browse files Browse the repository at this point in the history
… are shown (#11603)
  • Loading branch information
personalizedrefrigerator authored Jan 8, 2025
1 parent 633d87e commit e1e2ba8
Show file tree
Hide file tree
Showing 12 changed files with 36 additions and 19 deletions.
9 changes: 7 additions & 2 deletions packages/app-desktop/bridge.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import ElectronAppWrapper from './ElectronAppWrapper';
import shim from '@joplin/lib/shim';
import shim, { MessageBoxType } from '@joplin/lib/shim';
import { _, setLocale } from '@joplin/lib/locale';
import { BrowserWindow, nativeTheme, nativeImage, shell, dialog, MessageBoxSyncOptions, safeStorage } from 'electron';
import { dirname, toSystemSlashes } from '@joplin/lib/path-utils';
Expand Down Expand Up @@ -384,9 +384,14 @@ export class Bridge {

/* returns the index of the clicked button */
public showMessageBox(message: string, options: MessageDialogOptions = {}) {
const defaultButtons = [_('OK')];
if (options.type !== MessageBoxType.Error && options.type !== MessageBoxType.Info) {
defaultButtons.push(_('Cancel'));
}

const result = this.showMessageBox_(this.activeWindow(), { type: 'question',
message: message,
buttons: [_('OK'), _('Cancel')], ...options });
buttons: defaultButtons, ...options });

return result;
}
Expand Down
3 changes: 2 additions & 1 deletion packages/app-desktop/commands/copyDevCommand.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { CommandRuntime, CommandDeclaration } from '@joplin/lib/services/CommandService';
import { _ } from '@joplin/lib/locale';
import shim, { MessageBoxType } from '@joplin/lib/shim';
const app = require('@electron/remote').app;
const { clipboard } = require('electron');

Expand All @@ -14,7 +15,7 @@ export const runtime = (): CommandRuntime => {
const appPath = app.getPath('exe');
const cmd = `${appPath} --env dev`;
clipboard.writeText(cmd);
alert(`The dev mode command has been copied to clipboard:\n\n${cmd}`);
await shim.showMessageBox(`The dev mode command has been copied to clipboard:\n\n${cmd}`, { type: MessageBoxType.Info });
},
};
};
5 changes: 3 additions & 2 deletions packages/app-desktop/commands/restoreNoteRevision.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { CommandRuntime, CommandDeclaration, CommandContext } from '@joplin/lib/services/CommandService';
import RevisionService from '@joplin/lib/services/RevisionService';
import shim, { MessageBoxType } from '@joplin/lib/shim';

export const declaration: CommandDeclaration = {
name: 'restoreNoteRevision',
Expand All @@ -11,9 +12,9 @@ export const runtime = (): CommandRuntime => {
execute: async (_context: CommandContext, noteId: string, reverseRevIndex = 0) => {
try {
const note = await RevisionService.instance().restoreNoteById(noteId, reverseRevIndex);
alert(RevisionService.instance().restoreSuccessMessage(note));
await shim.showMessageBox(RevisionService.instance().restoreSuccessMessage(note), { type: MessageBoxType.Info });
} catch (error) {
alert(error.message);
await shim.showErrorDialog(error.message);
}
},
};
Expand Down
3 changes: 2 additions & 1 deletion packages/app-desktop/gui/ClipperConfigScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import ClipperServer from '@joplin/lib/ClipperServer';
import Setting from '@joplin/lib/models/Setting';
import EncryptionService from '@joplin/lib/services/e2ee/EncryptionService';
import { AppState } from '../app.reducer';
import shim, { MessageBoxType } from '@joplin/lib/shim';

class ClipperConfigScreenComponent extends React.Component {
public constructor() {
Expand All @@ -30,7 +31,7 @@ class ClipperConfigScreenComponent extends React.Component {
private copyToken_click() {
clipboard.writeText(this.props.apiToken);

alert(_('Token has been copied to the clipboard!'));
void shim.showMessageBox(_('Token has been copied to the clipboard!'), { type: MessageBoxType.Info });
}

private renewToken_click() {
Expand Down
3 changes: 2 additions & 1 deletion packages/app-desktop/gui/ConfigScreen/ConfigScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import shouldShowMissingPasswordWarning from '@joplin/lib/components/shared/conf
import MacOSMissingPasswordHelpLink from './controls/MissingPasswordHelpLink';
const { KeymapConfigScreen } = require('../KeymapConfig/KeymapConfigScreen');
import SettingComponent, { UpdateSettingValueEvent } from './controls/SettingComponent';
import shim from '@joplin/lib/shim';


interface Font {
Expand Down Expand Up @@ -144,7 +145,7 @@ class ConfigScreenComponent extends React.Component<any, any> {
screenName = section.name;

if (this.hasChanges()) {
const ok = confirm(_('This will open a new screen. Save your current changes?'));
const ok = await shim.showConfirmationDialog(_('This will open a new screen. Save your current changes?'));
if (ok) {
await shared.saveSettings(this);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import EncryptionService from '@joplin/lib/services/e2ee/EncryptionService';
import { themeStyle } from '@joplin/lib/theme';
import { _ } from '@joplin/lib/locale';
import time from '@joplin/lib/time';
import shim from '@joplin/lib/shim';
import shim, { MessageBoxType } from '@joplin/lib/shim';
import dialogs from '../dialogs';
import { decryptedStatText, determineKeyPassword, dontReencryptData, enableEncryptionConfirmationMessages, onSavePasswordClick, onToggleEnabledClick, reencryptData, upgradeMasterKey, useInputPasswords, useNeedMasterPassword, usePasswordChecker, useStats, useToggleShowDisabledMasterKeys } from '@joplin/lib/components/EncryptionConfigScreen/utils';
import { MasterKeyEntity } from '@joplin/lib/services/e2ee/types';
Expand Down Expand Up @@ -47,7 +47,7 @@ const EncryptionConfigScreen = (props: Props) => {
const onUpgradeMasterKey = useCallback(async (mk: MasterKeyEntity) => {
const password = determineKeyPassword(mk.id, masterPasswordKeys, props.masterPassword, props.passwords);
const result = await upgradeMasterKey(mk, password);
alert(result);
await shim.showMessageBox(result, { type: MessageBoxType.Info });
}, [props.passwords, masterPasswordKeys, props.masterPassword]);

const renderNeedUpgradeSection = () => {
Expand Down
3 changes: 2 additions & 1 deletion packages/app-desktop/gui/MasterPasswordDialog/Dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import EncryptionService from '@joplin/lib/services/e2ee/EncryptionService';
import KvStore from '@joplin/lib/services/KvStore';
import ShareService from '@joplin/lib/services/share/ShareService';
import LabelledPasswordInput from '../PasswordInput/LabelledPasswordInput';
import shim from '@joplin/lib/shim';

interface Props {
themeId: number;
Expand Down Expand Up @@ -80,7 +81,7 @@ export default function(props: Props) {
void reg.waitForSyncFinishedThenSync();
onClose();
} catch (error) {
alert(error.message);
void shim.showErrorDialog(error.message);
} finally {
setUpdatingPassword(false);
}
Expand Down
3 changes: 2 additions & 1 deletion packages/app-desktop/gui/NoteRevisionViewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const urlUtils = require('@joplin/lib/urlUtils');
const ReactTooltip = require('react-tooltip');
const { connect } = require('react-redux');
import shared from '@joplin/lib/components/shared/note-screen-shared';
import shim, { MessageBoxType } from '@joplin/lib/shim';

interface Props {
themeId: number;
Expand Down Expand Up @@ -97,7 +98,7 @@ class NoteRevisionViewerComponent extends React.PureComponent<Props, State> {
this.setState({ restoring: true });
await RevisionService.instance().importRevisionNote(this.state.note);
this.setState({ restoring: false });
alert(RevisionService.instance().restoreSuccessMessage(this.state.note));
await shim.showMessageBox(RevisionService.instance().restoreSuccessMessage(this.state.note), { type: MessageBoxType.Info });
}

private backButton_click() {
Expand Down
11 changes: 7 additions & 4 deletions packages/app-desktop/gui/ShareFolderDialog/ShareFolderDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { connect } from 'react-redux';
import { reg } from '@joplin/lib/registry';
import useAsyncEffect, { AsyncEffectEvent } from '@joplin/lib/hooks/useAsyncEffect';
import { ChangeEvent, Dropdown, DropdownOptions, DropdownVariant } from '../Dropdown/Dropdown';
import shim from '@joplin/lib/shim';

const logger = Logger.create('ShareFolderDialog');

Expand Down Expand Up @@ -242,13 +243,13 @@ function ShareFolderDialog(props: Props) {
}

async function recipient_delete(event: RecipientDeleteEvent) {
if (!confirm(_('Delete this invitation? The recipient will no longer have access to this shared notebook.'))) return;
if (!await shim.showConfirmationDialog(_('Delete this invitation? The recipient will no longer have access to this shared notebook.'))) return;

try {
await ShareService.instance().deleteShareRecipient(event.shareUserId);
} catch (error) {
logger.error(error);
alert(_('The recipient could not be removed from the list. Please try again.\n\nThe error was: "%s"', error.message));
await shim.showErrorDialog(_('The recipient could not be removed from the list. Please try again.\n\nThe error was: "%s"', error.message));
}

await ShareService.instance().refreshShareUsers(share.id);
Expand Down Expand Up @@ -290,7 +291,7 @@ function ShareFolderDialog(props: Props) {
});
await ShareService.instance().setPermissions(share.id, shareUserId, permissionsFromString(value));
} catch (error) {
alert(`Could not set permissions: ${error.message}`);
void shim.showErrorDialog(`Could not set permissions: ${error.message}`);
logger.error(error);
} finally {
setRecipientsBeingUpdated(prev => {
Expand Down Expand Up @@ -383,7 +384,9 @@ function ShareFolderDialog(props: Props) {

async function buttonRow_click(event: ClickEvent) {
if (event.buttonName === 'unshare') {
if (!confirm(_('Unshare this notebook? The recipients will no longer have access to its content.'))) return;
if (!await shim.showConfirmationDialog(_('Unshare this notebook? The recipients will no longer have access to its content.'))) {
return;
}
await ShareService.instance().unshareFolder(props.folderId);
void synchronize();
}
Expand Down
3 changes: 2 additions & 1 deletion packages/app-desktop/gui/ShareNoteDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { connect } from 'react-redux';
import { AppState } from '../app.reducer';
import { getEncryptionEnabled } from '@joplin/lib/services/synchronizer/syncInfoUtils';
import SyncTargetRegistry from '@joplin/lib/SyncTargetRegistry';
import shim from '@joplin/lib/shim';
const { clipboard } = require('electron');

interface Props {
Expand Down Expand Up @@ -146,7 +147,7 @@ export function ShareNoteDialog(props: Props) {
reg.logger().error('ShareNoteDialog: Cannot publish note:', error);

setSharesState('idle');
alert(JoplinServerApi.connectionErrorMessage(error));
void shim.showErrorDialog(JoplinServerApi.connectionErrorMessage(error));
}

break;
Expand Down
3 changes: 2 additions & 1 deletion packages/app-desktop/gui/Sidebar/hooks/useOnRenderItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import HeaderItem from '../listItemComponents/HeaderItem';
import AllNotesItem from '../listItemComponents/AllNotesItem';
import ListItemWrapper from '../listItemComponents/ListItemWrapper';
import { focus } from '@joplin/lib/utils/focusHandler';
import shim from '@joplin/lib/shim';

const Menu = bridge().Menu;
const MenuItem = bridge().MenuItem;
Expand Down Expand Up @@ -309,7 +310,7 @@ const useOnRenderItem = (props: Props) => {
}
} catch (error) {
logger.error(error);
alert(error.message);
await shim.showErrorDialog(error.message);
}
}, []);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { CommandRuntime, CommandDeclaration, CommandContext } from '@joplin/lib/
import { _ } from '@joplin/lib/locale';
import ShareService from '@joplin/lib/services/share/ShareService';
import Logger from '@joplin/utils/Logger';
import shim from '@joplin/lib/shim';

const logger = Logger.create('leaveSharedFolder');

Expand All @@ -13,7 +14,7 @@ export const declaration: CommandDeclaration = {
export const runtime = (): CommandRuntime => {
return {
execute: async (_context: CommandContext, folderId: string = null) => {
const answer = confirm(_('This will remove the notebook from your collection and you will no longer have access to its content. Do you wish to continue?'));
const answer = await shim.showConfirmationDialog(_('This will remove the notebook from your collection and you will no longer have access to its content. Do you wish to continue?'));
if (!answer) return;

try {
Expand All @@ -28,7 +29,7 @@ export const runtime = (): CommandRuntime => {
await ShareService.instance().leaveSharedFolder(folderId, share.user.id);
} catch (error) {
logger.error(error);
alert(_('Error: %s', error.message));
await shim.showErrorDialog(_('Error: %s', error.message));
}
},
enabledCondition: 'joplinServerConnected && folderIsShareRootAndNotOwnedByUser',
Expand Down

0 comments on commit e1e2ba8

Please # to comment.