Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .erb/configs/webpack.config.renderer.dev.dll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,18 @@ const configuration: webpack.Configuration = {

externals: ['fsevents', 'crypto-browserify'],

resolve: {
alias: {
react: path.resolve(__dirname, '../../node_modules/react'),
'react-dom': path.resolve(__dirname, '../../node_modules/react-dom'),
'react/jsx-runtime': path.resolve(__dirname, '../../node_modules/react/jsx-runtime'),
'react/jsx-dev-runtime': path.resolve(
__dirname,
'../../node_modules/react/jsx-dev-runtime'
)
}
},

/**
* Use `module` from `webpack.config.renderer.dev.js`
*/
Expand Down
12 changes: 12 additions & 0 deletions .erb/configs/webpack.config.renderer.dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,18 @@ const configuration: webpack.Configuration = {
path.join(webpackPaths.srcRendererPath, 'index.tsx')
],

resolve: {
alias: {
react: path.resolve(__dirname, '../../node_modules/react'),
'react-dom': path.resolve(__dirname, '../../node_modules/react-dom'),
'react/jsx-runtime': path.resolve(__dirname, '../../node_modules/react/jsx-runtime'),
'react/jsx-dev-runtime': path.resolve(
__dirname,
'../../node_modules/react/jsx-dev-runtime'
)
}
},

output: {
path: webpackPaths.distRendererPath,
publicPath: '/',
Expand Down
12 changes: 12 additions & 0 deletions .erb/configs/webpack.config.renderer.prod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,18 @@ const configuration: webpack.Configuration = {

entry: [path.join(webpackPaths.srcRendererPath, 'index.tsx')],

resolve: {
alias: {
react: path.resolve(__dirname, '../../node_modules/react'),
'react-dom': path.resolve(__dirname, '../../node_modules/react-dom'),
'react/jsx-runtime': path.resolve(__dirname, '../../node_modules/react/jsx-runtime'),
'react/jsx-dev-runtime': path.resolve(
__dirname,
'../../node_modules/react/jsx-dev-runtime'
)
}
},

output: {
path: webpackPaths.distRendererPath,
publicPath: './',
Expand Down
218 changes: 218 additions & 0 deletions HOOKS_IMPLEMENTATION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,218 @@
# Hooks Feature Implementation - FULLY FUNCTIONAL ✅

This implementation successfully adds 4 new hook settings to the Oblivion Desktop application that allow users to specify executables to run when certain connection events occur. **The hooks are now fully functional and will execute external programs when the events happen.**

## Added Hook Types

1. **Connection Success Hook** (`hookConnectSuccess`)
- Executable to run when connection is successfully established
- Arguments setting: `hookConnectSuccessArgs`
- **Triggers**: When VPN connection is successfully established

2. **Connection Failure Hook** (`hookConnectFail`)
- Executable to run when connection attempt fails
- Arguments setting: `hookConnectFailArgs`
- **Triggers**: When VPN connection fails to establish after all retry attempts

3. **Disconnect Hook** (`hookDisconnect`)
- Executable to run when disconnected
- Arguments setting: `hookDisconnectArgs`
- **Triggers**: When VPN connection is intentionally or unintentionally disconnected

4. **Connection Error Hook** (`hookConnectionError`)
- Executable to run when connection error occurs while connected
- Arguments setting: `hookConnectionErrorArgs`
- **Triggers**: When an error occurs while already connected (e.g., connection reset by peer, port conflicts, etc.)

## Implementation Status: ✅ FULLY FUNCTIONAL

All features have been successfully implemented including execution logic:

- ✅ Settings configuration and storage
- ✅ UI components with browse functionality
- ✅ File dialog integration
- ✅ Internationalization (i18n) support
- ✅ Reset/restore functionality
- ✅ TypeScript type safety
- ✅ CSS styling
- ✅ Cross-platform compatibility
- ✅ **Hook execution engine**
- ✅ **Context information passing**
- ✅ **Error handling for hook execution**
- ✅ **Logging for hook events**

## Files Modified

### Settings & Configuration

- ✅ `src/defaultSettings.ts` - Added new hook settings to settingsKeys type and defaultSettings object
- ✅ `src/localization/type.ts` - Added hook-related translation keys to Settings interface
- ✅ `src/localization/en.ts` - Added English translations for hook settings
- ✅ `src/localization/fa.ts` - Added Persian translations for hook settings
- ✅ `src/localization/ar.ts` - Added Arabic translations for hook settings
- ✅ `src/localization/cn.ts` - Added Chinese translations for hook settings
- ✅ `src/localization/[others].ts` - Added placeholder translations for all other languages

### IPC Communication

- ✅ `src/main/ipcListeners/fileDialog.ts` - New file for file dialog functionality
- ✅ `src/main/ipc.ts` - Import the new file dialog listener
- ✅ `src/main/preload.ts` - Added invoke method to electron handler

### UI Components

- ✅ `src/renderer/components/HookInput/index.tsx` - New component for hook input fields with browse functionality
- ✅ `src/renderer/pages/Options/useOptions.ts` - Added hook state management and handlers
- ✅ `src/renderer/pages/Options/index.tsx` - Added hook UI components to the options page
- ✅ `src/renderer/components/Modal/Restore/index.tsx` - Updated to handle hook settings reset
- ✅ `src/renderer/components/Modal/Restore/useRestoreModal.ts` - Added hook settings to restore functionality

### Styling

- ✅ `assets/css/style.css` - Added CSS styles for hook input components

## New Features Implemented

1. **File Browse Dialog**: Users can click "Browse" button to select executables via native file dialog
2. **Manual Path Entry**: Users can manually type/paste executable paths
3. **Command Arguments**: Each hook supports optional command line arguments
4. **Settings Persistence**: All hook settings are saved and loaded with other app settings
5. **Reset Functionality**: Hook settings are included in the restore defaults functionality
6. **Responsive Design**: Hook inputs adapt to different screen sizes
7. **Multilingual Support**: All UI text is translatable and translated for major languages

## UI Layout

The hooks section appears in the Options page under the "Hooks" section with:

- Input field for executable path
- Browse button to open file dialog
- Input field for optional arguments
- Description text for each hook type
- Responsive layout that stacks on mobile devices

## File Dialog Filter

The file dialog filters for common executable file types:

- Windows: `.exe`, `.bat`, `.cmd`
- macOS: `.app`
- Linux: `.sh`
- All files: `*`

## Usage Instructions

1. Navigate to Options page in the application
2. Scroll to the "Hooks" section (appears after the current settings)
3. For each hook type (4 total):
- Either type/paste the executable path manually
- OR click "Browse" to select via file dialog
- Optionally add command line arguments in the arguments field
4. Settings are automatically saved when changed
5. Use "Restore" button to reset all hooks to default (empty)

## Hook Execution and Context Information

When hooks are executed, they receive context information through environment variables:

### Common Environment Variables (All Hooks)

- `OBLIVION_HOOK_TYPE`: The type of hook being executed (`connectSuccess`, `connectFail`, `disconnect`, `connectionError`)
- `OBLIVION_TIMESTAMP`: ISO timestamp when the hook was triggered
- `OBLIVION_PROXYMODE`: Current proxy mode (e.g., `tun`, `system`)
- `OBLIVION_PORT`: Proxy port number
- `OBLIVION_HOSTIP`: Host IP address

### Connection Success Hook Additional Variables

- `OBLIVION_METHOD`: Connection method (e.g., `gool`, `psiphon`)
- `OBLIVION_ENDPOINT`: Connection endpoint
- `OBLIVION_LOCATION`: Selected location/country

### Connection Failure Hook Additional Variables

- `OBLIVION_RETRYATTEMPTS`: Number of retry attempts made

### Connection Error Hook Additional Variables

- `OBLIVION_ERRORMESSAGE`: Raw error message that triggered the hook
- `OBLIVION_TRANSLATEDERROR`: User-friendly translated error message

## Example Hook Scripts

### Windows Batch Script (`test-hook.bat`)

```batch
@echo off
echo Hook executed: %OBLIVION_HOOK_TYPE%
echo Time: %OBLIVION_TIMESTAMP%
echo Proxy Mode: %OBLIVION_PROXYMODE%
echo Port: %OBLIVION_PORT%
echo Host IP: %OBLIVION_HOSTIP%
if defined OBLIVION_METHOD echo Method: %OBLIVION_METHOD%
if defined OBLIVION_ENDPOINT echo Endpoint: %OBLIVION_ENDPOINT%
if defined OBLIVION_ERRORMESSAGE echo Error: %OBLIVION_ERRORMESSAGE%
```

### PowerShell Script (`test-hook.ps1`)

```powershell
param([string]$Message = "Hook execution")
$env:PSModulePath # Access all OBLIVION_* environment variables
Write-Host "Hook Type: $env:OBLIVION_HOOK_TYPE"
Write-Host "Timestamp: $env:OBLIVION_TIMESTAMP"
Write-Host "Proxy Mode: $env:OBLIVION_PROXYMODE"
# Log to file, send notifications, update external systems, etc.
```

## Technical Implementation Details

- All hook settings default to empty strings (`''`)
- File paths are stored as absolute paths for reliability
- The implementation is cross-platform compatible (Windows, macOS, Linux)
- Hook settings are included in all settings operations (get, set, restore)
- TypeScript types ensure type safety throughout the application
- CSS styles provide consistent UI experience with existing application design
- **Hook execution is asynchronous and non-blocking**
- **Failed hook executions are logged but don't affect VPN functionality**
- **Hooks run in detached processes with a 30-second timeout**
- **Context information is passed via environment variables**

## Security Considerations

- Hook executables are validated to exist before execution
- Basic file extension validation is performed
- Hook processes run detached and cannot block the main application
- Environment variables are prefixed with `OBLIVION_` to avoid conflicts
- Hook execution errors are logged but don't crash the application

## Completed Implementation

The hooks feature is now **fully functional** and includes:

1. ✅ **UI Implementation**: Complete settings interface with file browsing
2. ✅ **Storage System**: Persistent storage of hook configurations
3. ✅ **Execution Engine**: Full hook execution with context passing
4. ✅ **Error Handling**: Comprehensive error handling and logging
5. ✅ **Cross-Platform Support**: Works on Windows, macOS, and Linux
6. ✅ **Internationalization**: Multi-language support
7. ✅ **Security**: Safe execution with validation and timeouts

## Testing Recommendations

1. Test hook execution with provided test scripts (`test-hook.bat`, `test-hook.ps1`)
2. Test file dialog on all supported platforms
3. Test input validation for executable paths
4. Test settings persistence across app restarts
5. Test restore functionality
6. Test responsive layout on different screen sizes
7. Test internationalization with different languages
8. **Test actual hook execution during connection events**
9. **Test hook execution with invalid executables**
10. **Test environment variable passing**

---

**Implementation completed successfully! The hooks feature is now fully integrated and functional in the Oblivion Desktop application.** 🎉

**Users can now set up executable hooks that will automatically run when connection events occur, with full context information passed via environment variables.**
120 changes: 120 additions & 0 deletions HOOKS_USAGE_GUIDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
# How to Use Hooks in Oblivion Desktop

The hooks feature allows you to automatically run external programs when VPN connection events occur.

## Setup Instructions

1. **Open Oblivion Desktop** and navigate to the **Options** page
2. **Scroll down** to find the "Hooks" section
3. **Configure each hook type** as needed:
- **On Connection Success**: Runs when VPN connects successfully
- **On Connection Fail**: Runs when VPN fails to connect
- **On Disconnect**: Runs when VPN disconnects
- **On Connection Error**: Runs when connection errors occur

## Configuring a Hook

1. **Enter executable path manually** OR click **"Browse"** to select a file
2. **Add command line arguments** (optional) in the Arguments field
3. **Settings are saved automatically** when you make changes

## Example Use Cases

### Notification Scripts

- Show desktop notifications when connected/disconnected
- Play custom sounds for different events
- Send messages to messaging apps

### Network Configuration

- Update firewall rules when connected
- Restart network services
- Update DNS settings

### Logging and Monitoring

- Log connection events to files
- Send status updates to monitoring systems
- Update external dashboards

## Sample Scripts

### Windows Notification (PowerShell)

```powershell
# Save as notify-connection.ps1
param([string]$Title = "VPN Status")

$hookType = $env:OBLIVION_HOOK_TYPE
$timestamp = $env:OBLIVION_TIMESTAMP

switch ($hookType) {
"connectSuccess" {
[System.Windows.Forms.MessageBox]::Show("VPN Connected Successfully!", $Title)
}
"connectFail" {
[System.Windows.Forms.MessageBox]::Show("VPN Connection Failed!", $Title)
}
"disconnect" {
[System.Windows.Forms.MessageBox]::Show("VPN Disconnected", $Title)
}
"connectionError" {
[System.Windows.Forms.MessageBox]::Show("VPN Connection Error: $env:OBLIVION_ERRORMESSAGE", $Title)
}
}
```

### Linux/macOS Notification (Bash)

```bash
#!/bin/bash
# Save as notify-connection.sh and make executable

case "$OBLIVION_HOOK_TYPE" in
"connectSuccess")
notify-send "VPN Connected" "Successfully connected via $OBLIVION_PROXYMODE"
;;
"connectFail")
notify-send "VPN Failed" "Connection failed after $OBLIVION_RETRYATTEMPTS attempts"
;;
"disconnect")
notify-send "VPN Disconnected" "VPN connection terminated"
;;
"connectionError")
notify-send "VPN Error" "$OBLIVION_ERRORMESSAGE"
;;
esac
```

## Environment Variables Available

Your hook scripts receive information through environment variables:

- `OBLIVION_HOOK_TYPE`: Type of event (connectSuccess, connectFail, disconnect, connectionError)
- `OBLIVION_TIMESTAMP`: When the event occurred
- `OBLIVION_PROXYMODE`: Current proxy mode
- `OBLIVION_PORT`: Proxy port
- `OBLIVION_HOSTIP`: Host IP address

Additional variables depending on the hook type:

- Connection Success: `OBLIVION_METHOD`, `OBLIVION_ENDPOINT`, `OBLIVION_LOCATION`
- Connection Failure: `OBLIVION_RETRYATTEMPTS`
- Connection Error: `OBLIVION_ERRORMESSAGE`, `OBLIVION_TRANSLATEDERROR`

## Important Notes

- **Hook execution is asynchronous** - they won't block VPN operations
- **Hooks have a 30-second timeout** to prevent hanging
- **Failed hooks are logged** but won't affect VPN functionality
- **Use absolute paths** for executables for reliability
- **Test your hooks** before relying on them for critical operations

## Troubleshooting

- Check the application logs if hooks aren't executing
- Ensure executable files have proper permissions
- Verify file paths are correct and absolute
- Test hooks manually before setting them up
- Use the provided test scripts to verify functionality
Loading