1
1
/* eslint global-require: off, no-console: off, promise/always-return: off */
2
2
3
- /**
4
- * This module executes inside of electron's main process. You can start
5
- * electron renderer process from here and communicate with the other processes
6
- * through IPC.
7
- *
8
- * When running `npm run build` or `npm run build:main`, this file is compiled to
9
- * `./src/main.js` using webpack. This gives us some performance wins.
10
- */
11
3
import path from 'path' ;
12
4
import { app , BrowserWindow , shell , ipcMain } from 'electron' ;
13
5
import { autoUpdater } from 'electron-updater' ;
14
6
import log from 'electron-log' ;
15
7
import OSS from 'ali-oss' ;
16
8
import MenuBuilder from './menu' ;
17
9
import { resolveHtmlPath } from './util' ;
18
-
10
+ import type { ConfigParams } from '../renderer/type' ;
19
11
// oss有些方法只能在node端使用https://github.com/ali-sdk/ali-oss#browser-usage
20
- // const client = new OSS({}) ;
12
+ let client : null | OSS = null ;
21
13
22
14
export default class AppUpdater {
23
15
constructor ( ) {
@@ -29,23 +21,20 @@ export default class AppUpdater {
29
21
30
22
let mainWindow : BrowserWindow | null = null ;
31
23
32
- ipcMain . on ( 'ipc-example' , async ( event , arg ) => {
33
- const msgTemplate = ( pingPong : string ) => `IPC test: ${ pingPong } ` ;
34
- console . log ( msgTemplate ( arg ) ) ;
35
- event . reply ( 'ipc-example' , msgTemplate ( 'pong' ) ) ;
24
+ ipcMain . handle ( 'handleOss' , async ( event , method , ...args ) => {
25
+ console . log ( method , ...args ) ;
26
+ return client ?. [ method ] ( ...args ) ;
36
27
} ) ;
37
28
38
- ipcMain . on ( 'client' , async ( event ) => {
39
- const list = [ ] ;
40
- try {
41
- // list = await client.listBuckets();
42
- } catch ( error ) {
43
- console . log ( error ) ;
44
- }
45
-
46
- event . reply ( 'client' , list ) ;
29
+ ipcMain . handle ( 'initOssClient' , async ( event , ak : ConfigParams ) => {
30
+ client = new OSS ( {
31
+ region : ak . region ,
32
+ accessKeyId : ak . accessKeyId ! ,
33
+ accessKeySecret : ak . accessKeySecret ! ,
34
+ bucket : 'pi-version-backup' ,
35
+ } ) ;
36
+ return 0 ;
47
37
} ) ;
48
-
49
38
if ( process . env . NODE_ENV === 'production' ) {
50
39
const sourceMapSupport = require ( 'source-map-support' ) ;
51
40
sourceMapSupport . install ( ) ;
0 commit comments