Skip to content

Conversation

@roth-dev
Copy link
Collaborator

No description provided.

@invisal
Copy link
Collaborator

invisal commented Dec 19, 2024

This does not truly solve the problem because we need win reference. When application close and createWindow again, we need a new win. The easiest fix is

https://github.com/outerbase/studio-desktop/blob/master/electron/main.ts#L57

Make the win inside the object and we can pass the object to dockerIpc.

const application: {
  win?: BrowserWindow
} = {
   win: undefined
}

Then we can do bindDockerIpc by passing application and can be done outside the createWindow

@roth-dev
Copy link
Collaborator Author

Got it

electron/main.ts Outdated
Comment on lines 57 to 61
const application: {
win?: BrowserWindow;
} = {
win: undefined,
};
Copy link
Collaborator

@invisal invisal Dec 19, 2024

Choose a reason for hiding this comment

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

You can create OuterbaseApplication type to be {win?: BrowserWindow | null} so that you can reuse it in the dockerIpc

if (handlersBound) return; // Prevent duplicate registrations
handlersBound = true;

export function bindDockerIpc({ win }: { win?: BrowserWindow }) {
Copy link
Collaborator

@invisal invisal Dec 19, 2024

Choose a reason for hiding this comment

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

Destructure this way will lose the reference. Imagine:

const ref = {
  count: 1
}

function bar({count}) {
  setInterval(() => console.log('Count is', count), 1000);
}

bar(ref);

// This will print count 1 every second

ref.count = 2;
// Now I update new value, but as you can see, it will still print 1 every second instead of print 2

@invisal invisal merged commit d7d91ce into outerbase:master Dec 19, 2024
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