Skip to content

Commit

Permalink
feat: Update bash command to handle given path
Browse files Browse the repository at this point in the history
  • Loading branch information
erdkse committed Aug 26, 2021
1 parent aa7e5fe commit ec2ff70
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 51 deletions.
47 changes: 13 additions & 34 deletions electron/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ function createWindow() {
return win;
}

const openApplication = async () => {
const openApplication = async (givenPath?: string) => {
await app.whenReady();

if (isDev) {
Expand All @@ -142,7 +142,13 @@ const openApplication = async () => {
}

ElectronStore.initRenderer();
createWindow();
const win = createWindow();

if (givenPath) {
win.webContents.on('did-finish-load', () => {
win.webContents.send('executed-from', {path: givenPath});
});
}

if (app.dock) {
const image = nativeImage.createFromPath(path.join(app.getAppPath(), '/public/large-icon-256.png'));
Expand All @@ -164,45 +170,18 @@ const openApplication = async () => {
});
};

const openApplicationByCLI = () => {
if (MONOKLE_RUN_AS_NODE) {
yargs(hideBin(process.argv)).command(
'$0',
'opens current directory',
() => {},
async argv => {
const {executedFrom, _} = argv;
const [, executedPath] = _;

let fullPath: any = executedFrom;

if (executedPath && (<string>executedPath).startsWith('/')) {
fullPath = executedPath;
} else {
fullPath = `${fullPath}/${executedPath}`;
}

await app.whenReady();

ElectronStore.initRenderer();
const win = createWindow();

win.webContents.on('did-finish-load', () => {
win.webContents.send('executed-from', {path: fullPath});
});

app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit();
}
});
const {executedFrom} = argv;
openApplication(<string>executedFrom);
}
).argv;
};

terminal();

if (MONOKLE_RUN_AS_NODE) {
openApplicationByCLI();
} else {
openApplication();
}

terminal();
31 changes: 14 additions & 17 deletions resources/darwin/bin/monokle.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,19 @@ CLI="$CONTENTS/Resources/app/cli/index.js"

PASSED=$1

if [[ $PASSED = /* ]]; then
if [[ -d "$(pwd)$PASSED" ]]; then
MONOKLE_RUN_AS_NODE=1 "$MONOKLE" "$CLI" --executed-from="$(pwd)" "$@" &>/dev/null &
disown
exit $?
else
echo "The requested path is not a valid directory"
exit 1
fi
if [ -z $PASSED ]; then
ABSOLUTE_PATH=""
elif [[ $PASSED = /* ]]; then
ABSOLUTE_PATH=$PASSED
else
if [[ -d "$(pwd)/$PASSED" ]]; then
MONOKLE_RUN_AS_NODE=1 "$MONOKLE" "$CLI" --executed-from="$(pwd)" "$@" &>/dev/null &
disown
exit $?
else
echo "The requested path is not a valid directory"
exit 1
fi
ABSOLUTE_PATH="$(pwd)/$PASSED"
fi

if [[ -d "$ABSOLUTE_PATH" ]]; then
MONOKLE_RUN_AS_NODE=1 "$MONOKLE" "$CLI" --executed-from="$ABSOLUTE_PATH" "$@" &>/dev/null &
disown
exit $?
else
echo "The requested path is not a valid directory"
exit 1
fi

0 comments on commit ec2ff70

Please sign in to comment.