123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263 |
- 'use strict';
- const electron = require('electron');
- const core = require('../core');
- const config = require('../config/config');
- const titlebar = require('../components/titlebar');
- const menu = require('../components/menu');
- const tray = require('../components/tray');
- const notification = require('../components/notification');
- const http = require('../lib/http');
- const websocket = require('../lib/websocket');
- const localfs = require('../lib/localfs');
- const bittorrent = require('../lib/bittorrent');
- const shell = electron.shell;
- const nativeTheme = electron.nativeTheme;
- const dialog = electron.dialog;
- const ipcMain = electron.ipcMain;
- ipcMain.on('render-sync-get-runtime-environment', (event) => {
- if (!process || !process.versions) {
- return null;
- }
- var versions = process.versions;
- event.returnValue = [
- {
- name: 'Electron',
- value: versions.electron
- },
- {
- name: 'Node.js',
- value: versions.node
- },
- {
- name: 'Chromium',
- value: versions.chrome
- },
- {
- name: 'V8',
- value: versions.v8
- }
- ];
- });
- ipcMain.on('render-sync-get-global-setting', (event, key) => {
- if (key === 'version') {
- event.returnValue = core.version;
- } else if (key === 'ariaNgVersion') {
- event.returnValue = core.ariaNgVersion;
- } else if (key === 'buildCommit') {
- event.returnValue = core.buildCommit;
- } else if (key === 'isDevMode') {
- event.returnValue = core.isDevMode;
- } else if (key === 'useCustomAppTitle') {
- event.returnValue = core.useCustomAppTitle;
- } else {
- event.returnValue = undefined;
- }
- });
- ipcMain.on('render-set-native-theme', (event, theme) => {
- if (theme === 'dark') {
- nativeTheme.themeSource = 'dark';
- } else if (theme === 'light') {
- nativeTheme.themeSource = 'light'
- } else {
- nativeTheme.themeSource = 'system';
- }
- });
- ipcMain.on('render-set-titlebar-color', (event, titleBarBackgroundColor, titleBarSymbolColor) => {
- titlebar.updateWindowTitleBar(titleBarBackgroundColor, titleBarSymbolColor);
- });
- ipcMain.on('render-reload-native-window', (event) => {
- core.mainWindow.reload();
- });
- ipcMain.on('render-show-textbox-context-menu', (event, context) => {
- const contextMenu = menu.getTextboxContentMenu(context);
- if (contextMenu) {
- contextMenu.popup(core.mainWindow);
- }
- });
- ipcMain.on('render-show-system-notification', (event, context) => {
- notification.showNotification(context.title, context.body, context.silent);
- });
- ipcMain.on('render-update-app-menu-label', (event, labels) => {
- menu.setApplicationMenu({
- labels: labels
- });
- menu.setTextboxContextMenuTemplate({
- labels: labels
- });
- });
- ipcMain.on('render-update-tray-menu-label', (event, labels) => {
- tray.setContextMenu({
- labels: labels
- });
- });
- ipcMain.on('render-update-tray-tip', (event, tooltip) => {
- tray.setToolTip(tooltip);
- });
- ipcMain.on('render-sync-get-native-config', (event) => {
- event.returnValue = {
- defaultPosition: config.defaultPosition,
- minimizedToTray: config.minimizedToTray,
- execCommandOnStartup: config.execCommandOnStartup,
- execCommandArgumentsOnStartup: config.execCommandArgumentsOnStartup,
- execDetachedCommandOnStartup: config.execDetachedCommandOnStartup
- };
- });
- ipcMain.on('render-set-native-config-default-position', (event, value) => {
- config.defaultPosition = value;
- config.save('defaultPosition');
- });
- ipcMain.on('render-set-native-config-minimized-to-tray', (event, value) => {
- config.minimizedToTray = !!value;
- config.save('minimizedToTray');
- });
- ipcMain.on('render-set-native-config-exec-command-on-startup', (event, value) => {
- config.execCommandOnStartup = value;
- config.save('execCommandOnStartup');
- });
- ipcMain.on('render-set-native-config-exec-command-arguments-on-startup', (event, value) => {
- config.execCommandArgumentsOnStartup = value;
- config.save('execCommandArgumentsOnStartup');
- });
- ipcMain.on('render-set-native-config-exec-detached-command-on-startup', (event, value) => {
- config.execDetachedCommandOnStartup = value;
- config.save('execDetachedCommandOnStartup');
- });
- ipcMain.handle('render-get-native-config-last-check-updates-time', (event) => {
- return config.lastCheckUpdatesTime;
- });
- ipcMain.on('render-set-native-config-last-check-updates-time', (event, value) => {
- config.lastCheckUpdatesTime = value;
- config.save('lastCheckUpdatesTime');
- });
- ipcMain.handle('render-get-startup-command-process-output', (event, requestContext) => {
- return core.startupCommandOutput;
- });
- ipcMain.handle('render-request-http', (event, requestContext) => {
- return http.request(requestContext);
- });
- ipcMain.on('render-connect-websocket', (event, rpcUrl, options) => {
- websocket.connect(rpcUrl, options,
- function onOpen(context) {
- try {
- core.mainWindow.webContents.send('on-main-websocket-open', {
- url: context.url
- });
- } catch (ex) {
- // Do Nothing
- }
- },
- function onClose(context) {
- try {
- core.mainWindow.webContents.send('on-main-websocket-close', {
- url: context.url,
- autoReconnect: context.autoReconnect
- });
- } catch (ex) {
- // Do Nothing
- }
- },
- function onMessage(context) {
- try {
- core.mainWindow.webContents.send('on-main-websocket-message', {
- success: context.success,
- url: context.url,
- data: context.message
- });
- } catch (ex) {
- // Do Nothing
- }
- }
- );
- });
- ipcMain.on('render-reconnect-websocket', (event, rpcUrl, options) => {
- websocket.reconnect(rpcUrl, options);
- });
- ipcMain.on('render-send-websocket-message', (event, requestContext) => {
- websocket.send(requestContext)
- .catch(function () {
- try {
- core.mainWindow.webContents.send('on-main-websocket-message', {
- success: false,
- url: requestContext.url,
- request: requestContext.data,
- data: null
- });
- } catch (ex) {
- // Do Nothing
- }
- });
- });
- ipcMain.on('render-get-websocket-readystate', (event) => {
- event.returnValue = websocket.getReadyState();
- });
- ipcMain.on('render-open-external-url', (event, url) => {
- shell.openExternal(url);
- });
- ipcMain.on('render-sync-get-package-file-content', (event, path) => {
- event.returnValue = localfs.readPackageFile(path);
- });
- ipcMain.handle('render-get-localfs-file-buffer', (event, fullpath) => {
- return localfs.getLocalFSFileBuffer(fullpath);
- });
- ipcMain.handle('render-get-localfs-exists', (event, fullpath) => {
- return localfs.isExists(fullpath);
- });
- ipcMain.on('render-open-local-directory', (event, dir, filename) => {
- let fullpath = localfs.getFullPath(dir, filename);
- if (localfs.isExists(fullpath)) {
- shell.showItemInFolder(fullpath);
- } else {
- shell.openPath(dir);
- }
- });
- ipcMain.handle('render-show-open-file-dialog', (event, filters) => {
- return dialog.showOpenDialog({
- properties: ['openFile'],
- filters: filters
- });
- });
- ipcMain.on('render-show-dev-tools', (event) => {
- core.mainWindow.webContents.openDevTools();
- });
- ipcMain.on('render-sync-parse-bittorrent-info', (event, data) => {
- event.returnValue = bittorrent.parseBittorrentInfo(data);
- });
|