antares/src/renderer/components/TheTitleBar.vue

188 lines
4.8 KiB
Vue
Raw Normal View History

2020-06-02 19:13:57 +02:00
<template>
2022-06-08 13:04:19 +02:00
<div id="titlebar" v-if="!isLinux" @dblclick="toggleFullScreen">
2020-06-02 19:13:57 +02:00
<div class="titlebar-resizer" />
<div class="titlebar-elements">
<img
v-if="!isMacOS"
class="titlebar-logo"
src="@/images/logo.svg"
>
2020-06-02 19:13:57 +02:00
</div>
<div class="titlebar-elements titlebar-title">
2020-08-05 13:53:30 +02:00
{{ windowTitle }}
2020-06-02 19:13:57 +02:00
</div>
<div class="titlebar-elements">
<div
v-if="isDevelopment"
class="titlebar-element"
@click="openDevTools"
>
<i class="mdi mdi-24px mdi-code-tags" />
2020-06-02 19:13:57 +02:00
</div>
<div
v-if="isDevelopment"
class="titlebar-element"
@click="reload"
>
<i class="mdi mdi-24px mdi-refresh" />
2020-06-02 19:13:57 +02:00
</div>
2022-06-07 18:32:37 +02:00
<div v-if="isWindows" style="width: 140px;" />
2022-06-08 13:04:19 +02:00
<!-- <div
2022-06-07 18:32:37 +02:00
v-if="isLinux"
class="titlebar-element"
@click="minimizeApp"
>
<i class="mdi mdi-24px mdi-minus" />
2020-06-02 19:13:57 +02:00
</div>
<div
2022-06-07 18:32:37 +02:00
v-if="isLinux"
class="titlebar-element"
@click="toggleFullScreen"
>
<i v-if="isMaximized" class="mdi mdi-24px mdi-fullscreen-exit" />
<i v-else class="mdi mdi-24px mdi-fullscreen" />
2020-06-02 19:13:57 +02:00
</div>
<div
2022-06-07 18:32:37 +02:00
v-if="isLinux"
class="titlebar-element close-button"
@click="closeApp"
>
<i class="mdi mdi-24px mdi-close" />
2022-06-08 13:04:19 +02:00
</div> -->
2020-06-02 19:13:57 +02:00
</div>
</div>
</template>
<script>
import { ipcRenderer } from 'electron';
import { getCurrentWindow } from '@electron/remote';
2022-04-30 00:47:37 +02:00
import { useConnectionsStore } from '@/stores/connections';
import { useWorkspacesStore } from '@/stores/workspaces';
import { storeToRefs } from 'pinia';
2020-06-02 19:13:57 +02:00
export default {
name: 'TheTitleBar',
2022-04-30 00:47:37 +02:00
setup () {
const { getConnectionName } = useConnectionsStore();
const workspacesStore = useWorkspacesStore();
const { getSelected: selectedWorkspace } = storeToRefs(workspacesStore);
const { getWorkspace } = workspacesStore;
return {
getConnectionName,
selectedWorkspace,
getWorkspace
};
},
2020-06-02 19:13:57 +02:00
data () {
return {
w: getCurrentWindow(),
isMaximized: getCurrentWindow().isMaximized(),
isDevelopment: process.env.NODE_ENV === 'development',
2022-06-07 18:32:37 +02:00
isMacOS: process.platform === 'darwin',
isWindows: process.platform === 'win32',
isLinux: process.platform === 'linux'
2020-06-02 19:13:57 +02:00
};
},
2020-08-05 13:53:30 +02:00
computed: {
windowTitle () {
if (!this.selectedWorkspace) return '';
2021-07-08 17:43:33 +02:00
if (this.selectedWorkspace === 'NEW') return this.$t('message.createNewConnection');
2020-08-05 13:53:30 +02:00
const connectionName = this.getConnectionName(this.selectedWorkspace);
const workspace = this.getWorkspace(this.selectedWorkspace);
const breadcrumbs = Object.values(workspace.breadcrumbs).filter(breadcrumb => breadcrumb) || [workspace.client];
2020-08-05 13:53:30 +02:00
return [connectionName, ...breadcrumbs].join(' • ');
}
},
2020-06-02 19:13:57 +02:00
created () {
window.addEventListener('resize', this.onResize);
},
2022-04-21 14:39:24 +02:00
unmounted () {
2020-06-02 19:13:57 +02:00
window.removeEventListener('resize', this.onResize);
},
methods: {
closeApp () {
ipcRenderer.send('close-app');
2020-06-02 19:13:57 +02:00
},
minimizeApp () {
this.w.minimize();
},
toggleFullScreen () {
if (this.isMaximized)
this.w.unmaximize();
else
this.w.maximize();
},
openDevTools () {
this.w.openDevTools();
},
reload () {
this.w.reload();
},
onResize () {
this.isMaximized = this.w.isMaximized();
}
}
};
</script>
<style lang="scss">
2020-07-31 18:16:28 +02:00
#titlebar {
display: flex;
position: relative;
justify-content: space-between;
align-items: center;
height: $titlebar-height;
-webkit-app-region: drag;
user-select: none;
z-index: 9999;
.titlebar-resizer {
position: absolute;
top: 0;
width: 100%;
height: 4px;
z-index: 999;
-webkit-app-region: no-drag;
}
.titlebar-elements {
2020-06-02 19:13:57 +02:00
display: flex;
align-items: center;
&.titlebar-title {
position: absolute;
left: 0;
right: 0;
text-align: center;
display: block;
pointer-events: none;
}
2020-07-31 18:16:28 +02:00
.titlebar-logo {
height: $titlebar-height;
2021-04-30 14:14:01 +02:00
padding: 0.3rem 0.4rem;
2020-06-02 19:13:57 +02:00
}
2020-07-31 18:16:28 +02:00
.titlebar-element {
display: flex;
align-items: center;
height: $titlebar-height;
line-height: 0;
padding: 0 0.7rem;
2022-06-07 18:32:37 +02:00
opacity: 0.9;
2020-07-31 18:16:28 +02:00
transition: opacity 0.2s;
-webkit-app-region: no-drag;
2020-06-02 19:13:57 +02:00
2020-07-31 18:16:28 +02:00
&:hover {
opacity: 1;
}
2020-06-02 19:13:57 +02:00
}
2020-07-31 18:16:28 +02:00
}
}
2020-06-02 19:13:57 +02:00
</style>