mirror of
https://github.com/anyproto/anytype-ts.git
synced 2025-06-08 05:57:02 +09:00
Merge branch 'master' of github.com:anytypeio/js-anytype into dataview
This commit is contained in:
commit
9d6547c2b3
73 changed files with 1806 additions and 570 deletions
75
electron.js
75
electron.js
|
@ -1,5 +1,5 @@
|
|||
const electron = require('electron');
|
||||
const { app, BrowserWindow, ipcMain, shell, Menu, session, Tray, nativeImage } = require('electron');
|
||||
const { app, BrowserWindow, ipcMain, shell, Menu, session, Tray, nativeImage, nativeTheme } = require('electron');
|
||||
const { is, fixPathForAsarUnpack } = require('electron-util');
|
||||
const { autoUpdater } = require('electron-updater');
|
||||
const { download } = require('electron-dl');
|
||||
|
@ -131,6 +131,30 @@ function waitForLibraryAndCreateWindows () {
|
|||
});
|
||||
};
|
||||
|
||||
function trayIcon () {
|
||||
if (is.windows) {
|
||||
return path.join(__dirname, '/electron/icon64x64.png');
|
||||
} else {
|
||||
const dark = nativeTheme.shouldUseDarkColors;
|
||||
return path.join(__dirname, '/electron/icon-tray-' + (dark ? 'white' : 'black') + '.png');
|
||||
};
|
||||
};
|
||||
|
||||
nativeTheme.on('updated', () => {
|
||||
tray.setImage(trayIcon());
|
||||
});
|
||||
|
||||
function initTray () {
|
||||
tray = new Tray (trayIcon());
|
||||
tray.setToolTip('Anytype');
|
||||
tray.setContextMenu(Menu.buildFromTemplate([
|
||||
{
|
||||
label: 'Show window',
|
||||
click: () => { win.show(); }
|
||||
},
|
||||
]));
|
||||
};
|
||||
|
||||
function createWindow () {
|
||||
const { width, height } = electron.screen.getPrimaryDisplay().workAreaSize;
|
||||
const image = nativeImage.createFromPath(path.join(__dirname, '/electron/icon512x512.png'));
|
||||
|
@ -144,14 +168,7 @@ function createWindow () {
|
|||
})
|
||||
});
|
||||
|
||||
tray = new Tray (path.join(__dirname, '/electron/icon16x16.png'));
|
||||
tray.setToolTip('Anytype');
|
||||
tray.setContextMenu(Menu.buildFromTemplate([
|
||||
{
|
||||
label: 'Show window',
|
||||
click: () => { win.show(); }
|
||||
},
|
||||
]));
|
||||
initTray();
|
||||
|
||||
let state = windowStateKeeper({
|
||||
defaultWidth: width,
|
||||
|
@ -215,6 +232,14 @@ function createWindow () {
|
|||
return false;
|
||||
});
|
||||
|
||||
win.on('enter-full-screen', () => {
|
||||
send('enter-full-screen');
|
||||
});
|
||||
|
||||
win.on('leave-full-screen', () => {
|
||||
send('leave-full-screen');
|
||||
});
|
||||
|
||||
if (process.env.ELECTRON_DEV_EXTENSIONS) {
|
||||
BrowserWindow.addDevToolsExtension(
|
||||
path.join(os.homedir(), '/Library/Application Support/Google/Chrome/Default/Extensions/fmkadmapgofadopljbjfkapdkoienihi/4.6.0_0')
|
||||
|
@ -237,8 +262,13 @@ function createWindow () {
|
|||
exit(relaunch);
|
||||
});
|
||||
|
||||
ipcMain.on('update', (e) => {
|
||||
checkUpdate(false);
|
||||
ipcMain.on('updateDownload', (e) => {
|
||||
autoUpdater.downloadUpdate();
|
||||
});
|
||||
|
||||
ipcMain.on('updateCancel', (e) => {
|
||||
isUpdating = false;
|
||||
clearTimeout(timeoutUpdate);
|
||||
});
|
||||
|
||||
ipcMain.on('urlOpen', async (e, url) => {
|
||||
|
@ -336,7 +366,12 @@ function menuInit () {
|
|||
{ type: 'separator' },
|
||||
{
|
||||
label: 'Quit', accelerator: 'CmdOrCtrl+Q',
|
||||
click: () => { exit(false); }
|
||||
click: () => {
|
||||
if (win) {
|
||||
win.hide();
|
||||
};
|
||||
exit(false);
|
||||
}
|
||||
},
|
||||
]
|
||||
},
|
||||
|
@ -492,6 +527,7 @@ function setConfig (obj, callBack) {
|
|||
};
|
||||
|
||||
function checkUpdate (auto) {
|
||||
Util.log('info', 'isUpdating: ' + isUpdating);
|
||||
if (isUpdating) {
|
||||
return;
|
||||
};
|
||||
|
@ -507,9 +543,10 @@ function autoUpdaterInit () {
|
|||
|
||||
autoUpdater.logger = log;
|
||||
autoUpdater.logger.transports.file.level = 'debug';
|
||||
autoUpdater.autoDownload = false;
|
||||
autoUpdater.channel = config.channel;
|
||||
|
||||
setTimeout(() => { checkUpdate(true); }, TIMEOUT_UPDATE);
|
||||
timeoutUpdate = setTimeout(() => { checkUpdate(true); }, TIMEOUT_UPDATE);
|
||||
|
||||
autoUpdater.on('checking-for-update', () => {
|
||||
Util.log('info', 'Checking for update');
|
||||
|
@ -521,6 +558,10 @@ function autoUpdaterInit () {
|
|||
isUpdating = true;
|
||||
clearTimeout(timeoutUpdate);
|
||||
send('update-available', autoUpdate);
|
||||
|
||||
if (autoUpdate) {
|
||||
autoUpdater.downloadUpdate();
|
||||
};
|
||||
});
|
||||
|
||||
autoUpdater.on('update-not-available', (info) => {
|
||||
|
@ -530,8 +571,9 @@ function autoUpdaterInit () {
|
|||
});
|
||||
|
||||
autoUpdater.on('error', (err) => {
|
||||
isUpdating = false;
|
||||
Util.log('Error: ' + err);
|
||||
send('update-error', err);
|
||||
send('update-error', err, autoUpdate);
|
||||
});
|
||||
|
||||
autoUpdater.on('download-progress', (progress) => {
|
||||
|
@ -549,6 +591,7 @@ function autoUpdaterInit () {
|
|||
});
|
||||
|
||||
autoUpdater.on('update-downloaded', (info) => {
|
||||
isUpdating = false;
|
||||
Util.log('info', 'Update downloaded: ' + JSON.stringify(info, null, 3));
|
||||
send('update-downloaded');
|
||||
app.isQuiting = true;
|
||||
|
@ -592,10 +635,6 @@ function send () {
|
|||
};
|
||||
|
||||
function exit (relaunch) {
|
||||
if (win) {
|
||||
win.hide();
|
||||
};
|
||||
|
||||
let cb = () => {
|
||||
setTimeout(() => {
|
||||
if (relaunch) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue