Skip to content
Closed
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
18 changes: 18 additions & 0 deletions app/main.main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3194,6 +3194,24 @@ ipc.on('show-item-in-folder', (_event, folder) => {
shell.showItemInFolder(folder);
});

ipc.handle('open-file-path', async (_event, filePath: string) => {
if (!mainWindow) {
return;
}
const fileName = basename(filePath);
const { response } = await dialog.showMessageBox(mainWindow, {
type: 'question',
buttons: ['Open', 'Cancel'],
defaultId: 0,
cancelId: 1,
message: `Open "${fileName}"?`,
detail: 'This file will be opened with your default application.',
});
if (response === 0) {
await shell.openPath(filePath);
}
});

ipc.handle('show-save-dialog', async (_event, { defaultPath }) => {
if (!mainWindow) {
log.warn('show-save-dialog: no main window');
Expand Down
4 changes: 4 additions & 0 deletions stylesheets/_modules.scss
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,10 @@ $message-padding-horizontal: 12px;
cursor: pointer;
}

.module-message__simple-attachment-container {
width: 100%;
}

.module-message__simple-attachment {
@include mixins.button-reset;

Expand Down
8 changes: 6 additions & 2 deletions ts/components/conversation/Message.dom.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import type {
ConversationType,
ConversationTypeType,
InteractionModeType,
OpenAttachmentInDefaultAppActionCreatorType,
PushPanelForConversationActionType,
SaveAttachmentActionCreatorType,
SaveAttachmentsActionCreatorType,
Expand Down Expand Up @@ -386,6 +387,7 @@ export type PropsActions = {
attachment: AttachmentType;
messageId: string;
}) => void;
openAttachmentInDefaultApp: OpenAttachmentInDefaultAppActionCreatorType;
saveAttachment: SaveAttachmentActionCreatorType;
saveAttachments: SaveAttachmentsActionCreatorType;
showLightbox: (options: {
Expand Down Expand Up @@ -1356,6 +1358,7 @@ export class Message extends React.PureComponent<Props, State> {
// attachment. But we don't want the user to tab here unless that text exists.
const tabIndex = text ? 0 : -1;
return (
<div className="module-message__simple-attachment-container">
<button
className={classNames(
'module-message__simple-attachment',
Expand Down Expand Up @@ -1462,6 +1465,7 @@ export class Message extends React.PureComponent<Props, State> {
</div>
</div>
</button>
</div>
);
}

Expand Down Expand Up @@ -3218,7 +3222,7 @@ export class Message extends React.PureComponent<Props, State> {
const {
id,
attachments,
saveAttachment,
openAttachmentInDefaultApp,
timestamp,
kickOffAttachmentDownload,
attachmentDroppedDueToSize,
Expand Down Expand Up @@ -3251,7 +3255,7 @@ export class Message extends React.PureComponent<Props, State> {
messageId: id,
});
} else {
saveAttachment(firstAttachment, timestamp);
openAttachmentInDefaultApp(firstAttachment, timestamp);
}
};

Expand Down
1 change: 1 addition & 0 deletions ts/components/conversation/TimelineItem.dom.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ const getDefaultProps = () => ({
messageExpanded: action('messageExpanded'),
showConversation: action('showConversation'),
openGiftBadge: action('openGiftBadge'),
openAttachmentInDefaultApp: action('openAttachmentInDefaultApp'),
saveAttachment: action('saveAttachment'),
saveAttachments: action('saveAttachments'),
showPinMessageDialog: action('showPinMessageDialog'),
Expand Down
1 change: 1 addition & 0 deletions ts/components/conversation/TimelineMessage.dom.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@ const createProps = (overrideProps: Partial<Props> = {}): Props => ({
: overrideProps.readStatus,
renderReactionPicker,
renderAudioAttachment,
openAttachmentInDefaultApp: action('openAttachmentInDefaultApp'),
saveAttachment: action('saveAttachment'),
saveAttachments: action('saveAttachments'),
setQuoteByMessageId: action('setQuoteByMessageId'),
Expand Down
26 changes: 26 additions & 0 deletions ts/state/ducks/conversations.preload.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright 2019 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only

import { tmpdir } from 'node:os';
import type { ThunkAction } from 'redux-thunk';
import lodash from 'lodash';
import { type PhoneNumber } from 'google-libphonenumber';
Expand Down Expand Up @@ -1227,6 +1228,7 @@ export const actions = {
saveAttachment,
saveAttachments,
saveAttachmentFromMessage,
openAttachmentInDefaultApp,
saveAvatarToDisk,
scrollToMessage,
scrollToOldestUnreadMention,
Expand Down Expand Up @@ -4187,6 +4189,30 @@ function saveAttachment(
};
}

export type OpenAttachmentInDefaultAppActionCreatorType = ReadonlyDeep<
(attachment: AttachmentType, timestamp?: number) => unknown
>;

function openAttachmentInDefaultApp(
attachment: AttachmentType,
timestamp = Date.now()
): ThunkAction<void, RootStateType, unknown, ShowToastActionType> {
return async () => {
const fullPath = await Attachment.save({
attachment,
getUnusedFilename,
readAttachmentData,
saveAttachmentToDisk,
timestamp,
baseDir: tmpdir(),
});

if (fullPath) {
await ipcRenderer.invoke('open-file-path', fullPath);
}
};
}

const showSaveMultiDialog = (
i18n: LocalizerType
): Promise<{
Expand Down
2 changes: 2 additions & 0 deletions ts/state/smart/TimelineItem.preload.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ export const SmartTimelineItem = memo(function SmartTimelineItem(
markAttachmentAsCorrupted,
messageExpanded,
onPinnedMessageRemove,
openAttachmentInDefaultApp,
openGiftBadge,
retryDeleteForEveryone,
retryMessageSend,
Expand Down Expand Up @@ -297,6 +298,7 @@ export const SmartTimelineItem = memo(function SmartTimelineItem(
sendPollVote={sendPollVote}
renderItem={renderItem}
returnToActiveCall={returnToActiveCall}
openAttachmentInDefaultApp={openAttachmentInDefaultApp}
saveAttachment={saveAttachment}
saveAttachments={saveAttachments}
scrollToPollMessage={scrollToPollMessage}
Expand Down