Skip to content

Commit

Permalink
Merge pull request #1824 from beekeeper-studio/wayland-native
Browse files Browse the repository at this point in the history
Wayland native support for Beekeeper Studio!
  • Loading branch information
rathboma committed Dec 15, 2023
2 parents 837ea23 + 698cb01 commit 492458a
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 17 deletions.
18 changes: 15 additions & 3 deletions apps/studio/build/launcher-script.sh
Expand Up @@ -12,13 +12,25 @@ while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symli
done
SCRIPT_DIR="$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )"


# taken from the VSCode implementation
# https://aur.archlinux.org/cgit/aur.git/commit/?h=visual-studio-code-bin&id=a0595836467bb205fcabb7e6d44ad7da82b29ed2
XDG_CONFIG_HOME=${XDG_CONFIG_HOME:-~/.config}

# Allow users to override command-line options
if [[ -f $XDG_CONFIG_HOME/bks-flags.conf ]]; then
echo "launcher-script: found bks-flags.conf"
USER_FLAGS="$(cat $XDG_CONFIG_HOME/bks-flags.conf)"
fi


if [ ! -f "$CLONE" ]; then
exec "$SCRIPT_DIR/beekeeper-studio-bin" "$@"
exec "$SCRIPT_DIR/beekeeper-studio-bin" $USER_FLAGS "$@"
else
UNPRIVILEGED_USERNS_ENABLED=$(cat "$CLONE" 2>/dev/null)
if [[ $UNPRIVILEGED_USERNS_ENABLED == 0 ]]; then
exec "$SCRIPT_DIR/beekeeper-studio-bin" "--no-sandbox" "$@"
exec "$SCRIPT_DIR/beekeeper-studio-bin" "--no-sandbox" $USER_FLAGS "$@"
else
exec "$SCRIPT_DIR/beekeeper-studio-bin" "$@"
exec "$SCRIPT_DIR/beekeeper-studio-bin" $USER_FLAGS "$@"
fi
fi
2 changes: 1 addition & 1 deletion apps/studio/package.json
Expand Up @@ -16,7 +16,7 @@
"docs:build": "vuepress build docs",
"docs:serve": "vuepress dev docs",
"electron:build": "vue-cli-service electron:build",
"electron:serve": "vue-cli-service electron:serve --host localhost",
"electron:serve": "vue-cli-service electron:serve --host localhost --ozone-platform-hint=auto",
"postinstall": "electron-builder install-app-deps",
"postuninstall": "electron-builder install-app-deps"
},
Expand Down
8 changes: 5 additions & 3 deletions apps/studio/src/App.vue
@@ -1,7 +1,7 @@
<template>
<div class="style-wrapper">
<div class="beekeeper-studio-wrapper">
<titlebar v-if="$config.isMac || menuStyle === 'client'" />
<titlebar v-if="$config.isMac || menuStyle === 'client' || (runningWayland)" />
<template v-if="storeInitialized">
<connection-interface v-if="!connection" />
<core-interface
Expand Down Expand Up @@ -51,7 +51,8 @@ export default Vue.extend({
},
data() {
return {
url: null
url: null,
runningWayland: false
}
},
computed: {
Expand All @@ -73,9 +74,10 @@ export default Vue.extend({
async mounted() {
await this.$store.dispatch('fetchUsername')
const query = querystring.parse(global.location.search)
const query = querystring.parse(global.location.search, { parseBooleans: true })
if (query) {
this.url = query.url || null
this.runningWayland = !!query.runningWayland
}
Expand Down
30 changes: 24 additions & 6 deletions apps/studio/src/background.ts
Expand Up @@ -77,6 +77,16 @@ async function initBasics() {
return settings
}

// so we need to check that the DM is running in wayland
// and we need to check that wayland has been enabled
// why? Because we have to force the usage of the client titlebar
function isWaylandMode() {
const slice = platformInfo.isDevelopment ? 2 : 1
const parsedArgs = yargs(process.argv.slice(slice))
return parsedArgs['ozone-platform-hint'] &&
platformInfo.isWayland && platformInfo.isLinux
}


// Quit when all windows are closed.
app.on('window-all-closed', () => {
Expand All @@ -92,7 +102,8 @@ app.on('activate', async (_event, hasVisibleWindows) => {
// dock icon is clicked and there are no other windows open.
if (!hasVisibleWindows) {
if (!settings) throw "No settings initialized!"
buildWindow(settings)
const runningWayland = isWaylandMode()
buildWindow(settings, { runningWayland })
}
})

Expand All @@ -117,8 +128,12 @@ app.on('ready', async () => {
}
const slice = platformInfo.isDevelopment ? 2 : 1
const parsedArgs = yargs(process.argv.slice(slice))

log.debug("Parsing app args", parsedArgs)
const options = parsedArgs._.map((url: string) => ({ url }))
const runningWayland = isWaylandMode()

// this gets positional arguments
const options = parsedArgs._.map((url: string) => ({ url, runningWayland }))
const settings = await initBasics()

if (options.length > 0) {
Expand All @@ -127,7 +142,8 @@ app.on('ready', async () => {
} else {
if (getActiveWindows().length === 0) {
const settings = await initBasics()
await buildWindow(settings)
const runningWayland = isWaylandMode()
await buildWindow(settings, { runningWayland })
}
}
})
Expand All @@ -136,15 +152,17 @@ app.on('ready', async () => {
app.on('open-file', async (event, file) => {
event.preventDefault();
const settings = await initBasics()

await buildWindow(settings, { url: file })
const runningWayland = isWaylandMode()
await buildWindow(settings, { url: file, runningWayland })
});

// Open a connection from a url (e.g. postgres://host)
app.on('open-url', async (event, url) => {
event.preventDefault();
const settings = await initBasics()
await buildWindow(settings, { url })
const runningWayland = isWaylandMode()

await buildWindow(settings, { url, runningWayland })
});

// Exit cleanly on request from parent process in development mode.
Expand Down
15 changes: 11 additions & 4 deletions apps/studio/src/background/WindowBuilder.ts
Expand Up @@ -18,6 +18,7 @@ const windows: BeekeeperWindow[] = []

export interface OpenOptions {
url?: string
runningWayland: boolean
}

function getIcon() {
Expand All @@ -28,11 +29,17 @@ class BeekeeperWindow {
private win: BrowserWindow | null
private reloaded = false

constructor(settings: IGroupedUserSettings, openOptions?: OpenOptions) {
constructor(settings: IGroupedUserSettings, openOptions: OpenOptions) {
const theme = settings.theme
const dark = electron.nativeTheme.shouldUseDarkColors || theme.value.toString().includes('dark')
const showFrame = settings.menuStyle && settings.menuStyle.value == 'native' ? true : false
const titleBarStyle = platformInfo.isWindows && settings.menuStyle.value == 'native' ? 'default' : 'hidden'
let showFrame = settings.menuStyle && settings.menuStyle.value == 'native' ? true : false
let titleBarStyle: 'default' | 'hidden' = platformInfo.isWindows && settings.menuStyle.value == 'native' ? 'default' : 'hidden'

if (openOptions.runningWayland) {
showFrame = false
titleBarStyle = 'hidden'
}

log.info('constructing the window')
this.win = new BrowserWindow({
width: 1200,
Expand Down Expand Up @@ -127,6 +134,6 @@ export function getActiveWindows(): BeekeeperWindow[] {
return _.filter(windows, 'active')
}

export function buildWindow(settings: IGroupedUserSettings, options?: OpenOptions): void {
export function buildWindow(settings: IGroupedUserSettings, options: OpenOptions): void {
windows.push(new BeekeeperWindow(settings, options))
}
1 change: 1 addition & 0 deletions apps/studio/src/common/platform_info.ts
Expand Up @@ -43,6 +43,7 @@ if (p.env.PORTABLE_EXECUTABLE_DIR) {
const platformInfo = {
isWindows, isMac,
isLinux: !isWindows && !isMac,
isWayland: p.env.XDG_SESSION_TYPE === 'wayland',
isSnap: p.env.ELECTRON_SNAP,
isPortable: isWindows && p.env.PORTABLE_EXECUTABLE_DIR,
isDevelopment: isDevEnv,
Expand Down

0 comments on commit 492458a

Please sign in to comment.