1
0
Fork 0
mirror of https://github.com/anyproto/anytype-ts.git synced 2025-06-08 05:57:02 +09:00
anytype-ts/electron/js/api.js
Razor 3579220916
Feature/Navigation (#1)
* navigation panel

* navigation

* navigation

* fixes

* remove unused svg + fixes

* fixes

* move logic update

* move logic update

* fixes

* fixes

* search

* search

* sidebar resize logic

* sidebar resize logic

* sidebar resize logic

* sidebar resize logic

* remove relations button

* JS-1917: preloader update

* JS-1917: preloader update

* JS-897: delete logic update

* JS-897: delete logic update

* refactoring

* remove unused logic

* remove unused logic

* small fixes

* fix sentry crash

* JS-1955: settings popup

* JS-1955: settings popup

* JS-1955: settings popup

* refactoring

* refactoring

* refactoring

* fix overflow

* fix overflow

* fixes

* fix navigation when sidebar is on the right

* JS-1686: fix

* space icon

* remove drag n drop from navigation

* fixes

* JS-2024: fixes

* JS-2024: fixes

* JS-2024: fixes

* search fixes

* JS-2024: fixes

* JS-2053: fix

* JS-2052: graph root highlight

* JS-2052: graph root highlight

* JS-2052: graph root highlight

* sync status icons

* object creation flow updates

* JS-2046: fix

* sidebar resize fixes

* fix sentry crash

* fix sidebar open/close

* fixes

* fix

* fix

* fix

* resize navigation on popup close

* popup fixes

* JS-2048: fix

* fix cursor

* fix sidebar resize button

* fix sidebar handle size

* small refactoring

* JS-2058: shortcuts

* fix right click

* JS-1477: fix

* JS-2050: fix

* fix cmd+n flags

* fix search object

* fix search object

* remove debug

* JS-2066: revert sync component

* JS-2024

* JS-2083: shortcuts + refactoring

* JS-2083: shortcuts + refactoring

* fix toast position

* JS-2094: fix

* JS-2094: fix

* JS-2068: fix

* JS-2094: fix

* JS-2101: fix

* JS-2102: fix

* JS-2095: fixes

* JS-1931: fixes + refactoring

* fix sidebar overflow

* fix sidebar resize

* JS-2097: fix

* JS-2097: fix

* fix titleWrap

* fix list widget hovers

* JS-2096: edit icon

* JS-2096: fix

* fix font size

* fix

* JS-2098: fixes

* JS-2098: fixes

* JS-2098: fixes

* JS-2099: fixes

* fix window bg on init

* optimize resize

* JS-2100: gallery reworked as list component

* JS-2100: gallery reworked as list component

* resize logic update

* update resize logi

* move form components from util

* small gallery refactoring

* small gallery refactoring

* JS-2099: fix cards

* JS-2046: fix

* JS-2101: fix

* GO-1156: fix csv import param

* JS-2096: fix

* JS-2113: fix

* JS-1630: fix

* JS-1630: fix

* JS-2096: fixes

* JS-2098: fix

* JS-1904: fix

* JS-1904: add preview to bookmark

* JS-2126: fix

* JS-2112: navigation popups resize

* JS-2067: remove context behaviour from object creation

* fix row highlight in dark mode

* remove popup from resize logic

* JS-2123: fixes

* JS-2130: fix

* fix edit icon

* JS-2123: fix

* JS-2117: fix

* fix full popup

* fixes

* JS-2132: fix

* JS-2118: gallery card size calculation

* popup resize logic
2023-05-24 10:51:59 +02:00

160 lines
No EOL
3.2 KiB
JavaScript

const { app, shell, BrowserWindow } = require('electron');
const keytar = require('keytar');
const { download } = require('electron-dl');
const ConfigManager = require('./config.js');
const WindowManager = require('./window.js');
const UpdateManager = require('./update.js');
const Server = require('./server.js');
const Util = require('./util.js');
const KEYTAR_SERVICE = 'Anytype';
class Api {
account = null;
phrase = '';
isPinChecked = false;
appOnLoad (win) {
Util.send(win, 'init', {
dataPath: Util.dataPath(),
config: ConfigManager.config,
isDark: Util.isDarkTheme(),
isChild: win.isChild,
route: win.route,
account: this.account,
phrase: this.phrase,
isPinChecked: this.isPinChecked,
languages: win.webContents.session.availableSpellCheckerLanguages,
});
win.route = '';
};
setConfig (win, config) {
ConfigManager.set(config, (err) => { Util.send(win, 'config', ConfigManager.config); });
};
setAccount (win, account) {
this.account = account;
};
setPinChecked (win, isPinChecked) {
this.isPinChecked = isPinChecked;
};
setTheme (win, theme) {
this.setConfig(win, { theme });
};
setBackground (win, theme) {
BrowserWindow.getAllWindows().forEach(win => win.setBackgroundColor(Util.getBgColor(theme)));
};
setLanguage (win, languages) {
languages = languages || [];
win.webContents.session.setSpellCheckerLanguages(languages);
win.webContents.session.setSpellCheckerEnabled(languages.length ? true : false);
this.setConfig(win, { languages });
};
setZoom (win, zoom) {
zoom = Number(zoom) || 0;
zoom = Math.max(-5, Math.min(5, zoom));
win.webContents.setZoomLevel(zoom);
Util.send(win, 'zoom');
this.setConfig(win, { zoom });
};
spellcheckAdd (win, s) {
win.webContents.session.addWordToSpellCheckerDictionary(s);
};
keytarSet (win, key, value) {
if (key && value) {
this.phrase = value;
keytar.setPassword(KEYTAR_SERVICE, key, value);
};
};
keytarGet (win, key) {
keytar.getPassword(KEYTAR_SERVICE, key).then(value => {
this.phrase = value;
Util.send(win, 'keytarGet', key, value);
});
};
keytarDelete (win, key) {
keytar.deletePassword(KEYTAR_SERVICE, key);
};
updateCheck (win) {
if (this.isPinChecked) {
UpdateManager.checkUpdate(false);
};
};
updateDownload (win) {
UpdateManager.download();
};
updateConfirm (win) {
this.exit(win, true);
};
updateCancel (win) {
UpdateManager.cancel();
};
async download (win, url) {
await download(win, url, { saveAs: true });
};
winCommand (win, cmd, param) {
WindowManager.command(win, cmd, param);
};
windowOpen (win, route) {
WindowManager.createMain({ route, isChild: true });
};
urlOpen (win, url) {
shell.openExternal(url);
};
pathOpen (win, path) {
shell.openPath(path);
};
shutdown (win, relaunch) {
Util.log('info', '[Api].shutdown, relaunch: ' + relaunch);
if (relaunch) {
UpdateManager.relaunch();
} else {
app.exit(0);
};
};
exit (win, relaunch) {
if (app.isQuiting) {
return;
};
if (win) {
win.hide();
};
Util.log('info', '[Api].exit, relaunch: ' + relaunch);
Util.send(win, 'shutdownStart');
Server.stop().then(() => { this.shutdown(win, relaunch); });
};
};
module.exports = new Api();