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

implement ipc for file selection #79

Merged
merged 1 commit into from
Jan 6, 2025
Merged

implement ipc for file selection #79

merged 1 commit into from
Jan 6, 2025

Conversation

achou11
Copy link
Member

@achou11 achou11 commented Jan 6, 2025

Related to #55

Sets up the mechanisms for initiating the selection of a file in the filesystem from the renderer side and retrieving the full path to the selected file. Having this will enable features such as importing a project config file or custom map file.

This PR introduces the following:

  • IPC handler on the main window for summoning the open file dialog and returning the full path to the selected file (or undefined if no file is selected). Multi-file support was considered but we don't have an immediate need for it, so opted to refrain from including in this implementation.

  • new renderer-available "runtime" method selectFile(extensionFilters) which sends the relevant IPC and waits for the result.

  • mutation hook useSelectProjectConfigFile() which is unused in this PR, but will help feat: import config #55. Example usage could look like the following:

    onClick={() => {
        selectConfigFile.mutate(undefined, {
    	    onSuccess: (filePath) => {
    		    if (filePath) {
    			    // Do something with selected file...
    		    } else {
    			    // No file selected due to dialog cancellation
    		    }
    	    },
    	    onError: (error) => {
    		    // Handle error...
    	    },
        })
    }}

@achou11 achou11 requested a review from cimigree January 6, 2025 18:32
Copy link
Contributor

@cimigree cimigree left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great. Thanks for doing this. I tested in the electron console and it worked as expected.

@achou11 achou11 merged commit 453b421 into main Jan 6, 2025
4 checks passed
@achou11 achou11 deleted the ac/select-file-ipc branch January 6, 2025 19:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants