diff --git a/README.md b/README.md index 9e15938..c4f4b7a 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ For Windows and macOS, download the binary below: - Cross platform - Visual - Batch optimization - - i18n (简体中文, English) + - i18n (English, 简体中文, Nederlands) ## Built on diff --git a/modules/backend/controller.ts b/modules/backend/controller.ts index e5e63ca..aa6dc0a 100644 --- a/modules/backend/controller.ts +++ b/modules/backend/controller.ts @@ -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) @@ -155,6 +160,8 @@ class Controller { menu.aloneMode = state.aloneMode menu.render() }) + + ipcMain.on(IpcChannel.READY, this.readyHook) } } diff --git a/modules/backend/menu-actions.ts b/modules/backend/menu-actions.ts index 51a9aad..6ba7312 100644 --- a/modules/backend/menu-actions.ts +++ b/modules/backend/menu-actions.ts @@ -1,3 +1,4 @@ +import * as os from 'os' import { Menu, dialog, shell } from 'electron' import { EventEmitter } from 'events' import controller from './controller' @@ -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: [{ @@ -28,11 +38,7 @@ export const open = () => { 'png', ], }], - properties: [ - 'openFile', - 'openDirectory', - 'multiSelections', - ], + properties: properties as any, }, filePaths => { controller.receiveFiles(filePaths) }) diff --git a/modules/backend/updater.ts b/modules/backend/updater.ts index 6bff688..ac8e0a1 100644 --- a/modules/backend/updater.ts +++ b/modules/backend/updater.ts @@ -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 diff --git a/modules/common/constants.ts b/modules/common/constants.ts index 83e42b5..a836f2e 100644 --- a/modules/common/constants.ts +++ b/modules/common/constants.ts @@ -15,6 +15,7 @@ export const IpcChannel = Enum( 'SAVED', 'SYNC', 'APP_UPDATE', + 'READY', ) export type IpcChannel = Enum diff --git a/modules/locales/en-US.ts b/modules/locales/en-US.ts index 4c3053e..0ecda47 100644 --- a/modules/locales/en-US.ts +++ b/modules/locales/en-US.ts @@ -18,5 +18,5 @@ export default { ok: 'OK', before_optimized: 'before', after_optimized: 'after', - new_version: 'New version available', + new_version: 'Upgrade', } diff --git a/modules/locales/index.ts b/modules/locales/index.ts index a76a2c3..cf33ec6 100644 --- a/modules/locales/index.ts +++ b/modules/locales/index.ts @@ -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() } diff --git a/modules/renderer/App.tsx b/modules/renderer/App.tsx index 8fd880e..1f34363 100644 --- a/modules/renderer/App.tsx +++ b/modules/renderer/App.tsx @@ -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' diff --git a/modules/renderer/Index.tsx b/modules/renderer/Index.tsx index 3714206..d14c210 100644 --- a/modules/renderer/Index.tsx +++ b/modules/renderer/Index.tsx @@ -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 = () => { @@ -26,3 +28,5 @@ if (process.env.NODE_ENV === 'development') { document.getElementById('app'), ) } + +ipcRenderer.send(IpcChannel.READY) diff --git a/modules/renderer/containers/ActionBar.less b/modules/renderer/containers/ActionBar.less index 7fac4ab..707d0af 100644 --- a/modules/renderer/containers/ActionBar.less +++ b/modules/renderer/containers/ActionBar.less @@ -14,7 +14,7 @@ background: none; border: 0; outline: none; - width: 60px; + width: 80px; .icon, span { transition: all .2s; diff --git a/package.json b/package.json index a30821f..eba187e 100644 --- a/package.json +++ b/package.json @@ -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",