generated from mirrors/plugin-sample-vite-svelte
Add offline spell-checking
All checks were successful
Build on Push and create Release on Tag / build (push) Successful in 4m2s
All checks were successful
Build on Push and create Release on Tag / build (push) Successful in 4m2s
This commit is contained in:
parent
a13ac05afb
commit
032e7f0b8c
11 changed files with 252 additions and 64 deletions
|
|
@ -1,21 +1,7 @@
|
|||
import {SettingUtils} from "@/libs/setting-utils";
|
||||
import {showMessage} from 'siyuan';
|
||||
import {LanguageTool} from "@/languagetool";
|
||||
import SpellCheckPlugin from "@/index";
|
||||
|
||||
export type PluginSettings = {
|
||||
server: string
|
||||
username: string
|
||||
apiKey: string
|
||||
picky: boolean
|
||||
motherTongue: string
|
||||
preferredVariants: string
|
||||
enabledByDefault: boolean
|
||||
defaultLanguage: string
|
||||
preferredLanguages: string
|
||||
analytics: boolean
|
||||
}
|
||||
|
||||
import {LanguageTool, LanguageToolSettings} from "@/languagetool";
|
||||
|
||||
export class Settings {
|
||||
|
||||
|
|
@ -61,13 +47,12 @@ export class Settings {
|
|||
await su.load() // needed to fetch languages from server
|
||||
let languagesKV = {}
|
||||
try {
|
||||
let languages = await LanguageTool.getLanguages(<PluginSettings>su.dump())
|
||||
let languages = await new LanguageTool(<LanguageToolSettings>{server: su.get('server')}).getLanguages()
|
||||
languages.forEach(language => {
|
||||
languagesKV[language.longCode] = language.name + ' [' + language.longCode + ']'
|
||||
})
|
||||
} catch {
|
||||
} catch(e) {
|
||||
showMessage(plugin.i18nx.errors.checkServer, -1, 'error')
|
||||
showMessage(plugin.i18nx.errors.fatal, -1, 'error')
|
||||
}
|
||||
|
||||
su.addItem({
|
||||
|
|
@ -129,6 +114,22 @@ export class Settings {
|
|||
value: 'auto'
|
||||
})
|
||||
|
||||
su.addItem({
|
||||
type: 'checkbox',
|
||||
key: 'offline',
|
||||
title: to.offline.title,
|
||||
description: to.offline.description,
|
||||
value: false
|
||||
})
|
||||
|
||||
su.addItem({
|
||||
type: 'textinput',
|
||||
key: 'offlineDicts',
|
||||
title: to.offlineDicts.title,
|
||||
description: to.offlineDicts.description,
|
||||
value: 'en'
|
||||
})
|
||||
|
||||
su.addItem({
|
||||
type: 'checkbox',
|
||||
key: 'analytics',
|
||||
|
|
@ -137,6 +138,12 @@ export class Settings {
|
|||
value: true
|
||||
})
|
||||
|
||||
su.save = async function (data?: any) {
|
||||
data = data ?? this.dump();
|
||||
await this.plugin.saveData(this.file, this.dump());
|
||||
location.reload()
|
||||
}.bind(su)
|
||||
|
||||
await su.load()
|
||||
return su
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue