Skip to content

Commit

Permalink
Merge pull request #7 from FiercestT/Update-1.2.1
Browse files Browse the repository at this point in the history
Update 1.2.1
  • Loading branch information
FiercestT authored Dec 9, 2021
2 parents 07240c0 + 79b9dfa commit d527ced
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 30 deletions.
51 changes: 28 additions & 23 deletions extension/easyeda-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Stolen with love and modified from https://github.com/xsrf/easyeda-svg-import <3
*/

const releasesUrl = 'https://github.com/FiercestT/EasyEdaThemes/releases/latest'
const extensionId = Object.entries(easyeda.extension.instances).filter(e => e[1].blobURLs && e[1].blobURLs['manifest.json'] == api('getRes',{file:'manifest.json'}))[0][1].id;
const instance = easyeda.extension.instances[extensionId];

Expand Down Expand Up @@ -77,36 +78,40 @@ instance.Helper = class Helper
(async ()=>{
try {
if(!('version' in instance.manifest)) return;
if(!('homepage' in instance.manifest)) return;
if(!('updatebaseurl' in instance.manifest)) return;
var skipVersion = this.getValue('update-skip', instance.manifest.version);
var cmdUpdatePage = this.createCommand(()=>{ window.open(instance.manifest.homepage,'_blank') });
var cmdUpdateSkip = this.createCommand(()=>{ this.setConfig('update-skip',skipVersion) });
var response = await fetch(instance.manifest.updatebaseurl + 'manifest.json');
if(response.status != 200) {
console.log('Update check failed, Status: ' + response.status);
return;
}
var onlineManifest = await response.json();
if(onlineManifest.version == instance.manifest.version) {
console.log(`Update check ok, "${extensionId}" is up to date`);
return;
}
if(onlineManifest.version == skipVersion) {
console.log(`Update check ok, "${extensionId}" is not up to date but version is skipped`);
return;

let data = await (await fetch('https://api.github.com/repos/FiercestT/EasyEdaThemes/releases/latest')).json()
let latestVersion = data["tag_name"].match(/(\d\.)+\d/g)
let curVersion = instance.manifest.version

//Semantic version check

let latest = latestVersion[0].split('.')
let cur = curVersion.split('.')
let needsUpdate = false

for(let i = 0; i < latest.length; i++)
{
if(parseFloat(`0.${latest[i] || 0}`) > parseFloat(`0.${cur[i] || 0}`))
{
needsUpdate = true
break
}
}
console.log(`Update check ok, "${extensionId}" is not up to date`);
skipVersion = onlineManifest.version;

if(!needsUpdate)
return

var updateCmd = this.createCommand('updateVersion', ()=>{ window.open(releasesUrl,'_blank') });

$.messager.show({
title: `Update Available for <b>${instance.manifest.name}</b>`,
msg: `<table>
<tr><td>Installed:</td><td>${instance.manifest.name} ${instance.manifest.version}</td></tr>
<tr><td>Available:</td><td>${onlineManifest.name} ${onlineManifest.version}</td></tr>
<tr><td>Available:</td><td>${latestVersion}</td></tr>
</table>
<div class="dialog-button">
<a tabindex="0" cmd="${cmdUpdatePage};dialog-close" class="l-btn"><span class="l-btn-left"><span class="l-btn-text i18n">Download</span></span></a>
<a tabindex="0" cmd="${cmdUpdateSkip};dialog-close" class="l-btn"><span class="l-btn-left"><span class="l-btn-text i18n">Skip Version</span></span></a>
<a tabindex="0" cmd="${updateCmd};dialog-close" class="l-btn"><span class="l-btn-left"><span class="l-btn-text i18n">Download</span></span></a>
<a tabindex="0" cmd="dialog-close" class="l-btn"><span class="l-btn-left"><span class="l-btn-text i18n">Close</span></span></a>
</div>
`,
height: 'auto',
Expand Down
7 changes: 3 additions & 4 deletions extension/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ main();

async function main()
{
Helper.checkUpdate()

_themes = await Helper.loadFile('themes.json', Helper.fileTypes.JSON)
_css = await Helper.loadFile("style.txt", Helper.fileTypes.TEXT)

Expand All @@ -38,7 +40,6 @@ async function main()
cb_ApplyTheme(Helper.getValue(STOREID.LAST_THEME, getDefaultTheme())) //Apply last theme from storage or use default
}


///Applies the theme based on the passed theme name according to its name in 'THEMES' below
function cb_ApplyTheme(themeName)
{
Expand All @@ -57,9 +58,7 @@ function cb_ApplyTheme(themeName)

setEditorTheme(theme)

let selected = $('#theme_selected_checkmark') //Update the checkmark on the active theme
if(selected)
selected.remove();
$("div[id*='theme_selected_checkmark'").each((i, el) => el.remove()) //Update the checkmark on the active theme, remove all previous checkmarks.
$(`div[cmd="${getCommandId(`${COMMANDID.APPLY_THEME}(${themeName})`)}"]`).prepend('<div id="theme_selected_checkmark" class="menu-icon icon-selected"/>')

_activeTheme = themeName
Expand Down
2 changes: 1 addition & 1 deletion extension/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "EasyEda Themer",
"description": "Customize the EasyEda UI and editors. Made by Fiercest: https://github.com/FiercestT",
"author": "Fiercest",
"version": "1.1",
"version": "1.2.1",
"homepage": "https://github.com/FiercestT/EasyEdaThemes",
"scripts": [
"easyeda-helper.js",
Expand Down
16 changes: 16 additions & 0 deletions extension/style.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1030,4 +1030,20 @@ menu-icon.icon-selected {

.gray-border {
border: 1px solid var(--Contrast) !important;
}

.icon-eda-project {
color: var(--Accent_Color) !important;
}

.custom {
background: var(--Background) !important;
}

.tree-node:not(.tree-node-selected)>.tree-icon.icon-eda-eelib, .tree-node:not(.tree-node-selected)>.tree-icon.icon-eda-sch {
color: var(--Operators_Color) !important;
}

.tree-node:not(.tree-node-selected)>.tree-icon.icon-eda-pcb {
color: var(--Strings_Color) !important;
}
18 changes: 16 additions & 2 deletions extra/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,8 @@ a:-webkit-any-link {

/* Main */

@import url('https://fonts.googleapis.com/css?family=Roboto&display=swap');
body
{
font-family: 'Roboto' !important;
color: var(--Text) !important;
background: var(--Background) !important;
font-family: 'Roboto', sans-serif;
Expand Down Expand Up @@ -1032,4 +1030,20 @@ menu-icon.icon-selected {

.gray-border {
border: 1px solid var(--Contrast) !important;
}

.icon-eda-project {
color: var(--Accent_Color) !important;
}

.custom {
background: var(--Background) !important;
}

.tree-node:not(.tree-node-selected)>.tree-icon.icon-eda-eelib, .tree-node:not(.tree-node-selected)>.tree-icon.icon-eda-sch {
color: var(--Operators_Color) !important;
}

.tree-node:not(.tree-node-selected)>.tree-icon.icon-eda-pcb {
color: var(--Strings_Color) !important;
}

0 comments on commit d527ced

Please sign in to comment.