Skip to content

Commit

Permalink
feat: launch GUI from shell (#423)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelneale authored Dec 8, 2024
1 parent f7daed6 commit 314b872
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 2 deletions.
5 changes: 5 additions & 0 deletions ui/desktop/helper-scripts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Put `goosey` in your $PATH if you want to launch via:

`goosey .`

Will open goose GUI from any path you specify
41 changes: 41 additions & 0 deletions ui/desktop/helper-scripts/goosey
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/bin/bash

# Get the absolute path of the current directory
current_dir="$(pwd)"

# If an argument is provided, use it as the directory
if [ $# -gt 0 ]; then
# Handle tilde expansion and relative paths
if [[ "$1" == "~"* ]]; then
# Replace ~ with $HOME
dir="${1/#\~/$HOME}"
elif [[ "$1" == "." ]]; then
# Use absolute path as is
dir="$current_dir"
elif [[ "$1" == "."* ]]; then
# Convert relative path to absolute
dir="$(cd "$(dirname "$1")" && pwd)/$(basename "$1")"
else
# Convert relative path to absolute
dir="$(cd "$(dirname "$1")" && pwd)/$(basename "$1")"
fi
else
# Use current directory if no argument provided
dir="$current_dir"
fi

echo $dir

# On macOS, use the .app bundle
if [[ "$OSTYPE" == "darwin"* ]]; then
# Assuming Goose.app is installed in /Applications
if [ -d "/Applications/Goose.app" ]; then
/Applications/Goose.app/Contents/MacOS/Goose --args --dir "$dir"
else
echo "Error: Goose.app not found in /Applications"
exit 1
fi
else
# For Linux, assuming the binary is installed in the PATH
goose-app --dir "$dir"
fi
20 changes: 18 additions & 2 deletions ui/desktop/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,21 @@ if (started) app.quit();
declare var MAIN_WINDOW_VITE_DEV_SERVER_URL: string;
declare var MAIN_WINDOW_VITE_NAME: string;

// Parse command line arguments
const parseArgs = () => {
const args = process.argv.slice(2); // Remove first two elements (electron and script path)
let dirPath = null;

for (let i = 0; i < args.length; i++) {
if (args[i] === '--dir' && i + 1 < args.length) {
dirPath = args[i + 1];
break;
}
}

return { dirPath };
};

const checkApiCredentials = () => {

loadZshEnv(app.isPackaged);
Expand Down Expand Up @@ -254,10 +269,11 @@ app.whenReady().then(async () => {
}, 5000);
}

// Load zsh environment variables in production mode only
// Parse command line arguments
const { dirPath } = parseArgs();

createTray();
createChat(app);
createChat(app, undefined, dirPath);

// Show launcher input on key combo
globalShortcut.register('Control+Alt+Command+G', createLauncher);
Expand Down

0 comments on commit 314b872

Please sign in to comment.