Skip to content

Commit

Permalink
Merge pull request #16 from meowtec/dev
Browse files Browse the repository at this point in the history
fix update and apply Dutch translation
  • Loading branch information
meowtec authored Jul 16, 2017
2 parents a37ab2d + db8f83e commit a2201b0
Show file tree
Hide file tree
Showing 11 changed files with 42 additions and 19 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ For Windows and macOS, download the binary below:
- Cross platform
- Visual
- Batch optimization
- i18n (简体中文, English)
- i18n (English, 简体中文, Nederlands)

## Built on

Expand Down
11 changes: 9 additions & 2 deletions modules/backend/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,13 @@ import __ from '../locales'
type BrowserWindow = Electron.BrowserWindow

class Controller {
windows: number[] = []
menu = menuManager
private windows: number[] = []
private menu = menuManager
private readyHook: () => void

ready = new Promise((resolve) => {
this.readyHook = resolve
})

start() {
const shouldQuit = app.makeSingleInstance(this.onOtherInstance)
Expand Down Expand Up @@ -155,6 +160,8 @@ class Controller {
menu.aloneMode = state.aloneMode
menu.render()
})

ipcMain.on(IpcChannel.READY, this.readyHook)
}
}

Expand Down
16 changes: 11 additions & 5 deletions modules/backend/menu-actions.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as os from 'os'
import { Menu, dialog, shell } from 'electron'
import { EventEmitter } from 'events'
import controller from './controller'
Expand All @@ -19,6 +20,15 @@ export const about = () => {
}

export const open = () => {
const properties = [
'openFile',
'multiSelections',
]

if (os.platform() === 'darwin') {
properties.push('openDirectory')
}

dialog.showOpenDialog({
title: __('choose_images'),
filters: [{
Expand All @@ -28,11 +38,7 @@ export const open = () => {
'png',
],
}],
properties: [
'openFile',
'openDirectory',
'multiSelections',
],
properties: properties as any,
}, filePaths => {
controller.receiveFiles(filePaths)
})
Expand Down
4 changes: 2 additions & 2 deletions modules/backend/updater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ autoUpdater.autoDownload = false

autoUpdater.on('update-available', (info: IUpdateInfo) => {
log.info('update available', info.version, info.path)
setTimeout(() => {
controller.ready.then(() => {
const win = controller.getMainWindow()
if (win) {
win.webContents.send(IpcChannel.APP_UPDATE, info)
}
}, 2000)
})
})

export default autoUpdater
1 change: 1 addition & 0 deletions modules/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export const IpcChannel = Enum(
'SAVED',
'SYNC',
'APP_UPDATE',
'READY',
)
export type IpcChannel = Enum<typeof IpcChannel>

Expand Down
2 changes: 1 addition & 1 deletion modules/locales/en-US.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ export default {
ok: 'OK',
before_optimized: 'before',
after_optimized: 'after',
new_version: 'New version available',
new_version: 'Upgrade',
}
16 changes: 11 additions & 5 deletions modules/locales/index.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,29 @@
import { app } from 'electron'
import createLocale, { Gettext } from '../common/i18n'
import zh_CN from './zh-CN'
import en_US from './en-US'
import zh_CN from './zh-CN'
import nl_NL from './nl-NL'

const texts = {
'zh-CN': zh_CN,
'en-US': en_US,
'nl-NL': nl_NL,
}

let gettext: Gettext

// get os language in main or renderer
export const setup = () => {
const locale = app ? app.getLocale() : navigator.language
gettext = createLocale(texts, {}, 'en-US', locale)
// const locale = app ? app.getLocale() : navigator.language
const locale = 'nl-TW'
gettext = createLocale(texts, {
zh: 'zh-CN',
nl: 'nl-NL',
}, 'en-US', locale)
}

// renderer will auto setup
// main process should call setup on app ready
// renderer process: auto setup
// main process: should call setup on app ready
if (!app) {
setup()
}
Expand Down
1 change: 0 additions & 1 deletion modules/renderer/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import List from './containers/List'
import ActionBar from './containers/ActionBar'
import Alone from './containers/Alone'
import { prevent } from './utils/dom-event'
import { IpcChannel } from '../common/constants'
import store from './store/store'
import * as apis from './apis'

Expand Down
4 changes: 4 additions & 0 deletions modules/renderer/Index.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { ipcRenderer } from 'electron'
import * as React from 'react'
import * as ReactDOM from 'react-dom'
import { AppContainer } from 'react-hot-loader'
import store from './store/store'
import App from './App'
import { IpcChannel } from '../common/constants'

if (process.env.NODE_ENV === 'development') {
const render = () => {
Expand All @@ -26,3 +28,5 @@ if (process.env.NODE_ENV === 'development') {
document.getElementById('app'),
)
}

ipcRenderer.send(IpcChannel.READY)
2 changes: 1 addition & 1 deletion modules/renderer/containers/ActionBar.less
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
background: none;
border: 0;
outline: none;
width: 60px;
width: 80px;

.icon, span {
transition: all .2s;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Imagine",
"version": "0.1.3",
"version": "0.1.4",
"description": "pngquant gui",
"homepage": "https://github.com/meowtec/Imagine",
"main": "./lib/bootstrap.js",
Expand Down

0 comments on commit a2201b0

Please sign in to comment.