-
Notifications
You must be signed in to change notification settings - Fork 4
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
Ability to connect database multiple window #19
base: master
Are you sure you want to change the base?
Changes from 8 commits
de93555
f3ca7c8
39fc873
38dfba0
2340b28
89ca407
cf67e8f
3933425
5ca0d4d
9d88700
d22d5d6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export const STUDIO_ENDPOINT = "https://studio.outerbase.com/embed"; | ||
// const STUDIO_ENDPOINT = "http://localhost:3008/embed"; | ||
|
||
export const OUTERBASE_WEBSITE = "https://outerbase.com"; | ||
export const OUTERBASE_GITHUB = | ||
"https://github.com/outerbase/studio-desktop/issues"; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,175 @@ | ||
import { ConnectionStoreItem } from "@/lib/conn-manager-store"; | ||
import { app, Menu, MenuItemConstructorOptions, shell } from "electron"; | ||
import { isMac } from "../utils"; | ||
import { createDatabaseWindow, windowMap } from "../window/create-database"; | ||
import { OuterbaseApplication } from "../type"; | ||
import { createWindow } from "../main"; | ||
import { createConnectionWindow } from "../window/create-connection-window"; | ||
import { OUTERBASE_GITHUB, OUTERBASE_WEBSITE } from "../constants"; | ||
|
||
export function createMenu( | ||
win: OuterbaseApplication["win"], | ||
connections: ConnectionStoreItem[], | ||
) { | ||
function handleClick() { | ||
createWindow(); | ||
} | ||
|
||
function onOpenConnectionWindow(type: ConnectionStoreItem["type"]) { | ||
createConnectionWindow(win, type); | ||
win?.hide(); | ||
} | ||
|
||
function generateSubMenu() { | ||
const connMenu: MenuItemConstructorOptions["submenu"] = connections.map( | ||
(conn) => { | ||
return { | ||
label: conn.name, | ||
click: () => { | ||
const existingWindow = windowMap.get(conn.id); | ||
if (existingWindow && !existingWindow.isDestroyed()) { | ||
existingWindow.focus(); | ||
} else { | ||
createDatabaseWindow({ win, conn }); | ||
win?.hide(); | ||
} | ||
}, | ||
}; | ||
}, | ||
); | ||
|
||
return connMenu; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Make sure you slice the connection let say last 10, if there is more than 10, you can put "See more connections" |
||
|
||
const connSubMenu = generateSubMenu(); | ||
|
||
const customTemplate = [ | ||
...(isMac | ||
? [ | ||
{ | ||
label: app.name, | ||
submenu: [ | ||
{ role: "about" }, | ||
{ type: "separator" }, | ||
{ role: "services" }, | ||
{ type: "separator" }, | ||
{ role: "hide" }, | ||
{ role: "hideOthers" }, | ||
{ role: "unhide" }, | ||
{ type: "separator" }, | ||
{ role: "quit" }, | ||
], | ||
}, | ||
] | ||
: []), | ||
{ | ||
label: "File", | ||
submenu: [ | ||
{ | ||
label: "New Connection", | ||
submenu: [ | ||
{ | ||
label: "MySQL", | ||
click: () => onOpenConnectionWindow("mysql"), | ||
}, | ||
{ | ||
label: "PostgreSQL", | ||
click: () => onOpenConnectionWindow("postgres"), | ||
}, | ||
{ | ||
label: "SQLite", | ||
click: () => onOpenConnectionWindow("sqlite"), | ||
}, | ||
{ | ||
label: "Turso", | ||
click: () => onOpenConnectionWindow("turso"), | ||
}, | ||
{ | ||
label: "Cloudflare", | ||
click: () => onOpenConnectionWindow("cloudflare"), | ||
}, | ||
{ | ||
label: "Starbase", | ||
click: () => onOpenConnectionWindow("starbase"), | ||
}, | ||
], | ||
}, | ||
{ | ||
label: "New Window", | ||
click: handleClick, | ||
}, | ||
{ | ||
type: "separator", | ||
}, | ||
{ | ||
label: "Open Recent", | ||
enabled: connSubMenu.length > 0, | ||
submenu: connSubMenu, | ||
click: handleClick, | ||
}, | ||
{ | ||
type: "separator", | ||
}, | ||
{ role: "close" }, | ||
...(isMac ? [] : [{ label: "Exit", role: "quit" }]), | ||
], | ||
}, | ||
{ | ||
label: "Edit", | ||
submenu: [ | ||
{ role: "undo" }, | ||
{ role: "redo" }, | ||
{ type: "separator" }, | ||
{ role: "cut" }, | ||
{ role: "copy" }, | ||
{ role: "paste" }, | ||
{ role: "delete" }, | ||
{ role: "selectAll" }, | ||
], | ||
}, | ||
{ | ||
label: "View", | ||
submenu: [ | ||
{ role: "reload" }, | ||
{ role: "forceReload" }, | ||
{ role: "toggleDevTools" }, | ||
{ type: "separator" }, | ||
{ role: "resetZoom" }, | ||
{ role: "zoomIn" }, | ||
{ role: "zoomOut" }, | ||
{ type: "separator" }, | ||
{ role: "togglefullscreen" }, | ||
], | ||
}, | ||
{ | ||
label: "Window", | ||
submenu: [ | ||
{ role: "minimize" }, | ||
{ role: "zoom" }, | ||
...(isMac | ||
? [{ type: "separator" }, { role: "front" }] | ||
: [{ role: "close" }]), | ||
], | ||
}, | ||
{ | ||
label: "Help", | ||
submenu: [ | ||
{ | ||
label: "About Us", | ||
click: async () => { | ||
await shell.openExternal(OUTERBASE_WEBSITE); | ||
}, | ||
}, | ||
{ | ||
label: "Report issues", | ||
click: async () => { | ||
await shell.openExternal(OUTERBASE_GITHUB); | ||
}, | ||
}, | ||
], | ||
}, | ||
] as MenuItemConstructorOptions[]; | ||
|
||
const menu = Menu.buildFromTemplate(customTemplate); | ||
Menu.setApplicationMenu(menu); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import path from "node:path"; | ||
import { fileURLToPath } from "node:url"; | ||
|
||
const isMac = process.platform === "darwin"; | ||
const isWindow = process.platform === "win32"; | ||
const isLinux = process.platform === "linux"; | ||
|
||
function getOuterbaseDir() { | ||
return path.dirname(fileURLToPath(import.meta.url)); | ||
} | ||
|
||
const isDev = process.env.NODE_ENV === "development"; | ||
|
||
/** | ||
* | ||
* @param connId connection id string (optional) | ||
* @returns window configuration object | ||
*/ | ||
function getWindowConfig(connId?: string) { | ||
return { | ||
icon: path.join(process.env.VITE_PUBLIC, "electron-vite.svg"), | ||
show: false, | ||
width: 1024, | ||
height: 768, | ||
autoHideMenuBar: true, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
If it is true, Windows will never have menu |
||
webPreferences: { | ||
devTools: true, | ||
additionalArguments: ["--database=" + connId], | ||
preload: path.join(getOuterbaseDir(), "preload.mjs"), | ||
}, | ||
}; | ||
} | ||
|
||
export { isMac, isLinux, isWindow, isDev, getWindowConfig, getOuterbaseDir }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We want to maintain only one main windows. We can have multiple database windows, but should only have one main window