-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAppTitlebar.vue
More file actions
349 lines (328 loc) · 10.4 KB
/
AppTitlebar.vue
File metadata and controls
349 lines (328 loc) · 10.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
<template>
<div
:class="[`text-white/90 w-full z-[60]`]"
:style="calculateViaGradient"
>
<div class="flex items-center justify-between px-8 py-2 gap-5">
<OnClickOutside
class="flex items-center gap-2"
@trigger="showSecondLevelMenu = false"
>
<button
type="button"
class="flex justify-center items-center hover:bg-white/10 w-8 h-8 rounded"
@click="showSecondLevelMenu = !showSecondLevelMenu"
>
<i class="fas fa-fw fa-bars" />
</button>
<div
v-if="showSecondLevelMenu"
class="max-lg:absolute max-lg:w-40 max-lg:top-14 max-lg:left-2 max-lg:rounded max-lg:bg-zinc-800 max-lg:shadow-xl max-lg:text-white/90 max-lg:ring-1 max-lg:ring-zinc-700 max-lg:z-[300]"
>
<div class="flex max-lg:flex-col flex-row lg:gap-2 max-lg:bg-white/[0.03] max-lg:p-2">
<template
v-for="secondLevelMenu in secondLevelMenus"
:key="secondLevelMenu.label"
>
<div>
<AppTitlebarDropdown
:menu-items="secondLevelMenu.menuItems"
@select="(e) => e.click()"
>
{{ secondLevelMenu.label }}
</AppTitlebarDropdown>
</div>
</template>
<div class="lg:hidden">
<AppTitlebarDropdown
v-if="store.connected"
:menu-items="sceneCollectionMenuItems"
:selected="store.sceneCollectionList.currentSceneCollectionName"
@select="setActiveSceneCollection"
>
{{ store.sceneCollectionList.currentSceneCollectionName }}
</AppTitlebarDropdown>
</div>
<div class="lg:hidden">
<AppTitlebarDropdown
v-if="store.connected"
:menu-items="profileMenuItems"
:selected="store.profileList.currentProfileName"
@select="setActiveProfile"
>
{{ store.profileList.currentProfileName }}
</AppTitlebarDropdown>
</div>
</div>
</div>
<template v-else>
<AppTitlebarDropdown
:letter="activeConnection.letter"
:menu-items="menuItems"
@select="setActiveConnection"
>
{{ activeConnection.label }}
</AppTitlebarDropdown>
<AppTitlebarDropdown
v-if="store.connected"
class="max-lg:hidden"
:icon="{name: 'user'}"
:menu-items="profileMenuItems"
:selected="store.profileList.currentProfileName"
@select="setActiveProfile"
>
{{ store.profileList.currentProfileName }}
</AppTitlebarDropdown>
<AppTitlebarDropdown
v-if="store.connected"
class="max-lg:hidden"
:icon="{name: 'rectangle-history'}"
:menu-items="sceneCollectionMenuItems"
:selected="store.sceneCollectionList.currentSceneCollectionName"
@select="setActiveSceneCollection"
>
{{ store.sceneCollectionList.currentSceneCollectionName }}
</AppTitlebarDropdown>
</template>
</OnClickOutside>
<div class="flex items-center gap-6 -mr-6">
<AppControls v-if="store.connected" />
<AppElectronControls />
</div>
</div>
</div>
</template>
<script setup lang="ts">
import { OnClickOutside } from '@vueuse/components'
import AppTitlebarDropdown, { MenuItem } from '../atoms/AppTitlebarDropdown.vue'
import { computed, Ref, ref } from 'vue'
import { Connection, useAppStore } from '../../store/app'
import { useObs } from '../../composables/useObs'
import { useNotificationStore } from '../../store/notification'
import AppControls from '../atoms/AppControls.vue'
import { usePopupStore } from '../../store/popup'
import { useDocksStore } from '../../store/dock'
import { colorPalette } from '../../color-palette'
import AppElectronControls from '../molecules/AppElectronControls.vue'
import { useUserStore } from '../../store/user'
import { storeToRefs } from 'pinia'
import LoginPopup from '../popups/LoginPopup.vue'
import ConnectPopup from '../popups/ConnectPopup.vue'
const store = useAppStore()
const docks = useDocksStore()
const { error } = useNotificationStore()
const { openPopup } = usePopupStore()
const { obs } = useObs()
const userStore = useUserStore()
const { user } = storeToRefs(userStore)
const showSecondLevelMenu = ref(false)
const secondLevelMenus = computed(() => {
return [
{
label: 'Account',
menuItems: [
{
id: 0,
label: 'Sign in',
icon: { name: 'sign-in' },
click: () => openPopup(LoginPopup)
},
{
id: 1,
label: 'Sign out',
icon: { name: 'sign-out' },
click: () => userStore.logout()
}
]
},
{
label: 'View',
menuItems: [
{
id: 0,
label: 'Studio Mode',
icon: store.studioMode ? { name: 'check' } : { name: 'empty' },
click: () => store.toggleStudioMode()
},
{
id: 10,
label: 'Image Quality: Low Bandwidth',
icon: store.screenshot.imageCompressionQuality === 10 ? { name: 'check' } : { name: 'empty' },
click: () => store.setImageCompressionQuality(10)
},
{
id: 40,
label: 'Image Quality: Medium Bandwidth',
icon: store.screenshot.imageCompressionQuality === 40 ? { name: 'check' } : { name: 'empty' },
click: () => store.setImageCompressionQuality(40)
},
{
id: 80,
label: 'Image Quality: High Bandwidth',
icon: store.screenshot.imageCompressionQuality === 80 ? { name: 'check' } : { name: 'empty' },
click: () => store.setImageCompressionQuality(80)
}
]
},
{
label: 'Docks',
menuItems: [
{
id: 0,
label: 'Scenes',
icon: docks.loadedComponentTypes.includes('Sources') ? { name: 'check' } : { name: 'empty' },
click: async () => await docks.addComponent('Sources', 'Sources')
},
{
id: 10,
label: 'Sources',
icon: docks.loadedComponentTypes.includes('Scenes') ? { name: 'check' } : { name: 'empty' },
click: async () => await docks.addComponent('Scenes', 'Scenes')
},
{
id: 40,
label: 'Studio View',
icon: docks.loadedComponentTypes.includes('StudioView') ? { name: 'check' } : { name: 'empty' },
click: async () => await docks.addComponent('StudioView', 'Studio View')
},
{
id: 80,
label: 'Audio Mixer',
icon: docks.loadedComponentTypes.includes('AudioMixer') ? { name: 'check' } : { name: 'empty' },
click: async () => await docks.addComponent('AudioMixer', 'Audio Mixer')
},
{
id: 80,
label: 'IRL Control',
icon: docks.loadedComponentTypes.includes('IrlControl') ? { name: 'check' } : { name: 'empty' },
click: async () => await docks.addComponent('IrlControl', 'IRL Control')
}
]
},
{
label: 'Help',
menuItems: [
{
id: 0,
label: 'About',
icon: { name: 'info-circle' }
},
{
id: 1,
label: 'Check for updates',
icon: { name: 'download' }
},
{
id: 2,
label: 'Report a bug',
icon: { name: 'bug' }
},
{
id: 3,
label: 'Join the Discord',
icon: { name: 'discord' }
},
{
id: 4,
label: 'Open the Wiki',
icon: { name: 'book' }
}
]
}
]
})
const menuItems: Ref<MenuItem[]> = computed(() => {
const items: MenuItem[] = [
{
id: 0,
label: 'Connect to a new server',
icon: { name: 'plus' }
}
]
user.value?.connections?.forEach((connection) => {
items.push({
id: connection.id,
label: connection.name,
subtitle: `ws://${connection.ip}:${connection.port}`,
letter: { text: connection.name[0], color: connection.color },
data: {
ip: connection.ip,
port: connection.port,
password: connection.password
}
})
})
return items
})
const calculateViaGradient = computed(() => {
const { r, g, b } = colorPalette[activeConnection.value.letter?.color ?? 'red']
return {
'background': `linear-gradient(90deg, #18181B 0px, rgba(${r}, ${g}, ${b}, .4) 95px, #18181B 300px)`,
'-webkit-app-region': 'drag'
}
})
const profileMenuItems = computed(() => {
return store.profileList.profiles.map((profile) => ({
id: profile,
label: profile,
icon: { name: 'user' }
}))
})
const sceneCollectionMenuItems = computed(() => {
return store.sceneCollectionList.sceneCollections.map((sceneCollection) => ({
id: sceneCollection,
label: sceneCollection,
icon: { name: 'rectangle-history' }
}))
})
const activeConnection = computed(() => {
return menuItems.value.find((item) => {
if (!item.data) return false
const connection = item.data as Connection
return connection.ip === store.connection.ip &&
connection.port === store.connection.port &&
connection.password === store.connection.password
}) ?? {
label: store.connection.ip,
subtitle: `ws://${store.connection.ip}:${store.connection.port}`,
letter: { text: store.connection.ip[0], color: 'rose' }
}
})
const setActiveConnection = async (item: MenuItem) => {
if (!item.data) {
switch (item.id) {
case 0:
openPopup(ConnectPopup)
break
default:
error({
type: 'error',
title: 'Action not implemented',
message: 'This action is not implemented yet'
})
break
}
return
}
try {
await store.connect(item.data as Connection)
} catch (e) {
error({
type: 'error',
title: 'Connection error',
message: 'Could not connect to the server'
})
console.error(e)
}
}
const setActiveProfile = (item: MenuItem) => {
obs.call('SetCurrentProfile', {
'profileName': item.id as string
})
}
const setActiveSceneCollection = (item: MenuItem) => {
obs.call('SetCurrentSceneCollection', {
'sceneCollectionName': item.id as string
})
}
</script>