Change use-marker config under the Settings from Preferences

This commit is contained in:
AkiraFukushima 2022-01-01 22:41:28 +09:00
parent 76437ce599
commit a4811dab7c
No known key found for this signature in database
GPG Key ID: B6E51BAC4DE1A957
20 changed files with 105 additions and 61 deletions

View File

@ -16,8 +16,7 @@ const state = (): GeneralState => {
timeline: {
cw: false,
nsfw: false,
hideAllAttachments: false,
useMarkerTimeline: []
hideAllAttachments: false
},
other: {
launch: false

View File

@ -83,6 +83,10 @@ const state = (): TimelineSpaceState => {
direct: true,
local: true,
public: true
},
useMarker: {
home: false,
notifications: true
}
},
sns: 'mastodon',

View File

@ -141,6 +141,12 @@ const timelineState = {
account: {
accessToken: 'token',
baseURL: 'http://localhost'
},
timelineSetting: {
useMarker: {
home: false,
notifications: false
}
}
}
}
@ -148,8 +154,7 @@ const timelineState = {
const appState = {
namespaced: true,
state: {
proxyConfiguration: false,
useMarkerTimeline: []
proxyConfiguration: false
}
}

View File

@ -215,6 +215,12 @@ const timelineState = {
account: {
accessToken: 'token',
baseURL: 'http://localhost'
},
timelineSetting: {
useMarker: {
home: false,
notifications: false
}
}
}
}

View File

@ -12,8 +12,7 @@ describe('Preferences/General', () => {
timeline: {
cw: false,
nsfw: false,
hideAllAttachments: false,
useMarkerTimeline: []
hideAllAttachments: false
},
other: {
launch: false

View File

@ -1,5 +1,5 @@
import TimelineSpace, { TimelineSpaceState, blankAccount, MUTATION_TYPES } from '~/src/renderer/store/TimelineSpace'
import { Base } from '~/src/constants/initializer/setting'
import { DefaultSetting } from '~/src/constants/initializer/setting'
describe('TimelineSpace', () => {
describe('mutations', () => {
@ -11,7 +11,7 @@ describe('TimelineSpace', () => {
loading: false,
emojis: [],
tootMax: 500,
timelineSetting: Base.timeline,
timelineSetting: DefaultSetting.timeline,
sns: 'mastodon',
filters: []
}

View File

@ -111,6 +111,11 @@
"direct": "Direct Messages",
"local": "Local Timeline",
"public": "Public Timeline"
},
"use_marker": {
"title": "Load the timeline from the last reading position",
"home": "Home",
"notifications": "Notifications"
}
},
"filters": {
@ -162,8 +167,7 @@
"description": "Customize view in your timelines.",
"cw": "Always ignore contents warnings",
"nsfw": "Always ignore NSFW of medias",
"hideAllAttachments": "Hide all medias",
"useMarker": "Load timeline from the last reading position"
"hideAllAttachments": "Hide all medias"
},
"other": {
"title": "Other options",

View File

@ -20,8 +20,7 @@ const sound: Sound = {
const timeline: Timeline = {
cw: false,
nsfw: false,
hideAllAttachments: false,
useMarkerTimeline: ['notifications']
hideAllAttachments: false
}
const other: Other = {

View File

@ -1,4 +1,4 @@
import { Setting, Timeline, UnreadNotification } from '~/src/types/setting'
import { Setting, Timeline, UnreadNotification, UseMarker } from '~/src/types/setting'
const unreadNotification: UnreadNotification = {
direct: false,
@ -6,11 +6,17 @@ const unreadNotification: UnreadNotification = {
public: false
}
const timeline: Timeline = {
unreadNotification: unreadNotification
const useMarker: UseMarker = {
home: false,
notifications: true
}
export const Base: Setting = {
const timeline: Timeline = {
unreadNotification: unreadNotification,
useMarker: useMarker
}
export const DefaultSetting: Setting = {
accountID: '',
timeline: timeline
}

View File

@ -2,7 +2,7 @@ import storage from 'electron-json-storage'
import log from 'electron-log'
import objectAssignDeep from 'object-assign-deep'
import { BaseSettings, Setting } from '~/src/types/setting'
import { Base } from '~/src/constants/initializer/setting'
import { DefaultSetting } from '~/src/constants/initializer/setting'
import { isEmpty } from 'lodash'
export default class Settings {
@ -12,7 +12,7 @@ export default class Settings {
this.path = path
}
public async load(): Promise<BaseSettings> {
public async _load(): Promise<BaseSettings> {
try {
const settings = await this._get()
if (isEmpty(settings)) {
@ -26,17 +26,16 @@ export default class Settings {
}
public async get(accountID: string): Promise<Setting> {
const current = await this.load()
const current = await this._load()
const find: Setting | undefined = current.find(d => {
return d.accountID === accountID
})
if (find) {
return find
return objectAssignDeep({}, DefaultSetting, find)
}
const base = objectAssignDeep({}, Base, {
return objectAssignDeep({}, DefaultSetting, {
accountID: accountID
})
return base
}
private _get(): Promise<BaseSettings> {
@ -58,7 +57,7 @@ export default class Settings {
}
public async update(obj: Setting): Promise<BaseSettings> {
const current = await this.load()
const current = await this._load()
const find = current.find(d => {
return d.accountID === obj.accountID
})

View File

@ -23,12 +23,6 @@
<el-form-item for="hideAllAttachments" :label="$t('preferences.general.timeline.hideAllAttachments')">
<el-switch id="hideAllAttachments" v-model="timeline_hide_attachments" active-color="#13ce66"> </el-switch>
</el-form-item>
<el-form-item for="useMarker" :label="$t('preferences.general.timeline.useMarker')">
<el-checkbox-group v-model="timeline_use_marker">
<el-checkbox label="home" name="type"></el-checkbox>
<el-checkbox label="notifications" name="type"></el-checkbox>
</el-checkbox-group>
</el-form-item>
</el-form>
<el-form class="other section" label-position="right" label-width="250px" size="small" v-if="notDarwin">
<h3>{{ $t('preferences.general.other.title') }}</h3>
@ -105,17 +99,6 @@ export default {
})
}
},
timeline_use_marker: {
get() {
return this.$store.state.Preferences.General.general.timeline.useMarkerTimeline
},
set(value) {
console.log(value)
this.$store.dispatch('Preferences/General/updateTimeline', {
useMarkerTimeline: value
})
}
},
other_launch: {
get() {
return this.$store.state.Preferences.General.general.other.launch

View File

@ -15,6 +15,16 @@
<el-switch v-model="public" id="public" />
</el-form-item>
</el-form>
<el-form class="use-marker section" size="medium" label-position="right" label-width="250px">
<h3>{{ $t('settings.timeline.use_marker.title') }}</h3>
<el-form-item for="marker_home" :label="$t('settings.timeline.use_marker.home')">
<el-switch v-model="marker_home" id="marker_home" />
</el-form-item>
<el-form-item for="marker_notifications" :label="$t('settings.timeline.use_marker.notifications')">
<el-switch v-model="marker_notifications" id="marker_notifications" />
</el-form-item>
</el-form>
</div>
</template>
@ -51,6 +61,26 @@ export default {
public: value
})
}
},
marker_home: {
get() {
return this.$store.state.Settings.Timeline.setting.useMarker.home
},
set(value) {
this.$store.dispatch('Settings/Timeline/changeUseMarker', {
home: value
})
}
},
marker_notifications: {
get() {
return this.$store.state.Settings.Timeline.setting.useMarker.notifications
},
set(value) {
this.$store.dispatch('Settings/Timeline/changeUseMarker', {
notifications: value
})
}
}
},
async created() {

View File

@ -27,7 +27,6 @@ export type AppState = {
hideAllAttachments: boolean
tootPadding: number
userAgent: string
useMarkerTimeline: Array<string>
}
const state = (): AppState => ({
@ -52,8 +51,7 @@ const state = (): AppState => ({
ignoreCW: false,
ignoreNSFW: false,
hideAllAttachments: false,
userAgent: 'Whalebird',
useMarkerTimeline: ['notifications']
userAgent: 'Whalebird'
})
const MUTATION_TYPES = {
@ -67,8 +65,7 @@ const MUTATION_TYPES = {
ADD_FONT: 'addFont',
UPDATE_IGNORE_CW: 'updateIgnoreCW',
UPDATE_IGNORE_NSFW: 'updateIgnoreNSFW',
UPDATE_HIDE_ALL_ATTACHMENTS: 'updateHideAllAttachments',
UPDATE_USE_MARKER: 'updateUseMarker'
UPDATE_HIDE_ALL_ATTACHMENTS: 'updateHideAllAttachments'
}
const mutations: MutationTree<AppState> = {
@ -105,9 +102,6 @@ const mutations: MutationTree<AppState> = {
},
[MUTATION_TYPES.UPDATE_HIDE_ALL_ATTACHMENTS]: (state: AppState, hideAllAttachments: boolean) => {
state.hideAllAttachments = hideAllAttachments
},
[MUTATION_TYPES.UPDATE_USE_MARKER]: (state: AppState, useMarkerTimeline: Array<string>) => {
state.useMarkerTimeline = useMarkerTimeline
}
}
@ -133,7 +127,6 @@ const actions: ActionTree<AppState, RootState> = {
commit(MUTATION_TYPES.UPDATE_IGNORE_CW, conf.general.timeline.cw)
commit(MUTATION_TYPES.UPDATE_IGNORE_NSFW, conf.general.timeline.nsfw)
commit(MUTATION_TYPES.UPDATE_HIDE_ALL_ATTACHMENTS, conf.general.timeline.hideAllAttachments)
commit(MUTATION_TYPES.UPDATE_USE_MARKER, conf.general.timeline.useMarkerTimeline)
return conf
},
updateTheme: async ({ commit }, appearance: Appearance) => {

View File

@ -21,8 +21,7 @@ const state = (): GeneralState => ({
timeline: {
cw: false,
nsfw: false,
hideAllAttachments: false,
useMarkerTimeline: ['notifications']
hideAllAttachments: false
},
other: {
launch: false

View File

@ -1,8 +1,8 @@
import { Module, MutationTree, ActionTree } from 'vuex'
import { RootState } from '@/store'
import { MyWindow } from '~/src/types/global'
import { Setting, UnreadNotification, Timeline as TimelineSetting } from '~src/types/setting'
import { Base } from '~/src/constants/initializer/setting'
import { Setting, UnreadNotification, Timeline as TimelineSetting, UseMarker } from '~src/types/setting'
import { DefaultSetting } from '~/src/constants/initializer/setting'
const win = (window as any) as MyWindow
@ -11,7 +11,7 @@ export type TimelineState = {
}
const state = (): TimelineState => ({
setting: Base.timeline
setting: DefaultSetting.timeline
})
export const MUTATION_TYPES = {
@ -42,6 +42,19 @@ const actions: ActionTree<TimelineState, RootState> = {
await win.ipcRenderer.invoke('update-account-setting', setting)
dispatch('loadTimelineSetting')
return true
},
changeUseMarker: async ({ dispatch, state, rootState }, timeline: { key: boolean }) => {
const marker: UseMarker = Object.assign({}, state.setting.useMarker, timeline)
const tl: TimelineSetting = Object.assign({}, state.setting, {
useMarker: marker
})
const setting: Setting = {
accountID: rootState.Settings.accountID!,
timeline: tl
}
await win.ipcRenderer.invoke('update-account-setting', setting)
dispatch('loadTimelineSetting')
return true
}
}

View File

@ -10,7 +10,7 @@ import { AccountLoadError } from '@/errors/load'
import { TimelineFetchError } from '@/errors/fetch'
import { MyWindow } from '~/src/types/global'
import { Timeline, Setting } from '~src/types/setting'
import { Base } from '~/src/constants/initializer/setting'
import { DefaultSetting } from '~/src/constants/initializer/setting'
const win = (window as any) as MyWindow
@ -45,7 +45,7 @@ const state = (): TimelineSpaceState => ({
loading: false,
emojis: [],
tootMax: 500,
timelineSetting: Base.timeline,
timelineSetting: DefaultSetting.timeline,
sns: 'mastodon',
filters: []
})

View File

@ -134,7 +134,7 @@ const actions: ActionTree<HomeState, RootState> = {
console.error(err)
})
if (rootState.App.useMarkerTimeline.includes('home') && localMarker !== null) {
if (rootState.TimelineSpace.timelineSetting.useMarker.home && localMarker !== null) {
const last = await client.getStatus(localMarker.last_read_id)
const lastReadStatus = last.data
@ -240,7 +240,7 @@ const actions: ActionTree<HomeState, RootState> = {
return res.data
},
getMarker: async ({ rootState }): Promise<LocalMarker | null> => {
if (!rootState.App.useMarkerTimeline.includes('home')) {
if (!rootState.TimelineSpace.timelineSetting.useMarker.home) {
return null
}
const client = generator(

View File

@ -120,7 +120,7 @@ const actions: ActionTree<NotificationsState, RootState> = {
console.error(err)
})
if (rootState.App.useMarkerTimeline.includes('notifications') && localMarker !== null) {
if (rootState.TimelineSpace.timelineSetting.useMarker.notifications && localMarker !== null) {
// The result does not contain max_id's notification, when we specify max_id parameter in get notifications.
// So we need to get max_id's notification.
const last = await client.getNotification(localMarker.last_read_id)
@ -224,7 +224,7 @@ const actions: ActionTree<NotificationsState, RootState> = {
win.ipcRenderer.send('reset-badge')
},
getMarker: async ({ rootState }): Promise<LocalMarker | null> => {
if (!rootState.App.useMarkerTimeline.includes('notifications')) {
if (!rootState.TimelineSpace.timelineSetting.useMarker.notifications) {
return null
}
const client = generator(

View File

@ -4,8 +4,14 @@ export type UnreadNotification = {
public: boolean
}
export type UseMarker = {
home: boolean
notifications: boolean
}
export type Timeline = {
unreadNotification: UnreadNotification
useMarker: UseMarker
}
export type Setting = {
accountID: string

View File

@ -2,5 +2,4 @@ export type Timeline = {
cw: boolean
nsfw: boolean
hideAllAttachments: boolean
useMarkerTimeline: Array<string>
}