-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
182 additions
and
140 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import * as vscode from 'vscode' | ||
import { Theme } from './types' | ||
|
||
export const tipSetConfig = (config: string) => { | ||
vscode.window | ||
.showWarningMessage( | ||
`Please set "ayu-mirage-plus.${config}Theme" in settings.json first!`, | ||
'Open settings.json' | ||
) | ||
.then(value => | ||
value === 'Open settings.json' | ||
? vscode.commands.executeCommand('workbench.action.openSettingsJson') | ||
: null | ||
) | ||
} | ||
|
||
export const tipConfigFormat = () => { | ||
vscode.window.showInformationMessage('Ayu Mirage Plus 1.2.0 new!', { | ||
modal: true, | ||
detail: `现在配置项需要 name 和 colors 属性,请重新配置选项! | ||
Now you need use "name" and "colors" in the configuration items. | ||
For details, please refer to the extension page.`, | ||
}) | ||
} | ||
|
||
export const tipAlready = (name: string, config: string) => { | ||
vscode.window | ||
.showInformationMessage(`The "Ayu Mirage Plus ${name}" ${config}`, 'Reload Window') | ||
.then(value => | ||
value === 'Reload Window' | ||
? vscode.commands.executeCommand('workbench.action.reloadWindow') | ||
: null | ||
) | ||
} | ||
|
||
export const tipCreateConfig = (name: string) => { | ||
vscode.window | ||
.showWarningMessage( | ||
`The "Ayu Mirage Plus ${name}" has not been created yet!`, | ||
'Open settings.json' | ||
) | ||
.then(value => | ||
value === 'Open settings.json' | ||
? vscode.commands.executeCommand('workbench.action.openSettingsJson') | ||
: null | ||
) | ||
} | ||
|
||
export const tipRemove = (rmList: Theme[]) => { | ||
vscode.window | ||
.showInformationMessage( | ||
`${rmList?.map(item => item.label).toString()} has been removed!`, | ||
'Reload Window' | ||
) | ||
.then(value => | ||
value === 'Reload Window' | ||
? vscode.commands.executeCommand('workbench.action.reloadWindow') | ||
: null | ||
) | ||
} | ||
|
||
export const tipNothing = () => { | ||
vscode.window.showWarningMessage('Nothing to remove!') | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
export interface ConfigParams { | ||
name: string | ||
colors: { | ||
themeColor: string | ||
foreground: string | ||
border: string | ||
highlight: string | ||
} | ||
} | ||
|
||
export interface Theme { | ||
label: string | ||
uiTheme: string | ||
path: string | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,50 @@ | ||
import * as fs from 'fs' | ||
import * as path from 'path' | ||
import * as vscode from 'vscode' | ||
import { tipNothing, tipRemove } from '../config/tips' | ||
import { Theme } from '../config/types' | ||
|
||
export default async () => { | ||
fs.readFile(`${__dirname}/../package.json`, 'utf-8', async (err, data) => { | ||
if (err) { | ||
throw err | ||
} | ||
|
||
// 获取package.json中的主题配置 | ||
const packageFile = JSON.parse(data) | ||
let themes: { label: string; uiTheme: string; path: string }[] = packageFile.contributes.themes | ||
const rmList = await vscode.window.showQuickPick(themes, { | ||
let themes: Theme[] = packageFile.contributes.themes | ||
|
||
// 去除默认主题 | ||
const rmThemeList = themes.filter(item => item.label !== 'Ayu Mirage Plus') | ||
|
||
if (rmThemeList.length === 0) { | ||
tipNothing() | ||
return | ||
} | ||
|
||
// 选择需要删除的主题列表 | ||
const rmList = await vscode.window.showQuickPick(rmThemeList, { | ||
canPickMany: true, | ||
}) | ||
const rmThemeList = rmList?.filter(item => themes.includes(item)) | ||
|
||
// 删除主题文件 | ||
rmThemeList?.forEach(item => { | ||
const fileName = [ | ||
...__dirname.split(path.sep), | ||
...item.path.split('dist/')[1].split(path.sep), | ||
].join('/') | ||
if (fs.existsSync(fileName)) { | ||
fs.rmSync(fileName) | ||
} | ||
}) | ||
|
||
// 移除package.json中的主题 | ||
const res = themes.filter(item => !rmThemeList?.includes(item)) | ||
packageFile.contributes.themes = res | ||
fs.writeFileSync(`${__dirname}/../package.json`, JSON.stringify(packageFile)) | ||
|
||
if (rmThemeList !== undefined) { | ||
vscode.window | ||
.showInformationMessage( | ||
`${rmThemeList?.map(item => item.label).toString()} has been removed!`, | ||
'Reload Window' | ||
) | ||
.then(value => | ||
value === 'Reload Window' | ||
? vscode.commands.executeCommand('workbench.action.reloadWindow') | ||
: null | ||
) | ||
if (rmList !== undefined) { | ||
// 删除主题文件 | ||
rmList.forEach(item => { | ||
const fileName = [ | ||
...__dirname.split(path.sep), | ||
...item.path.split('dist/')[1].split(path.sep), | ||
].join('/') | ||
if (fs.existsSync(fileName)) { | ||
fs.rmSync(fileName) | ||
} | ||
}) | ||
|
||
// 移除package.json中的主题 | ||
const res = themes.filter(item => !rmList?.includes(item)) | ||
packageFile.contributes.themes = res | ||
fs.writeFileSync(`${__dirname}/../package.json`, JSON.stringify(packageFile)) | ||
|
||
tipRemove(rmList) | ||
} | ||
}) | ||
} |
Oops, something went wrong.