Skip to content

Commit

Permalink
Merge pull request #301 from ungjinPark/main
Browse files Browse the repository at this point in the history
Refactoring and add new features
  • Loading branch information
ferllings authored Jul 21, 2023
2 parents e30f3e7 + 37fc9a6 commit 595b528
Show file tree
Hide file tree
Showing 21 changed files with 319 additions and 149 deletions.
57 changes: 38 additions & 19 deletions src/CCAcontroller.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class CCAController {
hexColor = await getColorFromPickerAddOn()
.catch((error) => {
console.warn(`[ERROR] getColorFromPickerAddOn`, error)
})
})
this.receivedColorFromPicker(event, section, hexColor)
} else { // Electron picker
this.sendEventToAll('showPicker', section)
Expand All @@ -106,11 +106,11 @@ class CCAController {
if (component === 'alpha') {
value = parseFloat(value)
if (value > 1) value = 1
if (value < 0) value = 0
if (value < 0) value = 0
} else {
value = parseInt(value)
if (value > 255) value = 255
if (value < 0) value = 0
if (value < 0) value = 0
}

let color = this.sharedObject[`general.${section}Color`]
Expand All @@ -123,7 +123,7 @@ class CCAController {
dist = value - color.green()
} else if (component === "blue") {
dist = value - color.blue()
}
}
let red = color.red()
if ((red + dist) > 255) {
dist -= red + dist - 255
Expand Down Expand Up @@ -155,7 +155,7 @@ class CCAController {
color = color.blue(value)
} else if (component === "alpha") {
color = color.alpha(value)
}
}
}
this.sharedObject[`general.${section}Color`] = color
this.updateGlobal(section)
Expand Down Expand Up @@ -253,8 +253,8 @@ class CCAController {
this.updateDeficiency("foreground")
this.updateDeficiency("background")
this.updateContrastRatio()
this.updateColor('foreground')
this.updateColor('background')
this.updateColor('foreground')
this.updateColor('background')
}

updateDeficiency(section) {
Expand Down Expand Up @@ -321,7 +321,7 @@ class CCAController {
if (cr < 3) {
this.sharedObject['general.levelAA'] = 'fail'
}

const object = {
levelAA: this.sharedObject['general.levelAA'],
levelAAA: this.sharedObject['general.levelAAA'],
Expand All @@ -343,7 +343,7 @@ class CCAController {
this.sendEventToAll('contrastRatioChanged', object)
}

async copyResults() {
async copyResults(template) {
let level_1_4_3, level_1_4_6, level_1_4_11
const levelAA = this.sharedObject['general.levelAA']
const levelAAA = this.sharedObject['general.levelAAA']
Expand Down Expand Up @@ -378,19 +378,38 @@ class CCAController {
const crr = Number(cr.toFixed(rounding)).toLocaleString(i18n.lang)
// toLocalString removes trailing zero and use the correct decimal separator, based on the app select lang.

let text = `${t.CopyPaste["Foreground"]}: ${foregroundColorString}
${t.CopyPaste["Background"]}: ${backgroundColorString}
${t.Main["Contrast ratio"]}: ${crr}:1
${t.Main["1.4.3 Contrast (Minimum) (AA)"]}
${level_1_4_3}
${t.Main["1.4.6 Contrast (Enhanced) (AAA)"]}
${level_1_4_6}
${t.Main["1.4.11 Non-text Contrast (AA)"]}
${level_1_4_11}`
let text = template
for (const item of [
['%f.hex%', foregroundColorString],
['%b.hex%', backgroundColorString],
['%cr%', cr],
['%crr%', crr],
['%1.4.3%', level_1_4_3],
['%1.4.6%', level_1_4_6],
['%1.4.11%', level_1_4_11],
['%i18n.f%', t.CopyPaste["Foreground"]],
['%i18n.b%', t.CopyPaste["Background"]],
['%i18n.cr%', t.Main["Contrast ratio"]],
['%i18n.1.4.3%', t.Main["1.4.3 Contrast (Minimum) (AA)"]],
['%i18n.1.4.6%', t.Main["1.4.6 Contrast (Enhanced) (AAA)"]],
['%i18n.1.4.11%', t.Main["1.4.11 Non-text Contrast (AA)"]],
]) {
text = text.replaceAll(item[0], item[1])
}

clipboard.writeText(text)
}

async copyRegularResults() {
const template = await this.store.get('copy.regularTemplate')
this.copyResults(template)
}

async copyShortResults() {
const template = await this.store.get('copy.shortTemplate')
this.copyResults(template)
}

updateShortcut(shortcut, oldValue, newValue) {
console.log(shortcut, oldValue, newValue)
if (oldValue) {
Expand All @@ -412,4 +431,4 @@ ${t.Main["1.4.11 Non-text Contrast (AA)"]}
}
}

module.exports = CCAController
module.exports = CCAController
4 changes: 2 additions & 2 deletions src/browsers/preferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ module.exports = (dirname) => {

let createWindow = (x, y) => {
win = new BrowserWindow({
width: 400,
height: 380,
width: 500,
height: 600,
x: x,
y: y,
resizable: false,
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/preferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module.exports = (browsers, store) => {
ipcMain.on('init-preferences', () => {
const i18n = new(require('../i18n'))(store.get('lang'))
let config = {
i18n: i18n.asObject().Preferences
i18n: i18n.asObject()
}
sendEvent('init', config)
})
Expand Down
33 changes: 32 additions & 1 deletion src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,37 @@ const schema = {
type: 'string',
default: "system"
},
copy: {
type: 'object',
properties: {
regularTemplate: {
type: 'string',
default: '%i18n.f%: %f.hex%\n\
%i18n.b%: %b.hex%\n\
%i18n.cr%: %cr%:1\n\
%i18n.1.4.3%\n\
%1.4.3%\n\
%i18n.1.4.6%\n\
%1.4.6%\n\
%i18n.1.4.11%\n\
%1.4.11%',
},
shortTemplate: {
type: 'string',
default: '%i18n.f%: %f.hex%\n\
%i18n.b%: %b.hex%\n\
%i18n.cr%: %cr%:1',
},
},
default: {}
// Replaced on first modification, to match the user lang.
//%i18n.f% : "Foreground"
//%i18n.b% : "Background"
//%i18n.cr% : "Contrast ratio"
//%i18n.1.4.3% : "1.4.3 Contrast (Minimum)"
//%i18n.1.4.6% : "1.4.6 Contrast (Enhanced)"
//%i18n.1.4.11% : "1.4.11 Non-text Contrast"
},
picker: {
type: 'integer',
default: (process.platform === 'win32' || process.platform === 'win64' || /^(msys|cygwin)$/.test(process.env.OSTYPE))?2:1, // Disable for Windows until https://github.com/electron/electron/issues/27980
Expand Down Expand Up @@ -226,4 +257,4 @@ function sendEventToAll(event, ...params) {
Object.keys(controllers).map(function(key, index) {
controllers[key].sendEvent(event, ...params)
})
}
}
42 changes: 25 additions & 17 deletions src/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,15 @@ module.exports = (browsers, mainController, prefs) => {
label: i18n.menuT('Copy results'),
accelerator: 'CmdOrCtrl+Shift+C',
click: (item) => {
mainController.copyResults()
mainController.copyRegularResults()
}
},
{
label: i18n.menuT('Copy short results'),
accelerator: 'CmdOrCtrl+Alt+C',
click: (item) => {
mainController.copyShortResults()
},
}
]
},
Expand Down Expand Up @@ -99,42 +106,43 @@ module.exports = (browsers, mainController, prefs) => {
},
{
label: i18n.menuT('Actual Size'),
accelerator: 'CmdOrCtrl+0',
click (item, focusedWindow) {
accelerator: 'CmdOrCtrl+0',
click (item, focusedWindow) {
if (focusedWindow) {
focusedWindow.webContents.setZoomLevel(0)
main.changeZoom(0)
}
}
}
},
{
label: i18n.menuT('Zoom In'),
accelerator: 'CmdOrCtrl+Plus',
click (item, focusedWindow) {
if (focusedWindow) {
const {webContents} = focusedWindow
accelerator: 'CmdOrCtrl+Plus',
click (item, focusedWindow) {
if (focusedWindow) {
const {webContents} = focusedWindow
zoomLevel = webContents.getZoomLevel()
webContents.setZoomLevel(zoomLevel + 0.5)
main.changeZoom(zoomLevel + 0.5)
}
}
}
}
},
{
label: i18n.menuT('Zoom Out'),
accelerator: 'CmdOrCtrl+-',
click (item, focusedWindow) {
if (focusedWindow) {
const {webContents} = focusedWindow
accelerator: 'CmdOrCtrl+-',
click (item, focusedWindow) {
if (focusedWindow) {
const {webContents} = focusedWindow
zoomLevel = webContents.getZoomLevel()
webContents.setZoomLevel(zoomLevel - 0.5)
webContents.setZoomLevel(zoomLevel - 0.5)
main.changeZoom(zoomLevel - 0.5)
}
}
}
}
}
]
},
{
label: i18n.menuT('Development'),

submenu: [
{
label: i18n.menuT('Reload'),
Expand Down
1 change: 1 addition & 0 deletions src/views/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ section#background-color .buttons {
right: 0.5rem;
}


/* Free text input */

section#foreground-color .container,
Expand Down
28 changes: 24 additions & 4 deletions src/views/css/preferences.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@ body {
}

.buttons {
display: inline-block;
position: absolute;
bottom: 1rem;
right: 1rem;
text-align: right;
margin: 1rem;
}

.option {
Expand All @@ -18,3 +16,25 @@ body {
.option select, .width-8 {
min-width: 8rem;
}

label.block {
display: block;
}

textarea {
width: 100%;
display: block;
}

#copy ul {
margin: 0 0 0.5rem 0;
padding: 0;
columns: 2;
-webkit-columns: 2;
-moz-columns: 2;
}

#copy ul li {
font-size: 0.8rem;
margin: 0 0 0 0.5rem;
}
Loading

0 comments on commit 595b528

Please sign in to comment.