Skip to content
This repository has been archived by the owner on Apr 29, 2022. It is now read-only.

Commit

Permalink
Fix Mac App Store build crashes at launch (#55)
Browse files Browse the repository at this point in the history
  • Loading branch information
quanglam2807 authored Aug 13, 2019
1 parent cfa1ea6 commit 581b995
Show file tree
Hide file tree
Showing 8 changed files with 312 additions and 239 deletions.
Binary file not shown.
8 changes: 8 additions & 0 deletions build-resources/extendedInfo.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>LSMultipleInstancesProhibited</key>
<true/>
</dict>
</plist>
2 changes: 1 addition & 1 deletion docs/support.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ <h1>Translatium Support</h1>
<h3>Frequently Asked Questions (FAQs) </h3>
<p><b>How many languages does Translatim support?</b><br/>You can find the list of supported languages <a href="/languages">here</a>.</p>
<p><b>Does Translatium support PopClip?</b><br/>Yes, it does. You can download the PopClip extension from <a href="/popclip">here</a>.</p>
<p><b>Why speech recognition and some other features are removed?</b><br/>On November 7th, 2018, Translatium was removed from sale because the unofficial Google Translate <a href="https://en.wikipedia.org/wiki/Application_programming_interface">APIs</a> the app relies on was partially blocked by Google. In August 2019, we managed to bring the app back to life using legitimate APIs from other providers. While this decision allows the app to continue operating, it also forces us to remove certain features from the app. Still, we will try to add back the features in the future if possible.</p>
<p><b>Why speech recognition and some other features are removed?</b><br/>On November 7th, 2018, Translatium was removed from sale because the unofficial Google Translate <a href="https://en.wikipedia.org/wiki/Application_programming_interface">APIs</a> the app relied on were partially blocked by Google. In August 2019, we managed to bring the app back to life using legitimate APIs from other providers. While this decision allows the app to continue operating, it also forces us to remove certain features from the app. Still, we will try to add these features back in the future if possible.</p>
</div>
</div>
</section>
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"cross-env": "5.2.0",
"del": "5.0.0",
"electron": "5.0.9",
"electron-builder": "21.2.0",
"electron-builder": "20.44.4",
"eslint": "5.16.0",
"eslint-config-airbnb": "17.1.1",
"eslint-plugin-import": "2.18.2",
Expand Down
3 changes: 3 additions & 0 deletions packager.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const appVersion = fs.readJSONSync(path.join(__dirname, 'package.json')).version
let targets;
switch (process.platform) {
case 'darwin': {
// targets = Platform.MAC.createTarget(['mas-dev']);
targets = Platform.MAC.createTarget(['mas']);
break;
}
Expand Down Expand Up @@ -65,7 +66,9 @@ const opts = {
category: 'public.app-category.productivity',
entitlements: 'build-resources/entitlements.mas.plist',
entitlementsInherit: 'build-resources/entitlements.mas.inherit.plist',
// provisioningProfile: 'build-resources/embedded-development.provisionprofile',
provisioningProfile: 'build-resources/embedded.provisionprofile',
extendInfo: 'build-resources/Info.plist',
},
linux: {
category: 'Utility',
Expand Down
223 changes: 102 additions & 121 deletions public/electron.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,143 +29,124 @@ app.setAsDefaultProtocolClient('translatium');
let mb;
let mainWindow;

const gotTheLock = app.requestSingleInstanceLock();
// Load listeners
loadListeners();

app.on('second-instance', () => {
const REACT_PATH = isDev ? 'http://localhost:3000' : `file://${path.resolve(__dirname, 'index.html')}`;

const createWindow = () => {
const attachToMenubar = getPreference('attachToMenubar');
if (attachToMenubar) {
if (mb && mb.window) {
if (mb.window.isMinimized()) mb.window.restore();
mb.window.focus();
}
} else if (mainWindow) {
if (mainWindow.isMinimized()) mainWindow.restore();
mainWindow.focus();
mb = menubar({
index: REACT_PATH,
icon: path.resolve(__dirname, 'images', 'menubar-icon.png'),
preloadWindow: true,
browserWindow: {
webPreferences: {
nodeIntegration: true,
},
},
});

const contextMenu = Menu.buildFromTemplate([
{ role: 'about' },
{ type: 'separator' },
{
label: 'Preferences...',
click: () => ipcMain.emit('go-to-preferences'),
},
{ type: 'separator' },
{
label: 'Quit',
click: () => {
mb.app.quit();
},
},
]);

mb.on('ready', () => {
mb.tray.on('right-click', () => {
mb.tray.popUpContextMenu(contextMenu);
});
});
} else {
// Create the browser window.
mainWindow = new BrowserWindow({
width: 500,
height: 600,
minWidth: 320,
minHeight: 500,
titleBarStyle: 'hidden',
autoHideMenuBar: true,
webPreferences: {
nodeIntegration: true,
webSecurity: false,
},
});

// and load the index.html of the app.
mainWindow.loadURL(REACT_PATH);

// Emitted when the window is closed.
mainWindow.on('closed', () => {
// Dereference the window object, usually you would store windows
// in an array if your app supports multi windows, this is the time
// when you should delete the corresponding element.
mainWindow = null;
createMenu();
});
}
};

// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.on('ready', () => {
createWindow();
createMenu();
});

if (!gotTheLock) {
// Quit when all windows are closed.
app.on('window-all-closed', () => {
app.quit();
} else {
// Load listeners
loadListeners();

const REACT_PATH = isDev ? 'http://localhost:3000' : `file://${path.resolve(__dirname, 'index.html')}`;

const createWindow = () => {
const attachToMenubar = getPreference('attachToMenubar');
if (attachToMenubar) {
mb = menubar({
index: REACT_PATH,
icon: path.resolve(__dirname, 'images', 'menubar-icon.png'),
preloadWindow: true,
browserWindow: {
webPreferences: {
nodeIntegration: true,
},
},
});
});

const contextMenu = Menu.buildFromTemplate([
{ role: 'about' },
{ type: 'separator' },
{
label: 'Preferences...',
click: () => ipcMain.emit('go-to-preferences'),
},
{ type: 'separator' },
{
label: 'Quit',
click: () => {
mb.app.quit();
},
},
]);
app.on('activate', () => {
// On OS X it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
const attachToMenubar = getPreference('attachToMenubar');

mb.on('ready', () => {
mb.tray.on('right-click', () => {
mb.tray.popUpContextMenu(contextMenu);
});
});
if (attachToMenubar) {
if (mb == null) {
createWindow();
} else {
// Create the browser window.
mainWindow = new BrowserWindow({
width: 500,
height: 600,
minWidth: 320,
minHeight: 500,
titleBarStyle: 'hidden',
autoHideMenuBar: true,
webPreferences: {
nodeIntegration: true,
webSecurity: false,
},
});

// and load the index.html of the app.
mainWindow.loadURL(REACT_PATH);

// Emitted when the window is closed.
mainWindow.on('closed', () => {
// Dereference the window object, usually you would store windows
// in an array if your app supports multi windows, this is the time
// when you should delete the corresponding element.
mainWindow = null;
createMenu();
mb.on('ready', () => {
mb.showWindow();
});
}
};

// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.on('ready', () => {
} else if (mainWindow == null) {
createWindow();
createMenu();
});
} else {
mainWindow.show();
}
});

// Quit when all windows are closed.
app.on('window-all-closed', () => {
app.quit();
});
app.on('open-url', (e, urlStr) => {
e.preventDefault();

app.on('activate', () => {
// On OS X it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
const attachToMenubar = getPreference('attachToMenubar');
if (urlStr.startsWith('translatium://')) {
const urlObj = url.parse(urlStr, true);
const text = decodeURIComponent(urlObj.query.text || '');

const attachToMenubar = getPreference('attachToMenubar');
if (attachToMenubar) {
if (mb == null) {
createWindow();
} else {
mb.on('ready', () => {
mb.showWindow();
});
}
} else if (mainWindow == null) {
createWindow();
} else {
mainWindow.show();
}
});

app.on('open-url', (e, urlStr) => {
e.preventDefault();

if (urlStr.startsWith('translatium://')) {
const urlObj = url.parse(urlStr, true);
const text = decodeURIComponent(urlObj.query.text || '');

const attachToMenubar = getPreference('attachToMenubar');
if (attachToMenubar) {
if (mb && mb.window) {
mb.window.send('set-input-lang', 'auto');
mb.window.send('set-input-text', text);
}
} else if (mainWindow) {
mainWindow.send('set-input-lang', 'auto');
mainWindow.send('set-input-text', text);
if (mb && mb.window) {
mb.window.send('set-input-lang', 'auto');
mb.window.send('set-input-text', text);
}
} else if (mainWindow) {
mainWindow.send('set-input-lang', 'auto');
mainWindow.send('set-input-text', text);
}
});
}
}
});
1 change: 1 addition & 0 deletions src/components/pages/preferences/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ const Preferences = (props) => {
</ListItem>
{window.process.platform === 'darwin' && (
<React.Fragment>
<Divider />
<ListItem
button
onClick={() => remote.shell.openExternal('https://translatiumapp.com/popclip')}
Expand Down
Loading

0 comments on commit 581b995

Please sign in to comment.