Skip to content

Commit

Permalink
feat(file-open): open files in Lumi when clicked on (closes #1169) (#…
Browse files Browse the repository at this point in the history
…1470)

* feat(file-open): open files in Lumi when clicked on (closes #1169)

* test(lint): make linter happy

* test(lint): make linter happy
  • Loading branch information
JPSchellenberg committed Apr 21, 2021
1 parent c6de423 commit 121c190
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 5 deletions.
9 changes: 8 additions & 1 deletion client/src/state/H5PEditor/H5PEditorActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { ThunkAction, ThunkDispatch } from 'redux-thunk';
import * as Sentry from '@sentry/browser';
import Logger from '../../helpers/Logger';

import * as H from 'history';

import {
ContentId,
ITab,
Expand Down Expand Up @@ -484,7 +486,8 @@ export function save(
}

export function importH5P(
path: string
path: string,
history?: H.History
): ThunkAction<void, null, null, SaveActions> {
return (dispatch: any) => {
const tabId = shortid();
Expand All @@ -494,6 +497,10 @@ export function importH5P(
type: H5P_IMPORT_REQUEST
});

if (history) {
history.push('/h5peditor');
}

return api
.importH5P(path)
.then(({ body }) => {
Expand Down
3 changes: 1 addition & 2 deletions client/src/views/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import React, { useEffect } from 'react';
import { BrowserRouter as Router, Route, Switch } from 'react-router-dom';
import { useDispatch } from 'react-redux';
import { useTranslation } from 'react-i18next';

import Logger from '../helpers/Logger';

import CssBaseline from '@material-ui/core/CssBaseline';
Expand Down Expand Up @@ -48,8 +47,8 @@ export default function AppContainer() {
return (
<div id="app">
<CssBaseline />
<Websocket />
<Router>
<Websocket />
<AppBar />
<Switch>
<Route
Expand Down
9 changes: 9 additions & 0 deletions client/src/views/Launchpad.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import React from 'react';
import { useDispatch } from 'react-redux';
import { useHistory } from 'react-router-dom';
import { History } from 'history';

import { makeStyles, createStyles, Theme } from '@material-ui/core/styles';
import Card from '@material-ui/core/Card';
Expand All @@ -19,6 +21,10 @@ import { Link } from 'react-router-dom';

import { track } from '../state/track/actions';

declare var window: {
h: History;
};

const useStyles = makeStyles((theme: Theme) =>
createStyles({
root: {
Expand Down Expand Up @@ -56,6 +62,9 @@ export default function Launchpad() {
const classes = useStyles();
const { t } = useTranslation();
const dispatch = useDispatch();
const history = useHistory();

window.h = history;

return (
<div className={classes.root}>
Expand Down
10 changes: 8 additions & 2 deletions client/src/views/Websocket.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import { connect } from 'react-redux';
import * as Sentry from '@sentry/browser';
import SocketIOClient from 'socket.io-client';

import { History } from 'history';
import Logger from '../helpers/Logger';
import { ITab } from '../state/H5PEditor/H5PEditorTypes';
import { actions, IState, selectors } from '../state';
Expand All @@ -24,6 +24,10 @@ interface IComponentState {}

interface IProps extends IStateProps, IDispatchProps {}

declare var window: {
h: History;
};

export class WebsocketContainer extends React.Component<
IProps,
IComponentState
Expand Down Expand Up @@ -74,7 +78,9 @@ export class WebsocketContainer extends React.Component<

case 'OPEN_H5P':
action.payload.paths.forEach((file: any) => {
dispatch(actions.h5peditor.importH5P(file));
dispatch(
actions.h5peditor.importH5P(file, window.h)
);
});
break;

Expand Down
17 changes: 17 additions & 0 deletions server/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,23 @@ app.on('window-all-closed', () => {
}
});

app.on('open-file', (event, openedFilePath) => {
let filePath = openedFilePath;
if (process.argv.length >= 2) {
// or electron.remote.process.argv
filePath = process.argv[1];
}

websocket.emit('action', {
payload: {
paths: [filePath]
},
type: 'OPEN_H5P'
});

event.preventDefault();
});

app.on('activate', () => {
// on macOS it is common to re-create a window even after all windows have been closed
if (mainWindow === null) {
Expand Down

0 comments on commit 121c190

Please sign in to comment.