1
0
Fork 0
mirror of https://github.com/anyproto/anytype-ts.git synced 2025-06-08 05:57:02 +09:00
This commit is contained in:
Andrew Simachev 2021-03-30 15:37:07 +03:00
commit 856795ba0b
11 changed files with 107 additions and 68 deletions

View file

@ -17,17 +17,21 @@ const port = process.env.SERVER_PORT;
const openAboutWindow = require('about-window').default;
const keytar = require('keytar');
const bindings = require('bindings');
const envPath = path.join(__dirname, 'electron', 'env.json');
const TIMEOUT_UPDATE = 600 * 1000;
const MIN_WIDTH = 980;
const MIN_HEIGHT = 640;
const KEYTAR_SERVICE = 'Anytype';
let env = {};
try { env = JSON.parse(fs.readFileSync(envPath)); } catch (e) {};
let isUpdating = false;
let userPath = app.getPath('userData');
let tmpPath = path.join(userPath, 'tmp');
let waitLibraryPromise;
let useGRPC = !process.env.ANYTYPE_USE_ADDON && (process.env.ANYTYPE_USE_GRPC || (process.platform == "win32") || is.development);
let useGRPC = !process.env.ANYTYPE_USE_ADDON && (env.USE_GRPC || process.env.ANYTYPE_USE_GRPC || (process.platform == "win32") || is.development);
let defaultChannel = version.match('alpha') ? 'alpha' : 'latest';
let timeoutUpdate = 0;
let server;
@ -108,7 +112,7 @@ function trayIcon () {
if (is.windows) {
return path.join(__dirname, '/electron/icon64x64.png');
} else {
const dark = nativeTheme.shouldUseDarkColors;
const dark = nativeTheme.shouldUseDarkColors || nativeTheme.shouldUseHighContrastColors || nativeTheme.shouldUseInvertedColorScheme;
return path.join(__dirname, '/electron/icon-tray-' + (dark ? 'white' : 'black') + '.png');
};
};
@ -579,6 +583,7 @@ function autoUpdaterInit () {
autoUpdater.autoDownload = false;
autoUpdater.channel = config.channel;
clearTimeout(timeoutUpdate);
timeoutUpdate = setTimeout(() => { checkUpdate(true); }, TIMEOUT_UPDATE);
autoUpdater.on('checking-for-update', () => {
@ -627,7 +632,6 @@ function autoUpdaterInit () {
isUpdating = false;
Util.log('info', 'Update downloaded: ' + JSON.stringify(info, null, 3));
send('update-downloaded');
app.isQuiting = true;
exit(true);
});
};
@ -655,10 +659,14 @@ app.on('window-all-closed', (e) => {
});
app.on('before-quit', (e) => {
e.preventDefault();
Util.log('info', 'before-quit');
exit(false);
if (app.isQuiting) {
exit(0);
} else {
e.preventDefault();
exit(false);
};
});
app.on('activate', () => {
@ -666,23 +674,33 @@ app.on('activate', () => {
});
function send () {
console.log('SEND', arguments);
if (win) {
win.webContents.send.apply(win.webContents, arguments);
};
};
function shutdown (relaunch) {
Util.log('info', 'Shutdown, relaunch: ' + relaunch);
setTimeout(() => {
if (relaunch) {
Util.log('info', 'Relaunch');
app.relaunch();
app.isQuiting = true;
autoUpdater.quitAndInstall();
} else {
app.exit(0);
};
app.exit(0);
}, 2000);
}, 3000);
};
function exit (relaunch) {
Util.log('info', 'MW shutdown is starting');
if (app.isQuiting) {
return;
};
Util.log('info', 'MW shutdown is starting, relaunch: ' + relaunch);
if (useGRPC) {
if (server) {
@ -693,7 +711,7 @@ function exit (relaunch) {
} else {
Util.log('warn', 'MW server not set');
shutdown(relaunch);
}
};
} else {
send('shutdown', relaunch);
};