-
Notifications
You must be signed in to change notification settings - Fork 10
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
6 changed files
with
96 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,47 @@ | ||
import { clientStorageKey, Config } from './modules/config'; | ||
import { CMD } from './modules/globals'; | ||
import { CMD, counter, messages, showNofication } from './modules/globals'; | ||
import { changeAllStyles, extractAllStyles, updateStyleNames } from './modules/styles'; | ||
|
||
let currentConfig; | ||
|
||
if (CMD === 'clear-cache') { | ||
figma.clientStorage.setAsync(clientStorageKey, undefined).then(() => { | ||
figma.closePlugin('🧹 Cleaned saved settings from cache.'); | ||
return; | ||
}); | ||
} | ||
// | ||
else { | ||
figma.clientStorage.getAsync(clientStorageKey).then((cachedSettings) => { | ||
currentConfig = new Config(cachedSettings); | ||
|
||
// creating layers based on styles | ||
if (CMD === 'extract-all-styles') { | ||
extractAllStyles(currentConfig); | ||
} | ||
|
||
// | ||
else if (CMD === 'customize-plugin') { | ||
figma.showUI(__html__, { width: 360, height: 480 }); | ||
figma.ui.postMessage(cachedSettings); | ||
} | ||
|
||
// | ||
else { | ||
changeAllStyles(currentConfig); | ||
} | ||
}); | ||
|
||
figma.ui.onmessage = (msg) => { | ||
if (msg.type === 'cancel-modal') { | ||
figma.closePlugin('🥺 Everything is as before.'); | ||
return; | ||
} | ||
|
||
// save | ||
else if (msg.type === 'save-settings') { | ||
figma.clientStorage.setAsync(clientStorageKey, msg.uiSettings).then(() => { | ||
let newConfig = new Config(msg.uiSettings); | ||
|
||
updateStyleNames(currentConfig, newConfig); | ||
figma.closePlugin(); | ||
return; | ||
}); | ||
} | ||
}; | ||
} | ||
figma.clientStorage.getAsync(clientStorageKey).then((cachedSettings) => { | ||
currentConfig = new Config(cachedSettings); | ||
|
||
if (CMD === 'clear-cache') { | ||
figma.clientStorage.setAsync(clientStorageKey, undefined).then(() => { | ||
showNofication(0, messages(counter).clearCache, currentConfig.notificationTimeout); | ||
}); | ||
} | ||
// creating layers based on styles | ||
else if (CMD === 'extract-all-styles') { | ||
extractAllStyles(currentConfig); | ||
} | ||
|
||
// | ||
else if (CMD === 'customize-plugin') { | ||
figma.showUI(__html__, { width: 360, height: 480 }); | ||
figma.ui.postMessage(cachedSettings); | ||
} | ||
|
||
// | ||
else { | ||
changeAllStyles(currentConfig); | ||
} | ||
}); | ||
|
||
figma.ui.onmessage = (msg) => { | ||
if (msg.type === 'cancel-modal') { | ||
showNofication(0, messages(counter).cancelSettings, currentConfig.notificationTimeout); | ||
} | ||
|
||
// save | ||
else if (msg.type === 'save-settings') { | ||
figma.clientStorage.setAsync(clientStorageKey, msg.uiSettings).then(() => { | ||
const newConfig = new Config(msg.uiSettings); | ||
|
||
updateStyleNames(currentConfig, newConfig); | ||
}); | ||
} else { | ||
figma.closePlugin('🤷♂️ This should not happen. Nothing was changed...'); | ||
} | ||
}; |
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
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
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