Skip to content

Commit

Permalink
[add] Preferences V5
Browse files Browse the repository at this point in the history
  • Loading branch information
VecHK committed Jul 30, 2023
1 parent 16d133e commit 0bfe704
Show file tree
Hide file tree
Showing 10 changed files with 93 additions and 32 deletions.
3 changes: 2 additions & 1 deletion src/preferences/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default function getDefaultPreferences(
): Preferences {
return {
__is_poker__: true,
version: 4,
version: 5,
fill_empty_window: false,
refocus_window: false,
launch_poker_contextmenu: true,
Expand All @@ -35,5 +35,6 @@ export function generateExampleOption(): SiteOption {
name: '_DEFAULT_NAME_',
url_pattern: `https://example.com?search=${cfg.KEYWORD_REPLACEHOLDER}`,
access_mode: 'MOBILE',
width_size: 1
}
}
14 changes: 10 additions & 4 deletions src/preferences/versions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,19 @@ import { PreferencesV1 } from './v1-type'
import { PreferencesV2 } from './v2-type'
import { PreferencesV3 } from './v3-type'
import { PreferencesV4 } from './v4-type'
import { PreferencesV5 } from './v5-type'

export type DefinePreferences<Ver, T> = Readonly<{
__is_poker__: true
version: Ver
} & T>

// -------- 每次添加新的版本后,都得修改这块地方 --------
// -------- 隔壁 update.ts 的 updater 也要更新 --------
export const CURRENT_PREFERENCES_VERSION = 4
export * from './v4-type'
export type LatestVersion = PreferencesV4
export type AllVersion = LatestVersion | PreferencesV3 | PreferencesV2 | PreferencesV1
export const CURRENT_PREFERENCES_VERSION = 5
export * from './v5-type'
export type LatestVersion = PreferencesV5
export type AllVersion = LatestVersion | PreferencesV4 | PreferencesV3 | PreferencesV2 | PreferencesV1
// ------------------------------------------------------

export const checkVersion = (loaded_options: AllVersion) => {
Expand Down
6 changes: 3 additions & 3 deletions src/preferences/versions/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@ import { AllVersion, LatestVersion } from '.'
import { updater as v2Updater } from './v2'
import { updater as v3Updater } from './v3'
import { updater as v4Updater } from './v4'
import { updater as v5Updater } from './v5'

// -------- 每次添加新的版本后,都得修改这块地方 --------
// -------- 隔壁 index.ts 也要更新 --------
export function updatePreferences(s_opts: AllVersion): LatestVersion {
switch (s_opts.version) {
case 1:
return updatePreferences(v2Updater(s_opts))

case 2:
return updatePreferences(v3Updater(s_opts))

case 3:
return updatePreferences(v4Updater(s_opts))

case 4:
return updatePreferences(v5Updater(s_opts))
default:
return s_opts
}
Expand Down
6 changes: 3 additions & 3 deletions src/preferences/versions/v1-type.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
type URLPattern = string
export type SiteOption = {
type SiteOption = {
id: string
icon: string
name: string
url_pattern: URLPattern
}
export type SiteRow = Array<SiteOption>
export type SiteMatrix = Array<SiteRow>
type SiteRow = Array<SiteOption>
type SiteMatrix = Array<SiteRow>

export type PreferencesV1 = Readonly<{
version: 1
Expand Down
8 changes: 4 additions & 4 deletions src/preferences/versions/v2-type.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
export type URLPattern = string
export type SiteOption = {
type URLPattern = string
type SiteOption = {
id: string
icon: string | null
name: string
url_pattern: URLPattern
enable_mobile: boolean
}
export type SiteRow = Array<SiteOption>
export type SiteMatrix = Array<SiteRow>
type SiteRow = Array<SiteOption>
type SiteMatrix = Array<SiteRow>

export type PreferencesV2 = Readonly<{
version: 2
Expand Down
14 changes: 7 additions & 7 deletions src/preferences/versions/v3-type.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
export type URLPattern = string
export type SiteOption = {
import { DefinePreferences } from './'

type URLPattern = string
type SiteOption = {
id: string
icon: string | null
name: string
url_pattern: URLPattern
enable_mobile: boolean
}
export type SiteSettingsRow = {
type SiteSettingsRow = {
id: string
name: string
row: Array<SiteOption>
}
export type SiteSettings = Array<SiteSettingsRow>
type SiteSettings = Array<SiteSettingsRow>

export type PreferencesV3 = Readonly<{
__is_poker__: true,
version: 3
export type PreferencesV3 = DefinePreferences<3, {
launch_poker_contextmenu: boolean
site_settings: SiteSettings
}>
16 changes: 8 additions & 8 deletions src/preferences/versions/v4-type.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
export type URLPattern = string
export type SiteOption = {
import { DefinePreferences } from './'

type URLPattern = string
type SiteOption = {
id: string
icon: string | null
name: string
url_pattern: URLPattern
access_mode: 'DESKTOP' | 'MOBILE' | 'MOBILE-STRONG'
}
export type SiteSettingFloorID = string
export type SiteSettingFloor = {
type SiteSettingFloorID = string
type SiteSettingFloor = {
id: SiteSettingFloorID
name: string
row: Array<SiteOption>
}
export type SiteSettings = Array<SiteSettingFloor>
type SiteSettings = Array<SiteSettingFloor>

export type PreferencesV4 = Readonly<{
__is_poker__: true,
version: 4
export type PreferencesV4 = DefinePreferences<4, {
launch_poker_contextmenu: boolean

fill_empty_window: boolean
Expand Down
3 changes: 1 addition & 2 deletions src/preferences/versions/v4.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ export function updater(v3: PreferencesV3): PreferencesV4 {
__is_poker__: true,
version: 4,

launch_poker_contextmenu: true,

launch_poker_contextmenu: v3.launch_poker_contextmenu,
fill_empty_window: true,
refocus_window: true,

Expand Down
33 changes: 33 additions & 0 deletions src/preferences/versions/v5-type.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// v2.0.0 启用

import { DefinePreferences } from './'

export type URLPattern = string
export type SiteOption = {
id: string
icon: string | null
name: string
url_pattern: URLPattern
access_mode: 'DESKTOP' | 'MOBILE' | 'MOBILE-STRONG'
width_size: number
}
export type SiteSettingFloorID = string
export type SiteSettingFloor = {
id: SiteSettingFloorID
name: string
row: Array<SiteOption>
}
export type SiteSettings = Array<SiteSettingFloor>

export type PreferencesV5 = DefinePreferences<5, {
// 右键菜单栏【启动Poker】
launch_poker_contextmenu: boolean

// 将每一层的页面填充满
fill_empty_window: boolean

// 「唤回 Poker」窗口
refocus_window: boolean

site_settings: SiteSettings
}>
22 changes: 22 additions & 0 deletions src/preferences/versions/v5.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { PreferencesV4 } from './v4-type'
import { PreferencesV5 } from './v5-type'

export function updater(v4: PreferencesV4): PreferencesV5 {
return {
...v4,

version: 5,

site_settings: v4.site_settings.map(settings_row => {
return {
...settings_row,
row: settings_row.row.map(opt => {
return {
...opt,
width_size: 1
}
})
}
}),
}
}

0 comments on commit 0bfe704

Please sign in to comment.