fix: theme migration overwrite existing theme (#2975)
This commit is contained in:
parent
4edef30e0e
commit
19e35e63c9
@ -1,7 +1,15 @@
|
|||||||
import { app } from 'electron'
|
import { app } from 'electron'
|
||||||
|
|
||||||
import { join } from 'path'
|
import { join } from 'path'
|
||||||
import { rmdirSync, cpSync, existsSync } from 'fs'
|
import {
|
||||||
|
rmdirSync,
|
||||||
|
readFileSync,
|
||||||
|
existsSync,
|
||||||
|
mkdirSync,
|
||||||
|
readdirSync,
|
||||||
|
cpSync,
|
||||||
|
lstatSync,
|
||||||
|
} from 'fs'
|
||||||
import Store from 'electron-store'
|
import Store from 'electron-store'
|
||||||
import {
|
import {
|
||||||
getJanExtensionsPath,
|
getJanExtensionsPath,
|
||||||
@ -20,8 +28,8 @@ export async function migrate() {
|
|||||||
if (store.get('migrated_version') !== app.getVersion()) {
|
if (store.get('migrated_version') !== app.getVersion()) {
|
||||||
console.debug('start migration:', store.get('migrated_version'))
|
console.debug('start migration:', store.get('migrated_version'))
|
||||||
|
|
||||||
if (existsSync(getJanExtensionsPath()))
|
// if (existsSync(getJanExtensionsPath()))
|
||||||
rmdirSync(getJanExtensionsPath(), { recursive: true })
|
// rmdirSync(getJanExtensionsPath(), { recursive: true })
|
||||||
await migrateThemes()
|
await migrateThemes()
|
||||||
|
|
||||||
store.set('migrated_version', app.getVersion())
|
store.set('migrated_version', app.getVersion())
|
||||||
@ -32,11 +40,48 @@ export async function migrate() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function migrateThemes() {
|
async function migrateThemes() {
|
||||||
if (existsSync(join(getJanDataFolderPath(), 'themes')))
|
if (!existsSync(join(getJanDataFolderPath(), 'themes')))
|
||||||
rmdirSync(join(getJanDataFolderPath(), 'themes'), { recursive: true })
|
mkdirSync(join(getJanDataFolderPath(), 'themes'), { recursive: true })
|
||||||
cpSync(
|
|
||||||
join(await appResourcePath(), 'themes'),
|
const themes = readdirSync(join(await appResourcePath(), 'themes'))
|
||||||
join(getJanDataFolderPath(), 'themes'),
|
for (const theme of themes) {
|
||||||
{ recursive: true }
|
const themePath = join(await appResourcePath(), 'themes', theme)
|
||||||
)
|
if (existsSync(themePath) && !lstatSync(themePath).isDirectory()) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
await checkAndMigrateTheme(theme, themePath)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function checkAndMigrateTheme(
|
||||||
|
sourceThemeName: string,
|
||||||
|
sourceThemePath: string
|
||||||
|
) {
|
||||||
|
const janDataThemesFolder = join(getJanDataFolderPath(), 'themes')
|
||||||
|
const existingTheme = readdirSync(janDataThemesFolder).find(
|
||||||
|
(theme) => theme === sourceThemeName
|
||||||
|
)
|
||||||
|
if (existingTheme) {
|
||||||
|
const desTheme = join(janDataThemesFolder, existingTheme)
|
||||||
|
if (!existsSync(desTheme) || !lstatSync(desTheme).isDirectory()) return
|
||||||
|
|
||||||
|
const desThemeData = JSON.parse(
|
||||||
|
readFileSync(join(desTheme, 'theme.json'), 'utf-8')
|
||||||
|
)
|
||||||
|
const sourceThemeData = JSON.parse(
|
||||||
|
readFileSync(join(sourceThemePath, 'theme.json'), 'utf-8')
|
||||||
|
)
|
||||||
|
if (desThemeData.version !== sourceThemeData.version) {
|
||||||
|
console.debug('Updating theme', existingTheme)
|
||||||
|
rmdirSync(desTheme, { recursive: true })
|
||||||
|
cpSync(sourceThemePath, join(janDataThemesFolder, sourceThemeName), {
|
||||||
|
recursive: true,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
console.debug('Adding new theme', sourceThemeName)
|
||||||
|
cpSync(sourceThemePath, join(janDataThemesFolder, sourceThemeName), {
|
||||||
|
recursive: true,
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user