forked from FluentFlame/fluentflame-reader
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsettings.ts
More file actions
137 lines (132 loc) · 4.62 KB
/
Copy pathsettings.ts
File metadata and controls
137 lines (132 loc) · 4.62 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
import * as db from "./db"
import { IPartialTheme, loadTheme } from "@fluentui/react"
import locales from "./i18n/_locales"
import { ThemeSettings } from "../schema-types"
import intl from "react-intl-universal"
import { SourceTextDirection } from "./models/source"
let lightTheme: IPartialTheme = {
defaultFontStyle: {
fontFamily: '"Segoe UI", "Source Han Sans Regular", sans-serif',
},
}
let darkTheme: IPartialTheme = {
...lightTheme,
palette: {
neutralLighterAlt: "#282828",
neutralLighter: "#313131",
neutralLight: "#3f3f3f",
neutralQuaternaryAlt: "#484848",
neutralQuaternary: "#4f4f4f",
neutralTertiaryAlt: "#6d6d6d",
neutralTertiary: "#c8c8c8",
neutralSecondary: "#d0d0d0",
neutralSecondaryAlt: "#d2d0ce",
neutralPrimaryAlt: "#dadada",
neutralPrimary: "#ffffff",
neutralDark: "#f4f4f4",
black: "#f8f8f8",
white: "#1f1f1f",
themePrimary: "#3a96dd",
themeLighterAlt: "#020609",
themeLighter: "#091823",
themeLight: "#112d43",
themeTertiary: "#235a85",
themeSecondary: "#3385c3",
themeDarkAlt: "#4ba0e1",
themeDark: "#65aee6",
themeDarker: "#8ac2ec",
accent: "#3a96dd",
},
}
export function setThemeDefaultFont(locale: string) {
switch (locale) {
case "zh-CN":
lightTheme.defaultFontStyle.fontFamily =
'"Segoe UI", "Source Han Sans SC Regular", "Microsoft YaHei", sans-serif'
break
case "zh-TW":
lightTheme.defaultFontStyle.fontFamily =
'"Segoe UI", "Source Han Sans TC Regular", "Microsoft JhengHei", sans-serif'
break
case "ja":
lightTheme.defaultFontStyle.fontFamily =
'"Segoe UI", "Source Han Sans JP Regular", "Yu Gothic UI", sans-serif'
break
case "ko":
lightTheme.defaultFontStyle.fontFamily =
'"Segoe UI", "Source Han Sans KR Regular", "Malgun Gothic", sans-serif'
break
default:
lightTheme.defaultFontStyle.fontFamily =
'"Segoe UI", "Source Han Sans Regular", sans-serif'
}
darkTheme.defaultFontStyle.fontFamily =
lightTheme.defaultFontStyle.fontFamily
applyThemeSettings()
}
export function setThemeSettings(theme: ThemeSettings) {
window.settings.setThemeSettings(theme)
applyThemeSettings()
}
export function getThemeSettings(): ThemeSettings {
return window.settings.getThemeSettings()
}
export function applyThemeSettings() {
loadTheme(window.settings.shouldUseDarkColors() ? darkTheme : lightTheme)
}
window.settings.addThemeUpdateListener(shouldDark => {
loadTheme(shouldDark ? darkTheme : lightTheme)
})
export function getCurrentLocale() {
let locale = window.settings.getCurrentLocale()
if (locale in locales) return locale
locale = locale.split("-")[0]
return locale in locales ? locale : "en-US"
}
export async function exportAll() {
const filters = [{ name: intl.get("app.frData"), extensions: ["frdata"] }]
const write = await window.utils.showSaveDialog(
filters,
"*/Fluent_Reader_Backup.frdata"
)
if (write) {
let output = window.settings.getAll()
output["lovefield"] = {
sources: await db.fluentDB.sources.toArray(),
items: await db.itemsDB.select().from(db.items).exec(),
}
write(JSON.stringify(output), intl.get("settings.writeError"))
}
}
export async function importAll() {
const filters = [{ name: intl.get("app.frData"), extensions: ["frdata"] }]
let data = await window.utils.showOpenDialog(filters)
if (!data) return true
let confirmed = await window.utils.showMessageBox(
intl.get("app.restore"),
intl.get("app.confirmImport"),
intl.get("confirm"),
intl.get("cancel"),
true,
"warning"
)
if (!confirmed) return true
let configs = JSON.parse(data)
await db.fluentDB.sources.clear()
await db.itemsDB.delete().from(db.items).exec()
configs.lovefield.sources.forEach(s => {
s.lastFetched = new Date(s.lastFetched)
if (!s.textDir) s.textDir = SourceTextDirection.LTR
if (!s.hidden) s.hidden = false
return db.fluentDB.sources.add(s)
})
const iRows = configs.lovefield.items.map(i => {
i.date = new Date(i.date)
i.fetchedDate = new Date(i.fetchedDate)
return db.items.createRow(i)
})
await db.itemsDB.insert().into(db.items).values(iRows).exec()
delete configs.lovefield
window.settings.setAll(configs)
return false
}