Skip to content
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

Use original file name for exports when possible #688

Merged
merged 2 commits into from
Jul 8, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion main/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ const openEditorWindow = async (filePath, {recordedFps, isNewRecording, original

editorWindow.webContents.on('did-finish-load', async () => {
ipc.callRenderer(editorWindow, 'export-options', exportOptions);
await ipc.callRenderer(editorWindow, 'file', {filePath, fps, originalFilePath});
await ipc.callRenderer(editorWindow, 'file', {filePath, fps, originalFilePath, isNewRecording});
editorWindow.show();
});
};
Expand Down
6 changes: 3 additions & 3 deletions main/export.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

const path = require('path');
const {basename, parse} = require('path');
Copy link
Member

Choose a reason for hiding this comment

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

Generally don't use destructuring for path. Most of the names are too generic without context and that makes the code harder to read. parse could mean so many things, but when you see path.parse it's much clearer.

Copy link
Member Author

Choose a reason for hiding this comment

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

That makes a lot of sense 👍

const PCancelable = require('p-cancelable');
const moment = require('moment');

Expand All @@ -22,7 +22,7 @@ class Export {
this.isDefault = options.isDefault;

const now = moment();
this.defaultFileName = `Kapture ${now.format('YYYY-MM-DD')} at ${now.format('H.mm.ss')}.${this.format}`;
this.defaultFileName = options.isNewRecording ? `Kapture ${now.format('YYYY-MM-DD')} at ${now.format('H.mm.ss')}.${this.format}` : `${parse(this.inputPath).name}.${this.format}`;

this.context = new ShareServiceContext({
format: this.format,
Expand All @@ -39,7 +39,7 @@ class Export {

get data() {
return {
defaultFileName: this.isDefault ? path.basename(this.context.targetFilePath) : this.defaultFileName,
defaultFileName: this.isDefault ? basename(this.context.targetFilePath) : this.defaultFileName,
text: this.text,
status: this.status,
percentage: this.percentage,
Expand Down
9 changes: 5 additions & 4 deletions renderer/containers/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ export default class EditorContainer extends Container {
this.videoContainer = videoContainer;
}

mount = (filePath, fps = 15, originalFilePath, resolve) => {
mount = (filePath, fps = 15, originalFilePath, isNewRecording, resolve) => {
const src = `file://${filePath}`;
this.finishLoading = resolve;

this.setState({src, filePath, originalFilePath, fps, originalFps: fps, wasMuted: false});
this.setState({src, filePath, originalFilePath, fps, originalFps: fps, wasMuted: false, isNewRecording});
this.videoContainer.setSrc(src);
}

Expand Down Expand Up @@ -172,7 +172,7 @@ export default class EditorContainer extends Container {
}

startExport = () => {
const {width, height, fps, filePath, originalFilePath, options, format, plugin: serviceTitle, originalFps} = this.state;
const {width, height, fps, filePath, originalFilePath, options, format, plugin: serviceTitle, originalFps, isNewRecording} = this.state;
const {startTime, endTime, isMuted} = this.videoContainer.state;

const plugin = options.find(option => option.format === format).plugins.find(p => p.title === serviceTitle);
Expand All @@ -193,7 +193,8 @@ export default class EditorContainer extends Container {
isDefault,
serviceTitle,
format,
originalFps
originalFps,
isNewRecording
};

const {ipcRenderer: ipc} = require('electron-better-ipc');
Expand Down
4 changes: 2 additions & 2 deletions renderer/pages/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ export default class EditorPage extends React.Component {
componentDidMount() {
const {ipcRenderer: ipc} = require('electron-better-ipc');

ipc.answerMain('file', async ({filePath, fps, originalFilePath}) => {
ipc.answerMain('file', async ({filePath, fps, originalFilePath, isNewRecording}) => {
await new Promise((resolve, reject) => {
editorContainer.mount(filePath, parseInt(fps, 10), originalFilePath, resolve, reject);
editorContainer.mount(filePath, parseInt(fps, 10), originalFilePath, isNewRecording, resolve, reject);
});
return true;
});
Expand Down