Skip to content

Commit

Permalink
Enable your extension to run on VS Code for the web #581, #601, Fixed…
Browse files Browse the repository at this point in the history
… setting sometime doesn't work problem #606
  • Loading branch information
Binaryify committed Sep 30, 2021
1 parent d452b44 commit f64c3cd
Show file tree
Hide file tree
Showing 9 changed files with 88 additions and 54 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# CHANGELOG
## 3.13.0 | 2021.09.30
- Enable your extension to run on VS Code for the web [#601](https://github.com/Binaryify/OneDark-Pro/pull/601) [#581](https://github.com/Binaryify/OneDark-Pro/issues/581)

- Fixed setting sometime doesn't work problem [#606](https://github.com/Binaryify/OneDark-Pro/issues/606)

## 3.12.1 | 2021.09.26
- Fixed One Dark Pro Darker theme's markdown style no apply problem

## 3.12.0 | 2021.09.19
- Dynamically loading themes files, add `Starfall Ocean` in built-in themes [#605](https://github.com/Binaryify/OneDark-Pro/issues/605)

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "material-theme",
"displayName": "One Dark Pro",
"description": "Atom‘s iconic One Dark theme for Visual Studio Code",
"version": "3.12.1",
"version": "3.13.0",
"publisher": "zhuangtongfa",
"license": "MIT",
"bugs": {
Expand Down
10 changes: 5 additions & 5 deletions scripts/generate-theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,23 @@ import * as darkerConfig from '../src/darkerConfig.json'
import { promises as fs } from 'fs'

export function writeFile(path: string, data: unknown): Promise<void> {
return fs.writeFile(path, JSON.stringify(data, null, 2))
return fs.writeFile(path, JSON.stringify(data, null, 2))
}

async function main(){
async function main() {
writeFile(
join(__dirname, '..', 'themes', 'OneDark-Pro.json'),
await Theme.init(defaultSettings)
)

writeFile(
join(__dirname, '..', 'themes', 'OneDark-Pro-flat.json'),
await Theme.init(flatConfig)
)

writeFile(
join(__dirname, '..', 'themes', 'OneDark-Pro-darker.json'),
await Theme.init(darkerConfig)
)
}
main()
main()
68 changes: 40 additions & 28 deletions src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import { join } from 'path'
import { TextEncoder } from "util";
import { commands as Commands, ConfigurationTarget, Uri, workspace } from 'vscode';
import { TextEncoder } from 'util'
import {
commands as Commands,
ConfigurationTarget,
Uri,
workspace,
} from 'vscode'
import { ChangelogWebview } from './webviews/Changelog'
import { updateCSS, updateTheme } from './utils'

Expand All @@ -10,35 +15,42 @@ import { updateCSS, updateTheme } from './utils'
*/
export async function activate() {
const flagPath = Uri.file(join(__dirname, '../temp', 'flag.txt'))

let flag
try {
await workspace.fs.writeFile(flagPath, new TextEncoder().encode(''))

const configArr = [
{ defaultVal: false, type: 'bold' },
{ defaultVal: true, type: 'italic' },
{ defaultVal: false, type: 'vivid' },
]
const configuration = workspace.getConfiguration('oneDarkPro')
let isDefaultConfig = configArr.every((item) => {
return configuration.get<boolean>(item.type) === item.defaultVal
})
let colorConfig = configuration.get<object>(`color`)
let colorFlagStr = ''
for (let key in colorConfig) {
colorFlagStr += colorConfig[key]
// await workspace.fs.writeFile(flagPath, new TextEncoder().encode('true'))
try {
if (await workspace.fs.stat(flagPath)) {
flag = true
}
} catch (error) {}
if (!flag) {
await workspace.fs.writeFile(flagPath, new TextEncoder().encode('true'))
const configArr = [
{ defaultVal: false, type: 'bold' },
{ defaultVal: true, type: 'italic' },
{ defaultVal: false, type: 'vivid' },
]
const configuration = workspace.getConfiguration('oneDarkPro')
let isDefaultConfig = configArr.every((item) => {
return configuration.get<boolean>(item.type) === item.defaultVal
})
let colorConfig = configuration.get<object>(`color`)
let colorFlagStr = ''
for (let key in colorConfig) {
colorFlagStr += colorConfig[key]
}
if (colorFlagStr != '') {
isDefaultConfig = false
}
if (!isDefaultConfig) {
updateTheme()
}
if (!configuration.get<boolean>('markdownStyle')) {
updateCSS()
}
}
if (colorFlagStr != '') {
isDefaultConfig = false
}
if (!isDefaultConfig) {
updateTheme()
}
if (!configuration.get<boolean>('markdownStyle')) {
updateCSS()
}

} catch (err) {
console.log(err)
// do nothing
}

Expand Down
7 changes: 5 additions & 2 deletions src/themes/Theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ async function createEditorTokens(config: ThemeConfiguration) {
}

function configFactory(configuration) {
let result: TokenColor[] = data.tokenColors.default
let result: TokenColor[] = JSON.parse(
JSON.stringify(data.tokenColors.default)
)

function uniqBy(
baseArray: TokenColor[],
Expand Down Expand Up @@ -87,9 +89,10 @@ export class Theme {
// this.colors = createEditorTokens(configuration)
}
static async init(config) {
return {
const result = {
...new Theme(config),
colors: await createEditorTokens(config),
}
return result
}
}
5 changes: 3 additions & 2 deletions src/themes/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@ export const generateTheme = {
colorObj[item] = value
}
})
return await Theme.init({
const buildConfig={
bold: configuration.get<boolean>('bold', defaultSettings.bold),
editorTheme:
themeName ||
configuration.get<string>('editorTheme', defaultSettings.editorTheme),
italic: configuration.get<boolean>('italic', defaultSettings.italic),
vivid: configuration.get<boolean>('vivid', defaultSettings.vivid),
...colorObj,
})
}
return await Theme.init(buildConfig)
},
}
1 change: 0 additions & 1 deletion src/utils/updateCSS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,4 @@ export function updateCSS() {
fileContents)
})
}
// promptToReload()
}
15 changes: 9 additions & 6 deletions src/utils/updateTheme.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
import { join } from 'path'
import { Uri, workspace } from 'vscode'
import { TextEncoder } from "util";
import { TextEncoder } from 'util'
import { generateTheme } from '../themes'
import { promptToReload } from './'

export async function updateTheme() {
const writeTheme = (fileName: string, themeName?: string) => {
const writeTheme = async (fileName: string, themeName?: string) => {
const THEME_PATH = Uri.file(join(__dirname, '../../', 'themes', fileName))
const theme = generateTheme.fromSettings(themeName)
return workspace.fs.writeFile(THEME_PATH, new TextEncoder().encode(JSON.stringify(theme)))
};
const theme = await generateTheme.fromSettings(themeName)
return workspace.fs.writeFile(
THEME_PATH,
new TextEncoder().encode(JSON.stringify(theme, null, 2))
)
}

let promiseArr = []
promiseArr = [
writeTheme('OneDark-Pro.json'),
writeTheme('OneDark-Pro-flat.json', 'One Dark Pro Flat'),
writeTheme('OneDark-Pro-darker.json', 'One Dark Pro Darker')
writeTheme('OneDark-Pro-darker.json', 'One Dark Pro Darker'),
]
await Promise.all(promiseArr)
promptToReload()
Expand Down
28 changes: 19 additions & 9 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,6 @@
dependencies:
regenerator-runtime "^0.13.4"

"@discoveryjs/json-ext@^0.5.0":
version "0.5.3"
resolved "https://registry.npmjs.org/@discoveryjs/json-ext/-/json-ext-0.5.3.tgz"
integrity sha512-Fxt+AfXgjMoin2maPIYzFZnQjAXjAL0PHscM5pRTtatFqB+vZxAM9tLp2Optnuw3QOQC40jTNeGYFOMvyf7v9g==

"@cspotcode/source-map-consumer@0.8.0":
version "0.8.0"
resolved "https://registry.yarnpkg.com/@cspotcode/source-map-consumer/-/source-map-consumer-0.8.0.tgz#33bf4b7b39c178821606f669bbc447a6a629786b"
Expand All @@ -47,6 +42,11 @@
dependencies:
"@cspotcode/source-map-consumer" "0.8.0"

"@discoveryjs/json-ext@^0.5.0":
version "0.5.3"
resolved "https://registry.npmjs.org/@discoveryjs/json-ext/-/json-ext-0.5.3.tgz"
integrity sha512-Fxt+AfXgjMoin2maPIYzFZnQjAXjAL0PHscM5pRTtatFqB+vZxAM9tLp2Optnuw3QOQC40jTNeGYFOMvyf7v9g==

"@eslint/eslintrc@^0.4.3":
version "0.4.3"
resolved "https://registry.npmjs.org/@eslint/eslintrc/-/eslintrc-0.4.3.tgz"
Expand Down Expand Up @@ -167,6 +167,11 @@
resolved "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.8.tgz"
integrity sha512-YSBPTLTVm2e2OoQIDYx8HaeWJ5tTToLH67kXR7zYNGupXMEHa2++G8k+DczX2cFVgalypqtyZIcU19AFcmOpmg==

"@types/node@*":
version "16.10.1"
resolved "https://registry.yarnpkg.com/@types/node/-/node-16.10.1.tgz#f3647623199ca920960006b3dccf633ea905f243"
integrity sha512-4/Z9DMPKFexZj/Gn3LylFgamNKHm4K3QDi0gz9B26Uk0c8izYf97B5fxfpspMNkWlFupblKM/nV8+NA9Ffvr+w==

"@types/node@14.17.10":
version "14.17.10"
resolved "https://registry.yarnpkg.com/@types/node/-/node-14.17.10.tgz#93f4b095af275a0427114579c10ec7aa696729d7"
Expand Down Expand Up @@ -409,7 +414,12 @@ acorn@^8.4.1:
resolved "https://registry.yarnpkg.com/acorn/-/acorn-8.4.1.tgz#56c36251fc7cabc7096adc18f05afe814321a28c"
integrity sha512-asabaBSkEKosYKMITunzX177CXxQ4Q8BSSzMTKD+FefUhipQC70gfW5SiUDhYQ3vk8G+81HqQk7Fv9OXwwn9KA==

ajv@^6.10.0, ajv@^6.12.4:
ajv-keywords@^3.5.2:
version "3.5.2"
resolved "https://registry.yarnpkg.com/ajv-keywords/-/ajv-keywords-3.5.2.tgz#31f29da5ab6e00d1c2d329acf7b5929614d5014d"
integrity sha512-5p6WTN0DdTGVQk6VjcEju19IgaHudalcfabD7yhDGeA6bcQnmL+CpveLJq/3hvfwd1aof6L386Ougkx6RfyMIQ==

ajv@^6.10.0, ajv@^6.12.4, ajv@^6.12.5:
version "6.12.6"
resolved "https://registry.npmjs.org/ajv/-/ajv-6.12.6.tgz"
integrity sha512-j3fVLgvTo527anyYyJOGTYJbG+vnnQYvE0m5mmkc1TK+nxAppkCLMIL0aZ4dblVCNoGShhm+kzE4ZUykBoMg4g==
Expand Down Expand Up @@ -3975,14 +3985,14 @@ source-map-resolve@^0.5.0:
source-map-url "^0.4.0"
urix "^0.1.0"

source-map-support@^0.5.17, source-map-support@~0.5.19:
source-map-support@~0.5.19:
version "0.5.19"
resolved "https://registry.npmjs.org/source-map-support/-/source-map-support-0.5.19.tgz"
integrity sha512-Wonm7zOCIJzBGQdB+thsPar0kYuCIzYvxZwlBa87yi/Mdjv7Tip2cyVbLj5o0cFPN4EVkuTwb3GDDyUx2DGnGw==
dependencies:
buffer-from "^1.0.0"
source-map "^0.6.0"

source-map-url@^0.4.0:
version "0.4.0"
resolved "https://registry.npmjs.org/source-map-url/-/source-map-url-0.4.0.tgz"
Expand All @@ -4002,7 +4012,7 @@ source-map@~0.7.2:
version "0.7.3"
resolved "https://registry.npmjs.org/source-map/-/source-map-0.7.3.tgz"
integrity sha512-CkCj6giN3S+n9qrYiBTX5gystlENnRW5jZeNLHpe6aue+SrHcG5VYwujhW9s4dY31mEGsxBDrHR6oI69fTXsaQ==

split-string@^3.0.1, split-string@^3.0.2:
version "3.1.0"
resolved "https://registry.npmjs.org/split-string/-/split-string-3.1.0.tgz"
Expand Down

0 comments on commit f64c3cd

Please sign in to comment.