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

ADDED: feedback if terminal could not be started fixes #186 #190

Merged
merged 1 commit into from
Nov 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 4 additions & 4 deletions src/components/FileTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,11 @@ export class FileTableClass extends React.Component<Props, State> {
public componentDidUpdate(): void {
const scrollTop = this.state.position === -1 ? this.cache.scrollTop : null;
const viewState = this.injected.viewState;
if (!viewState.viewId) {
console.log('componentDidUpdate', this.state.position, this.cache.scrollTop, scrollTop);
}
// if (!viewState.viewId) {
// console.log('componentDidUpdate', this.state.position, this.cache.scrollTop, scrollTop);
// }

// edge case: previous saved scrollTop isn't good anymore
// edge case: previous saved scrollTop isn't valid anymore
// eg. files have been deleted, or selected item has been renamed,
// so that using previous scrollTop would hide the selected item
// if (/*scrollTop !== null && scrollTop > -1*/1) {
Expand Down
14 changes: 11 additions & 3 deletions src/components/dialogs/PrefsDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { SettingsState } from '../../state/settingsState';
import { inject } from 'mobx-react';
import { Select, ItemRenderer } from '@blueprintjs/select';
import { FsLocal, FolderExists } from '../../services/plugins/FsLocal';
import { AppAlert } from '../AppAlert';
import { ipcRenderer } from 'electron';
import { HOME_DIR } from '../../utils/platform';

Expand Down Expand Up @@ -186,10 +187,17 @@ class PrefsDialogClass extends React.Component<PrefsProps, State> {
settingsState.saveSettings();
};

testTerminal = (): void => {
const { settingsState } = this.injected;
testTerminal = async (): Promise<void> => {
const { settingsState, t } = this.injected;
const path = settingsState.getTerminalCommand(HOME_DIR);
ipcRenderer.invoke('openTerminal', path);
const error: { code: number; terminal: string } = await ipcRenderer.invoke('openTerminal', path);
if (error) {
const { code, terminal } = error;
AppAlert.show(t('DIALOG.PREFS.TEST_TERMINAL_FAILED', { terminal, code }), {
intent: Intent.DANGER,
icon: 'error',
});
}
};

public render(): React.ReactNode {
Expand Down
23 changes: 16 additions & 7 deletions src/components/shortcuts/MenuAccelerators.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,27 +99,36 @@ class MenuAcceleratorsClass extends React.Component<Props> {
}
};

onOpenTerminal = (_: string, data: { viewId: number; tabIndex: number }) => {
onOpenTerminal = async (_: string, data: { viewId: number; tabIndex: number }) => {
let cache: FileState;

if (typeof data.viewId === 'undefined') {
if (!data || typeof data.viewId === 'undefined') {
cache = this.getActiveFileCache();
} else {
const winState = this.appState.winStates[0];
const view = winState.views[data.viewId];
cache = view.caches[data.tabIndex];
if (cache.status !== 'ok') {
cache = null;
}
}

if (cache.status !== 'ok' || cache.error) {
return;
}

const isOverlayOpen = document.body.classList.contains('bp3-overlay-open');

if (cache && !isOverlayOpen && !isEditable(document.activeElement)) {
const resolvedPath = cache.getAPI().resolve(cache.path);
const { settingsState } = this.injected;
const { settingsState, t } = this.injected;
const terminalCmd = settingsState.getTerminalCommand(resolvedPath);
cache.openTerminal(terminalCmd);
const error = await cache.openTerminal(terminalCmd);
if (error) {
AppToaster.show({
message: t('ERRORS.OPEN_TERMINAL_FAILED'),
icon: 'warning-sign',
intent: Intent.WARNING,
timeout: 0,
});
}
}
};

Expand Down
21 changes: 16 additions & 5 deletions src/electron/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,22 @@ const ElectronApp = {
this.openDevTools(true);
});

ipcMain.handle('openTerminal', (event: Event, cmd: string) => {
console.log('running', cmd);
const exec = child_process.exec;
exec(cmd).unref();
});
ipcMain.handle(
'openTerminal',
(event: Event, cmd: string): Promise<{ code: number; terminal: string }> => {
console.log('running', cmd);
const exec = child_process.exec;
return new Promise((resolve) => {
exec(cmd, (error: child_process.ExecException) => {
if (error) {
resolve({ code: error.code, terminal: cmd });
} else {
resolve();
}
}).unref();
});
},
);

ipcMain.handle('languageChanged', (e: Event, strings: LocaleString) => {
if (this.appMenu) {
Expand Down
6 changes: 4 additions & 2 deletions src/locale/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@
"INVALID_FOLDER": "Invalid folder name or non-existing folder",
"DEFAULT_TERMINAL": "External terminal",
"DEFAULT_TERMINAL_HELP": "Customizes what kind of terminal to launch",
"TEST_TERMINAL": "Click here to launch the specified external terminal"
"TEST_TERMINAL": "Click here to launch the specified external terminal",
"TEST_TERMINAL_FAILED": "Unable to start specified terminal: {{terminal}} (return code: {{code}})"
},
"DELETE": {
"CONFIRM": "Are you sure you want to delete <1>{{count}}</1> file(s)/folder(s)?<3 /><4 />This action will <6>permanentaly</6> delete the selected elements."
Expand Down Expand Up @@ -199,7 +200,8 @@
"NODEST": "copy target could not be accessed",
"COPY_ERROR": "Couldn't copy files: {{message}}",
"COPY_UNKNOWN_ERROR": "Error while copying files.",
"SHELL_OPEN_FAILED": "Could not open file: {{path}}"
"SHELL_OPEN_FAILED": "Could not open file: {{path}}",
"OPEN_TERMINAL_FAILED": "Could not open terminal. Check that the path is correct in the settings."
},
"MAIN_PROCESS": {
"PRESS_TO_EXIT": "Keep pressing ⌘Q to exit"
Expand Down
6 changes: 4 additions & 2 deletions src/locale/lang/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@
"INVALID_FOLDER": "Nom de dossier invalide ou introuvable",
"DEFAULT_TERMINAL": "Terminal externe",
"DEFAULT_TERMINAL_HELP": "Spécifie le type de terminal à lancer",
"TEST_TERMINAL": "Cliquez ici pour lancer le terminal specifié"
"TEST_TERMINAL": "Cliquez ici pour lancer le terminal specifié",
"TEST_TERMINAL_FAILED": "Impossible de lancer le terminal spécifié: {{terminal}} (code de retour: {{code}})"
},
"DELETE": {
"CONFIRM": "Etes-vous sûr de vouloir supprimer <1>{{count}}</1> fichier(s)/dossier(s) ?<3 /><4 />Cette action supprimera de manière <6>permanente</6> les éléments sélectionnés."
Expand Down Expand Up @@ -199,7 +200,8 @@
"NODEST": "la destination de la copie n'est pas accessible",
"COPY_ERROR": "La copie n'a pu s'effectuer: {{message}}",
"COPY_UNKNOWN_ERROR": "Impossible de copier les fichiers demandés.",
"SHELL_OPEN_FAILED": "Impossible d'ouvrir le fichier: {{path}}"
"SHELL_OPEN_FAILED": "Impossible d'ouvrir le fichier: {{path}}",
"OPEN_TERMINAL_FAILED": "Impossible d'ouvrir le terminal. Vérifiez le chemin du terminal dans les paramètres."
},
"MAIN_PROCESS": {
"PRESS_TO_EXIT": "Maintenez la touche ⌘Q enfoncée pour quitter"
Expand Down
5 changes: 3 additions & 2 deletions src/state/fileState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -559,9 +559,10 @@ export class FileState {
return this.cd(file.dir, file.fullname).catch(this.handleError);
}

openTerminal(path: string): void {
async openTerminal(path: string): Promise<boolean> {
if (this.getFS().name === 'local') {
ipcRenderer.invoke('openTerminal', path);
const error: { code: number } = await ipcRenderer.invoke('openTerminal', path);
return !!error;
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/state/settingsState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export class SettingsState {
}

installListeners(): void {
remote.nativeTheme.on('updated', () => console.log('updated') || this.setActiveTheme());
remote.nativeTheme.on('updated', () => this.setActiveTheme());
}

getParam(name: string): JSObject {
Expand Down