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

v2 [#3133] SingleInstanceData: Fill missing WD as is #3154

Merged
merged 5 commits into from
Jan 3, 2024
Merged

v2 [#3133] SingleInstanceData: Fill missing WD as is #3154

merged 5 commits into from
Jan 3, 2024

Conversation

Vovan-VE
Copy link
Contributor

@Vovan-VE Vovan-VE commented Dec 23, 2023

Description

Minimal fix for missing WorkingDirectory for linux and windows.

Fixes #3133

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

Tested locally in my wails app by replacing wails repo to local forked repo. Worked fine under linux and windows. Darwin was not changed and I cannot test it.

go.mod

replace github.com/wailsapp/wails/v2 => ../wails/v2

app.go

func (a *App) secondInstance(data options.SecondInstanceData) {
	runtime.LogInfof(a.ctx, "%#v", data)
}

linux

[/abs/path]$ ./app ../../path/file.txt ../foo/bar.txt

first instance output

INF | options.SecondInstanceData{Args:[]string{"../../path/file.txt", "../foo/bar.txt"}, WorkingDirectory:"/abs/path"}

windows

C:\abs\path> app.exe ..\..\path\file.txt ..\foo\bar.txt

first instance output

INF | options.SecondInstanceData{Args:[]string{"..\\..\\path\\file.txt", "..\\foo\\bar.txt"}, WorkingDirectory:"C:\\abs\\path"}
  • Windows
  • Linux

Test Configuration

Still same as in #3133

Checklist:

  • I have updated website/src/pages/changelog.mdx with details of this PR
  • My code follows the general coding style of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Summary by CodeRabbit

  • Bug Fixes
    • Fixed uninitialized SecondInstanceData.WorkingDirectory on Linux and Windows.

Copy link
Contributor

coderabbitai bot commented Dec 23, 2023

Walkthrough

The recent update involves enhancing the SetupSingleInstance function across both Linux and Windows platforms to ensure that the WorkingDirectory is properly initialized within the SecondInstanceData structure. This change is crucial for maintaining consistency across instances, particularly in handling the working directory path.

Changes

File Path Change Summary
v2/internal/frontend/desktop/linux/single_instance.go
v2/internal/frontend/desktop/windows/single_instance.go
Modified SetupSingleInstance to retrieve the working directory, included error handling for working directory retrieval and data marshaling, and incorporated the current working directory into the SecondInstanceData struct before marshaling and sending the data.

Assessment against linked issues

Objective Addressed Explanation
Address the issue where SecondInstanceData.WorkingDirectory is always empty on Linux when using SingleInstanceLock. (#3133)
Ensure that when running the application with a second instance, the WorkingDirectory in options.SecondInstanceData is correctly populated with the absolute path. (#3133)
Investigate and resolve the discrepancy between the expected behavior (/abs/path) and the actual behavior ("") of WorkingDirectory in the options.SecondInstanceData structure on Linux. (#3133)
Verify the fix across different Linux distributions and versions, considering potential variations in file system handling. (#3133)

Poem

In the realm of code, where rabbits hop,
A single instance, now on top.
Directories set, both far and near,
🐇 CodeRabbit's work, now crystal clear.

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share

Tips

Chat with CodeRabbit Bot (@coderabbitai)

  • You can directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit-tests for this file.
  • You can tag CodeRabbit on specific lines of code or entire files in the PR by tagging @coderabbitai in a comment. Examples:
    • @coderabbitai generate unit tests for this file.
    • @coderabbitai modularize this function.
  • You can tag @coderabbitai in a PR comment and ask questions about the PR and the codebase. Examples:
    • @coderabbitai generate interesting stats about this repository from git and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid.
    • @coderabbitai read the files in the src/scheduler package and generate README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

@Vovan-VE
Copy link
Contributor Author

@APshenkin

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 4

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 3c7a218 and 1f6183d.
Files selected for processing (2)
  • v2/internal/frontend/desktop/linux/single_instance.go (1 hunks)
  • v2/internal/frontend/desktop/windows/single_instance.go (1 hunks)
Additional comments: 2
v2/internal/frontend/desktop/linux/single_instance.go (1)
  • 55-65: Verify if os.Exit(1) is the intended behavior after sending the message to the existing instance. Ensure that any necessary cleanup is performed before exiting.
v2/internal/frontend/desktop/windows/single_instance.go (1)
  • 51-57: Verify if os.Exit(0) is the intended behavior after sending the message to the existing instance. Ensure that any necessary cleanup is performed before exiting.

v2/internal/frontend/desktop/linux/single_instance.go Outdated Show resolved Hide resolved
v2/internal/frontend/desktop/linux/single_instance.go Outdated Show resolved Hide resolved
v2/internal/frontend/desktop/windows/single_instance.go Outdated Show resolved Hide resolved
v2/internal/frontend/desktop/windows/single_instance.go Outdated Show resolved Hide resolved
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
@leaanthony
Copy link
Member

Thanks 🙏 Please could you add an entry to the changelog located at website/src/pages/changelog.mdx?

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 2

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 1f6183d and eda17f9.
Files selected for processing (2)
  • v2/internal/frontend/desktop/linux/single_instance.go (1 hunks)
  • v2/internal/frontend/desktop/windows/single_instance.go (1 hunks)
Additional comments: 6
v2/internal/frontend/desktop/linux/single_instance.go (3)
  • 58-62: The use of os.Getwd() to set the working directory is correct, but ensure that the working directory is always the intended value in all use cases, as it can vary depending on how the application is launched.

  • 66-66: Error logging for marshaling data is correctly implemented. Ensure that the log output is monitored and that these logs are stored securely, as they may contain sensitive information.

  • 69-69: The use of os.Exit(1) is appropriate for terminating the second instance of the application. However, ensure that this behavior is documented and expected by the application's users, as it can be abrupt.

v2/internal/frontend/desktop/windows/single_instance.go (3)
  • 54-58: The use of os.Getwd() to set the working directory is correct, but ensure that the working directory is always the intended value in all use cases, as it can vary depending on how the application is launched.

  • 60-62: Error logging for marshaling data is correctly implemented. Ensure that the log output is monitored and that these logs are stored securely, as they may contain sensitive information.

  • 65-65: The use of os.Exit(0) is appropriate for terminating the second instance of the application. However, ensure that this behavior is documented and expected by the application's users, as it can be abrupt.

Comment on lines +59 to +61
if err != nil {
log.Printf("Failed to get working directory: %v", err)
return
Copy link
Contributor

Choose a reason for hiding this comment

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

Proper error handling is implemented for the os.Getwd() call. However, consider if returning early is the best approach, as it may prevent further necessary cleanup or logic that should execute regardless of this error.

Comment on lines 55 to 57
if err != nil {
log.Printf("Failed to get working directory: %v", err)
return
Copy link
Contributor

Choose a reason for hiding this comment

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

Proper error handling is implemented for the os.Getwd() call. However, consider if returning early is the best approach, as it may prevent further necessary cleanup or logic that should execute regardless of this error.

@leaanthony leaanthony added the awaiting feedback More information is required from the requestor label Jan 3, 2024
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between eda17f9 and 085cb63.
Files selected for processing (3)
  • v2/internal/frontend/desktop/linux/single_instance.go (2 hunks)
  • v2/internal/frontend/desktop/windows/single_instance.go (2 hunks)
  • website/src/pages/changelog.mdx (1 hunks)
Files skipped from review as they are similar to previous changes (2)
  • v2/internal/frontend/desktop/linux/single_instance.go
  • v2/internal/frontend/desktop/windows/single_instance.go
Additional comments: 1
website/src/pages/changelog.mdx (1)
  • 27-27: The changelog entry for PR v2 [#3133] SingleInstanceData: Fill missing WD as is #3154 is clear and accurately describes the fix implemented for the uninitialized SecondInstanceData.WorkingDirectory on Linux and Windows platforms. It succinctly captures the essence of the changes made and the platforms affected.

@Vovan-VE
Copy link
Contributor Author

Vovan-VE commented Jan 3, 2024

I skipped that err checks just in the same style as the local code style there.

Copy link
Member

@leaanthony leaanthony left a comment

Choose a reason for hiding this comment

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

Thanks so much for this 🙏

@APshenkin
Copy link
Contributor

@Vovan-VE sorry, that didn't looked at this earlier, holidays knocked me away from the laptop 😅

Thank you for fixing this!

@leaanthony leaanthony merged commit f7c1946 into wailsapp:master Jan 3, 2024
10 checks passed
@Vovan-VE Vovan-VE deleted the fix/3133-variant-1 branch January 3, 2024 18:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting feedback More information is required from the requestor
Projects
None yet
Development

Successfully merging this pull request may close these issues.

v2 linux: SecondInstanceData.WorkingDirectory not initialized
3 participants