enhance(frontend): deckをpreferences管理に

This commit is contained in:
syuilo 2025-03-11 11:14:55 +09:00
parent 1f2801af02
commit 1f345eb839
7 changed files with 231 additions and 215 deletions

View File

@ -6,9 +6,11 @@
import { createApp, defineAsyncComponent, markRaw } from 'vue'; import { createApp, defineAsyncComponent, markRaw } from 'vue';
import { ui } from '@@/js/config.js'; import { ui } from '@@/js/config.js';
import * as Misskey from 'misskey-js'; import * as Misskey from 'misskey-js';
import { v4 as uuid } from 'uuid';
import { common } from './common.js'; import { common } from './common.js';
import type { Component } from 'vue'; import type { Component } from 'vue';
import type { Keymap } from '@/utility/hotkey.js'; import type { Keymap } from '@/utility/hotkey.js';
import type { DeckProfile } from '@/deck.js';
import { i18n } from '@/i18n.js'; import { i18n } from '@/i18n.js';
import { alert, confirm, popup, post, toast } from '@/os.js'; import { alert, confirm, popup, post, toast } from '@/os.js';
import { useStream } from '@/stream.js'; import { useStream } from '@/stream.js';
@ -143,12 +145,34 @@ export async function mainBoot() {
if (themes.length > 0) { if (themes.length > 0) {
prefer.commit('themes', themes); prefer.commit('themes', themes);
} }
const plugins = ColdDeviceStorage.get('plugins'); const plugins = ColdDeviceStorage.get('plugins');
prefer.commit('plugins', plugins.map(p => ({ prefer.commit('plugins', plugins.map(p => ({
...p, ...p,
installId: (p as any).id, installId: (p as any).id,
id: undefined, id: undefined,
}))); })));
prefer.commit('deck.profile', deckStore.s.profile);
misskeyApi('i/registry/keys', {
scope: ['client', 'deck', 'profiles'],
}).then(async keys => {
const profiles: DeckProfile[] = [];
for (const key of keys) {
const deck = await misskeyApi('i/registry/get', {
scope: ['client', 'deck', 'profiles'],
key: key,
});
profiles.push({
id: uuid(),
name: key,
columns: deck.columns,
layout: deck.layout,
});
}
prefer.commit('deck.profiles', profiles);
});
prefer.commit('lightTheme', ColdDeviceStorage.get('lightTheme')); prefer.commit('lightTheme', ColdDeviceStorage.get('lightTheme'));
prefer.commit('darkTheme', ColdDeviceStorage.get('darkTheme')); prefer.commit('darkTheme', ColdDeviceStorage.get('darkTheme'));
prefer.commit('syncDeviceDarkMode', ColdDeviceStorage.get('syncDeviceDarkMode')); prefer.commit('syncDeviceDarkMode', ColdDeviceStorage.get('syncDeviceDarkMode'));
@ -223,9 +247,6 @@ export async function mainBoot() {
prefer.commit('sound.on.noteMy', store.s.sound_noteMy as any); prefer.commit('sound.on.noteMy', store.s.sound_noteMy as any);
prefer.commit('sound.on.notification', store.s.sound_notification as any); prefer.commit('sound.on.notification', store.s.sound_notification as any);
prefer.commit('sound.on.reaction', store.s.sound_reaction as any); prefer.commit('sound.on.reaction', store.s.sound_reaction as any);
store.set('deck.profile', deckStore.s.profile);
store.set('deck.columns', deckStore.s.columns);
store.set('deck.layout', deckStore.s.layout);
store.set('menu', []); store.set('menu', []);
} }

View File

@ -3,13 +3,23 @@
* SPDX-License-Identifier: AGPL-3.0-only * SPDX-License-Identifier: AGPL-3.0-only
*/ */
import { throttle } from 'throttle-debounce';
import { notificationTypes } from 'misskey-js'; import { notificationTypes } from 'misskey-js';
import { ref } from 'vue';
import { v4 as uuid } from 'uuid';
import { i18n } from './i18n.js';
import type { BasicTimelineType } from '@/timelines.js'; import type { BasicTimelineType } from '@/timelines.js';
import type { SoundStore } from '@/preferences/def.js'; import type { SoundStore } from '@/preferences/def.js';
import { misskeyApi } from '@/utility/misskey-api.js'; import type { MenuItem } from '@/types/menu.js';
import { deepClone } from '@/utility/clone.js'; import { deepClone } from '@/utility/clone.js';
import { store } from '@/store.js'; import { prefer } from '@/preferences.js';
import * as os from '@/os.js';
export type DeckProfile = {
name: string;
id: string;
columns: Column[];
layout: Column['id'][][];
};
type ColumnWidget = { type ColumnWidget = {
name: string; name: string;
@ -53,127 +63,132 @@ export type Column = {
soundSetting?: SoundStore; soundSetting?: SoundStore;
}; };
export const loadDeck = async () => { const _currentProfile = prefer.s['deck.profiles'].find(p => p.name === prefer.s['deck.profile']);
let deck; const __currentProfile = _currentProfile ? deepClone(_currentProfile) : null;
export const columns = ref(__currentProfile ? __currentProfile.columns : []);
export const layout = ref(__currentProfile ? __currentProfile.layout : []);
try { if (prefer.s['deck.profile'] == null) {
deck = await misskeyApi('i/registry/get', { addProfile('Main');
scope: ['client', 'deck', 'profiles'], }
key: store.s['deck.profile'],
});
} catch (err) {
if (typeof err === 'object' && err != null && 'code' in err && err.code === 'NO_SUCH_KEY') {
// 後方互換性のため
if (store.s['deck.profile'] === 'default') {
saveDeck();
return;
}
store.set('deck.columns', []); export function forceSaveCurrentDeckProfile() {
store.set('deck.layout', []); const currentProfile = prefer.s['deck.profiles'].find(p => p.name === prefer.s['deck.profile']);
return; if (currentProfile == null) return;
}
throw err;
}
store.set('deck.columns', deck.columns); const newProfile = deepClone(currentProfile);
store.set('deck.layout', deck.layout); newProfile.columns = columns.value;
newProfile.layout = layout.value;
const newProfiles = prefer.s['deck.profiles'].filter(p => p.name !== prefer.s['deck.profile']);
newProfiles.push(newProfile);
prefer.commit('deck.profiles', newProfiles);
}
export const saveCurrentDeckProfile = () => {
forceSaveCurrentDeckProfile();
}; };
export async function forceSaveDeck() { function switchProfile(profile: DeckProfile) {
await misskeyApi('i/registry/set', { prefer.commit('deck.profile', profile.name);
scope: ['client', 'deck', 'profiles'], const currentProfile = deepClone(profile);
key: store.s['deck.profile'], columns.value = currentProfile.columns;
value: { layout.value = currentProfile.layout;
columns: store.r['deck.columns'].value, forceSaveCurrentDeckProfile();
layout: store.r['deck.layout'].value,
},
});
} }
// TODO: deckがloadされていない状態でsaveすると意図せず上書きが発生するので対策する function addProfile(name: string) {
export const saveDeck = throttle(1000, () => { if (name.trim() === '') return;
forceSaveDeck(); if (prefer.s['deck.profiles'].find(p => p.name === name)) return;
});
export async function getProfiles(): Promise<string[]> { const newProfile: DeckProfile = {
return await misskeyApi('i/registry/keys', { id: uuid(),
scope: ['client', 'deck', 'profiles'], name,
}); columns: [],
layout: [],
};
prefer.commit('deck.profiles', [...prefer.s['deck.profiles'], newProfile]);
switchProfile(newProfile);
} }
export async function deleteProfile(key: string): Promise<void> { function createFirstProfile() {
return await misskeyApi('i/registry/remove', { addProfile('Main');
scope: ['client', 'deck', 'profiles'], }
key: key,
}); export function deleteProfile(name: string): void {
const newProfiles = prefer.s['deck.profiles'].filter(p => p.name !== name);
prefer.commit('deck.profiles', newProfiles);
if (prefer.s['deck.profiles'].length === 0) {
createFirstProfile();
} else {
switchProfile(prefer.s['deck.profiles'][0]);
}
} }
export function addColumn(column: Column) { export function addColumn(column: Column) {
if (column.name === undefined) column.name = null; if (column.name === undefined) column.name = null;
store.push('deck.columns', column); columns.value.push(column);
store.push('deck.layout', [column.id]); layout.value.push([column.id]);
saveDeck(); saveCurrentDeckProfile();
} }
export function removeColumn(id: Column['id']) { export function removeColumn(id: Column['id']) {
store.set('deck.columns', store.s['deck.columns'].filter(c => c.id !== id)); columns.value = columns.value.filter(c => c.id !== id);
store.set('deck.layout', store.s['deck.layout'] layout.value = layout.value.map(ids => ids.filter(_id => _id !== id)).filter(ids => ids.length > 0);
.map(ids => ids.filter(_id => _id !== id)) saveCurrentDeckProfile();
.filter(ids => ids.length > 0));
saveDeck();
} }
export function swapColumn(a: Column['id'], b: Column['id']) { export function swapColumn(a: Column['id'], b: Column['id']) {
const aX = store.s['deck.layout'].findIndex(ids => ids.indexOf(a) !== -1); const aX = layout.value.findIndex(ids => ids.indexOf(a) !== -1);
const aY = store.s['deck.layout'][aX].findIndex(id => id === a); const aY = layout.value[aX].findIndex(id => id === a);
const bX = store.s['deck.layout'].findIndex(ids => ids.indexOf(b) !== -1); const bX = layout.value.findIndex(ids => ids.indexOf(b) !== -1);
const bY = store.s['deck.layout'][bX].findIndex(id => id === b); const bY = layout.value[bX].findIndex(id => id === b);
const layout = deepClone(store.s['deck.layout']); const newLayout = deepClone(layout.value);
layout[aX][aY] = b; newLayout[aX][aY] = b;
layout[bX][bY] = a; newLayout[bX][bY] = a;
store.set('deck.layout', layout); layout.value = newLayout;
saveDeck(); saveCurrentDeckProfile();
} }
export function swapLeftColumn(id: Column['id']) { export function swapLeftColumn(id: Column['id']) {
const layout = deepClone(store.s['deck.layout']); const newLayout = deepClone(layout.value);
store.s['deck.layout'].some((ids, i) => { layout.value.some((ids, i) => {
if (ids.includes(id)) { if (ids.includes(id)) {
const left = store.s['deck.layout'][i - 1]; const left = layout.value[i - 1];
if (left) { if (left) {
layout[i - 1] = store.s['deck.layout'][i]; newLayout[i - 1] = layout.value[i];
layout[i] = left; newLayout[i] = left;
store.set('deck.layout', layout); layout.value = newLayout;
} }
return true; return true;
} }
return false; return false;
}); });
saveDeck(); saveCurrentDeckProfile();
} }
export function swapRightColumn(id: Column['id']) { export function swapRightColumn(id: Column['id']) {
const layout = deepClone(store.s['deck.layout']); const newLayout = deepClone(layout.value);
store.s['deck.layout'].some((ids, i) => { layout.value.some((ids, i) => {
if (ids.includes(id)) { if (ids.includes(id)) {
const right = store.s['deck.layout'][i + 1]; const right = layout.value[i + 1];
if (right) { if (right) {
layout[i + 1] = store.s['deck.layout'][i]; newLayout[i + 1] = layout.value[i];
layout[i] = right; newLayout[i] = right;
store.set('deck.layout', layout); layout.value = newLayout;
} }
return true; return true;
} }
return false; return false;
}); });
saveDeck(); saveCurrentDeckProfile();
} }
export function swapUpColumn(id: Column['id']) { export function swapUpColumn(id: Column['id']) {
const layout = deepClone(store.s['deck.layout']); const newLayout = deepClone(layout.value);
const idsIndex = store.s['deck.layout'].findIndex(ids => ids.includes(id)); const idsIndex = layout.value.findIndex(ids => ids.includes(id));
const ids = deepClone(store.s['deck.layout'][idsIndex]); const ids = deepClone(layout.value[idsIndex]);
ids.some((x, i) => { ids.some((x, i) => {
if (x === id) { if (x === id) {
const up = ids[i - 1]; const up = ids[i - 1];
@ -181,20 +196,20 @@ export function swapUpColumn(id: Column['id']) {
ids[i - 1] = id; ids[i - 1] = id;
ids[i] = up; ids[i] = up;
layout[idsIndex] = ids; newLayout[idsIndex] = ids;
store.set('deck.layout', layout); layout.value = newLayout;
} }
return true; return true;
} }
return false; return false;
}); });
saveDeck(); saveCurrentDeckProfile();
} }
export function swapDownColumn(id: Column['id']) { export function swapDownColumn(id: Column['id']) {
const layout = deepClone(store.s['deck.layout']); const newLayout = deepClone(layout.value);
const idsIndex = store.s['deck.layout'].findIndex(ids => ids.includes(id)); const idsIndex = layout.value.findIndex(ids => ids.includes(id));
const ids = deepClone(store.s['deck.layout'][idsIndex]); const ids = deepClone(layout.value[idsIndex]);
ids.some((x, i) => { ids.some((x, i) => {
if (x === id) { if (x === id) {
const down = ids[i + 1]; const down = ids[i + 1];
@ -202,105 +217,137 @@ export function swapDownColumn(id: Column['id']) {
ids[i + 1] = id; ids[i + 1] = id;
ids[i] = down; ids[i] = down;
layout[idsIndex] = ids; newLayout[idsIndex] = ids;
store.set('deck.layout', layout); layout.value = newLayout;
} }
return true; return true;
} }
return false; return false;
}); });
saveDeck(); saveCurrentDeckProfile();
} }
export function stackLeftColumn(id: Column['id']) { export function stackLeftColumn(id: Column['id']) {
let layout = deepClone(store.s['deck.layout']); let newLayout = deepClone(layout.value);
const i = store.s['deck.layout'].findIndex(ids => ids.includes(id)); const i = layout.value.findIndex(ids => ids.includes(id));
layout = layout.map(ids => ids.filter(_id => _id !== id)); newLayout = newLayout.map(ids => ids.filter(_id => _id !== id));
layout[i - 1].push(id); newLayout[i - 1].push(id);
layout = layout.filter(ids => ids.length > 0); newLayout = newLayout.filter(ids => ids.length > 0);
store.set('deck.layout', layout); layout.value = newLayout;
saveDeck(); saveCurrentDeckProfile();
} }
export function popRightColumn(id: Column['id']) { export function popRightColumn(id: Column['id']) {
let layout = deepClone(store.s['deck.layout']); let newLayout = deepClone(layout.value);
const i = store.s['deck.layout'].findIndex(ids => ids.includes(id)); const i = layout.value.findIndex(ids => ids.includes(id));
const affected = layout[i]; const affected = newLayout[i];
layout = layout.map(ids => ids.filter(_id => _id !== id)); newLayout = newLayout.map(ids => ids.filter(_id => _id !== id));
layout.splice(i + 1, 0, [id]); newLayout.splice(i + 1, 0, [id]);
layout = layout.filter(ids => ids.length > 0); newLayout = newLayout.filter(ids => ids.length > 0);
store.set('deck.layout', layout); layout.value = newLayout;
const columns = deepClone(store.s['deck.columns']); const newColumns = deepClone(columns.value);
for (const column of columns) { for (const column of newColumns) {
if (affected.includes(column.id)) { if (affected.includes(column.id)) {
column.active = true; column.active = true;
} }
} }
store.set('deck.columns', columns); columns.value = newColumns;
saveDeck(); saveCurrentDeckProfile();
} }
export function addColumnWidget(id: Column['id'], widget: ColumnWidget) { export function addColumnWidget(id: Column['id'], widget: ColumnWidget) {
const columns = deepClone(store.s['deck.columns']); const newColumns = deepClone(columns.value);
const columnIndex = store.s['deck.columns'].findIndex(c => c.id === id); const columnIndex = columns.value.findIndex(c => c.id === id);
const column = deepClone(store.s['deck.columns'][columnIndex]); const column = deepClone(columns.value[columnIndex]);
if (column == null) return; if (column == null) return;
if (column.widgets == null) column.widgets = []; if (column.widgets == null) column.widgets = [];
column.widgets.unshift(widget); column.widgets.unshift(widget);
columns[columnIndex] = column; newColumns[columnIndex] = column;
store.set('deck.columns', columns); columns.value = newColumns;
saveDeck(); saveCurrentDeckProfile();
} }
export function removeColumnWidget(id: Column['id'], widget: ColumnWidget) { export function removeColumnWidget(id: Column['id'], widget: ColumnWidget) {
const columns = deepClone(store.s['deck.columns']); const newColumns = deepClone(columns.value);
const columnIndex = store.s['deck.columns'].findIndex(c => c.id === id); const columnIndex = columns.value.findIndex(c => c.id === id);
const column = deepClone(store.s['deck.columns'][columnIndex]); const column = deepClone(columns.value[columnIndex]);
if (column == null) return; if (column == null) return;
if (column.widgets == null) column.widgets = []; if (column.widgets == null) column.widgets = [];
column.widgets = column.widgets.filter(w => w.id !== widget.id); column.widgets = column.widgets.filter(w => w.id !== widget.id);
columns[columnIndex] = column; newColumns[columnIndex] = column;
store.set('deck.columns', columns); columns.value = newColumns;
saveDeck(); saveCurrentDeckProfile();
} }
export function setColumnWidgets(id: Column['id'], widgets: ColumnWidget[]) { export function setColumnWidgets(id: Column['id'], widgets: ColumnWidget[]) {
const columns = deepClone(store.s['deck.columns']); const newColumns = deepClone(columns.value);
const columnIndex = store.s['deck.columns'].findIndex(c => c.id === id); const columnIndex = columns.value.findIndex(c => c.id === id);
const column = deepClone(store.s['deck.columns'][columnIndex]); const column = deepClone(columns.value[columnIndex]);
if (column == null) return; if (column == null) return;
column.widgets = widgets; column.widgets = widgets;
columns[columnIndex] = column; newColumns[columnIndex] = column;
store.set('deck.columns', columns); columns.value = newColumns;
saveDeck(); saveCurrentDeckProfile();
} }
export function updateColumnWidget(id: Column['id'], widgetId: string, widgetData: any) { export function updateColumnWidget(id: Column['id'], widgetId: string, widgetData: any) {
const columns = deepClone(store.s['deck.columns']); const newColumns = deepClone(columns.value);
const columnIndex = store.s['deck.columns'].findIndex(c => c.id === id); const columnIndex = columns.value.findIndex(c => c.id === id);
const column = deepClone(store.s['deck.columns'][columnIndex]); const column = deepClone(columns.value[columnIndex]);
if (column == null) return; if (column == null) return;
if (column.widgets == null) column.widgets = []; if (column.widgets == null) column.widgets = [];
column.widgets = column.widgets.map(w => w.id === widgetId ? { column.widgets = column.widgets.map(w => w.id === widgetId ? {
...w, ...w,
data: widgetData, data: widgetData,
} : w); } : w);
columns[columnIndex] = column; newColumns[columnIndex] = column;
store.set('deck.columns', columns); columns.value = newColumns;
saveDeck(); saveCurrentDeckProfile();
} }
export function updateColumn(id: Column['id'], column: Partial<Column>) { export function updateColumn(id: Column['id'], column: Partial<Column>) {
const columns = deepClone(store.s['deck.columns']); const newColumns = deepClone(columns.value);
const columnIndex = store.s['deck.columns'].findIndex(c => c.id === id); const columnIndex = columns.value.findIndex(c => c.id === id);
const currentColumn = deepClone(store.s['deck.columns'][columnIndex]); const currentColumn = deepClone(columns.value[columnIndex]);
if (currentColumn == null) return; if (currentColumn == null) return;
for (const [k, v] of Object.entries(column)) { for (const [k, v] of Object.entries(column)) {
currentColumn[k] = v; currentColumn[k] = v;
} }
columns[columnIndex] = currentColumn; newColumns[columnIndex] = currentColumn;
store.set('deck.columns', columns); columns.value = newColumns;
saveDeck(); saveCurrentDeckProfile();
}
export function switchProfileMenu(ev: MouseEvent) {
const items: MenuItem[] = prefer.s['deck.profile'] ? [{
text: prefer.s['deck.profile'],
active: true,
action: () => {},
}] : [];
const profiles = prefer.s['deck.profiles'];
items.push(...(profiles.filter(p => p.name !== prefer.s['deck.profile']).map(p => ({
text: p.name,
action: () => {
switchProfile(p);
},
}))), { type: 'divider' as const }, {
text: i18n.ts._deck.newProfile,
icon: 'ti ti-plus',
action: async () => {
const { canceled, result: name } = await os.inputText({
title: i18n.ts._deck.profile,
minLength: 1,
});
if (canceled || name == null || name.trim() === '') return;
addProfile(name);
},
});
os.popupMenu(items, ev.currentTarget ?? ev.target);
} }

View File

@ -9,6 +9,7 @@ import type { Theme } from '@/theme.js';
import type { SoundType } from '@/utility/sound.js'; import type { SoundType } from '@/utility/sound.js';
import type { Plugin } from '@/plugin.js'; import type { Plugin } from '@/plugin.js';
import type { DeviceKind } from '@/utility/device-kind.js'; import type { DeviceKind } from '@/utility/device-kind.js';
import type { Column, DeckProfile } from '@/deck.js';
import { DEFAULT_DEVICE_KIND } from '@/utility/device-kind.js'; import { DEFAULT_DEVICE_KIND } from '@/utility/device-kind.js';
/** サウンド設定 */ /** サウンド設定 */
@ -45,6 +46,14 @@ export const PREF_DEF = {
data: Record<string, any>; data: Record<string, any>;
}[], }[],
}, },
'deck.profile': {
accountDependent: true,
default: null as string | null,
},
'deck.profiles': {
accountDependent: true,
default: [] as DeckProfile[],
},
overridedDeviceKind: { overridedDeviceKind: {
default: null as DeviceKind | null, default: null as DeviceKind | null,

View File

@ -42,6 +42,8 @@ export type PreferencesProfile = {
syncByAccount: [Account, keyof PREF][], syncByAccount: [Account, keyof PREF][],
}; };
// TODO: 任意のプロパティをデバイス間で同期できるようにする?
export class ProfileManager extends EventEmitter<{ export class ProfileManager extends EventEmitter<{
updated: (ctx: { updated: (ctx: {
profile: PreferencesProfile profile: PreferencesProfile

View File

@ -10,7 +10,6 @@ import darkTheme from '@@/themes/d-green-lime.json5';
import { hemisphere } from '@@/js/intl-const.js'; import { hemisphere } from '@@/js/intl-const.js';
import type { DeviceKind } from '@/utility/device-kind.js'; import type { DeviceKind } from '@/utility/device-kind.js';
import type { Plugin } from '@/plugin.js'; import type { Plugin } from '@/plugin.js';
import type { Column } from '@/deck.js';
import { miLocalStorage } from '@/local-storage.js'; import { miLocalStorage } from '@/local-storage.js';
import { Storage } from '@/pizzax.js'; import { Storage } from '@/pizzax.js';
import { DEFAULT_DEVICE_KIND } from '@/utility/device-kind.js'; import { DEFAULT_DEVICE_KIND } from '@/utility/device-kind.js';
@ -117,18 +116,6 @@ export const store = markRaw(new Storage('base', {
where: 'deviceAccount', where: 'deviceAccount',
default: {} as Record<string, string>, // plugin id, token default: {} as Record<string, string>, // plugin id, token
}, },
'deck.profile': {
where: 'deviceAccount',
default: 'default',
},
'deck.columns': {
where: 'deviceAccount',
default: [] as Column[],
},
'deck.layout': {
where: 'deviceAccount',
default: [] as Column['id'][][],
},
enablePreferencesAutoCloudBackup: { enablePreferencesAutoCloudBackup: {
where: 'device', where: 'device',

View File

@ -36,7 +36,7 @@ SPDX-License-Identifier: AGPL-3.0-only
</div> </div>
<div :class="$style.sideMenu"> <div :class="$style.sideMenu">
<div :class="$style.sideMenuTop"> <div :class="$style.sideMenuTop">
<button v-tooltip.noDelay.left="`${i18n.ts._deck.profile}: ${store.s['deck.profile']}`" :class="$style.sideMenuButton" class="_button" @click="changeProfile"><i class="ti ti-caret-down"></i></button> <button v-tooltip.noDelay.left="`${i18n.ts._deck.profile}: ${prefer.s['deck.profile']}`" :class="$style.sideMenuButton" class="_button" @click="switchProfileMenu"><i class="ti ti-caret-down"></i></button>
<button v-tooltip.noDelay.left="i18n.ts._deck.deleteProfile" :class="$style.sideMenuButton" class="_button" @click="deleteProfile"><i class="ti ti-trash"></i></button> <button v-tooltip.noDelay.left="i18n.ts._deck.deleteProfile" :class="$style.sideMenuButton" class="_button" @click="deleteProfile"><i class="ti ti-trash"></i></button>
</div> </div>
<div :class="$style.sideMenuMiddle"> <div :class="$style.sideMenuMiddle">
@ -95,7 +95,6 @@ SPDX-License-Identifier: AGPL-3.0-only
import { computed, defineAsyncComponent, ref, watch, shallowRef } from 'vue'; import { computed, defineAsyncComponent, ref, watch, shallowRef } from 'vue';
import { v4 as uuid } from 'uuid'; import { v4 as uuid } from 'uuid';
import XCommon from './_common_/common.vue'; import XCommon from './_common_/common.vue';
import type { MenuItem } from '@/types/menu.js';
import XSidebar from '@/ui/_common_/navbar.vue'; import XSidebar from '@/ui/_common_/navbar.vue';
import XDrawerMenu from '@/ui/_common_/navbar-for-mobile.vue'; import XDrawerMenu from '@/ui/_common_/navbar-for-mobile.vue';
import MkButton from '@/components/MkButton.vue'; import MkButton from '@/components/MkButton.vue';
@ -103,7 +102,6 @@ import * as os from '@/os.js';
import { navbarItemDef } from '@/navbar.js'; import { navbarItemDef } from '@/navbar.js';
import { $i } from '@/account.js'; import { $i } from '@/account.js';
import { i18n } from '@/i18n.js'; import { i18n } from '@/i18n.js';
import { unisonReload } from '@/utility/unison-reload.js';
import { deviceKind } from '@/utility/device-kind.js'; import { deviceKind } from '@/utility/device-kind.js';
import { prefer } from '@/preferences.js'; import { prefer } from '@/preferences.js';
import XMainColumn from '@/ui/deck/main-column.vue'; import XMainColumn from '@/ui/deck/main-column.vue';
@ -117,8 +115,7 @@ import XMentionsColumn from '@/ui/deck/mentions-column.vue';
import XDirectColumn from '@/ui/deck/direct-column.vue'; import XDirectColumn from '@/ui/deck/direct-column.vue';
import XRoleTimelineColumn from '@/ui/deck/role-timeline-column.vue'; import XRoleTimelineColumn from '@/ui/deck/role-timeline-column.vue';
import { mainRouter } from '@/router/main.js'; import { mainRouter } from '@/router/main.js';
import { store } from '@/store.js'; import { columns, layout, columnTypes, switchProfileMenu, addColumn as addColumnToStore, deleteProfile as deleteProfile_ } from '@/deck.js';
import { columnTypes, forceSaveDeck, getProfiles, loadDeck, addColumn as addColumnToStore, deleteProfile as deleteProfile_ } from '@/deck.js';
const XStatusBars = defineAsyncComponent(() => import('@/ui/_common_/statusbars.vue')); const XStatusBars = defineAsyncComponent(() => import('@/ui/_common_/statusbars.vue'));
const XAnnouncements = defineAsyncComponent(() => import('@/ui/_common_/announcements.vue')); const XAnnouncements = defineAsyncComponent(() => import('@/ui/_common_/announcements.vue'));
@ -137,7 +134,7 @@ const columnComponents = {
mainRouter.navHook = (path, flag): boolean => { mainRouter.navHook = (path, flag): boolean => {
if (flag === 'forcePage') return false; if (flag === 'forcePage') return false;
const noMainColumn = !store.s['deck.columns'].some(x => x.type === 'main'); const noMainColumn = !columns.value.some(x => x.type === 'main');
if (prefer.s['deck.navWindow'] || noMainColumn) { if (prefer.s['deck.navWindow'] || noMainColumn) {
os.pageWindow(path); os.pageWindow(path);
return true; return true;
@ -160,8 +157,6 @@ watch(route, () => {
}); });
*/ */
const columns = store.r['deck.columns'];
const layout = store.r['deck.layout'];
const menuIndicated = computed(() => { const menuIndicated = computed(() => {
if ($i == null) return false; if ($i == null) return false;
for (const def in navbarItemDef) { for (const def in navbarItemDef) {
@ -210,65 +205,20 @@ function onWheel(ev: WheelEvent) {
document.documentElement.style.overflowY = 'hidden'; document.documentElement.style.overflowY = 'hidden';
document.documentElement.style.scrollBehavior = 'auto'; document.documentElement.style.scrollBehavior = 'auto';
loadDeck();
function changeProfile(ev: MouseEvent) {
let items: MenuItem[] = [{
text: store.s['deck.profile'],
active: true,
action: () => {},
}];
getProfiles().then(profiles => {
items.push(...(profiles.filter(k => k !== store.s['deck.profile']).map(k => ({
text: k,
action: () => {
store.set('deck.profile', k);
unisonReload();
},
}))), { type: 'divider' as const }, {
text: i18n.ts._deck.newProfile,
icon: 'ti ti-plus',
action: async () => {
const { canceled, result: name } = await os.inputText({
title: i18n.ts._deck.profile,
minLength: 1,
});
if (canceled || name == null) return;
os.promiseDialog((async () => {
await store.set('deck.profile', name);
await forceSaveDeck();
})(), () => {
unisonReload();
});
},
});
}).then(() => {
os.popupMenu(items, ev.currentTarget ?? ev.target);
});
}
async function deleteProfile() { async function deleteProfile() {
if (prefer.s['deck.profile'] == null) return;
const { canceled } = await os.confirm({ const { canceled } = await os.confirm({
type: 'warning', type: 'warning',
text: i18n.tsx.deleteAreYouSure({ x: store.s['deck.profile'] }), text: i18n.tsx.deleteAreYouSure({ x: prefer.s['deck.profile'] }),
}); });
if (canceled) return; if (canceled) return;
os.promiseDialog((async () => { await deleteProfile_(prefer.s['deck.profile']);
if (store.s['deck.profile'] === 'default') {
await store.set('deck.columns', []); os.success();
await store.set('deck.layout', []);
await forceSaveDeck();
} else {
await deleteProfile_(store.s['deck.profile']);
}
await store.set('deck.profile', 'default');
})(), () => {
unisonReload();
});
} }
</script> </script>
<style> <style>

View File

@ -100,7 +100,7 @@ function onOtherDragEnd() {
function toggleActive() { function toggleActive() {
if (!props.isStacked) return; if (!props.isStacked) return;
updateColumn(props.column.id, { updateColumn(props.column.id, {
active: !props.column.active, active: props.column.active == null ? false : !props.column.active,
}); });
} }