@@ -31,8 +31,27 @@ import { getUploadFiles } from '~/main/utils/handleArgv'
3131import db from '#/datastore'
3232import bus from '@core/bus'
3333import { privacyManager } from '~/main/utils/privacyManager'
34+ import logger from 'apis/core/picgo/logger'
3435
3536const isDevelopment = process . env . NODE_ENV !== 'production'
37+
38+ const handleStartUpFiles = ( argv : string [ ] , cwd : string ) => {
39+ const files = getUploadFiles ( argv , cwd , logger )
40+ if ( files === null || files . length > 0 ) { // 如果有文件列表作为参数,说明是命令行启动
41+ if ( files === null ) {
42+ logger . info ( 'cli -> uploading file from clipboard' )
43+ uploadClipboardFiles ( )
44+ } else {
45+ logger . info ( 'cli -> uploading files from cli' , ...files . map ( item => item . path ) )
46+ const win = windowManager . getAvailableWindow ( )
47+ uploadChoosedFiles ( win . webContents , files )
48+ }
49+ return true
50+ } else {
51+ return false
52+ }
53+ }
54+
3655class LifeCycle {
3756 private beforeReady ( ) {
3857 protocol . registerSchemesAsPrivileged ( [ { scheme : 'picgo' , privileges : { secure : true , standard : true } } ] )
@@ -69,15 +88,7 @@ class LifeCycle {
6988 } )
7089 server . startup ( )
7190 if ( process . env . NODE_ENV !== 'development' ) {
72- let files = getUploadFiles ( )
73- if ( files === null || files . length > 0 ) { // 如果有文件列表作为参数,说明是命令行启动
74- if ( files === null ) {
75- uploadClipboardFiles ( )
76- } else {
77- const win = windowManager . getAvailableWindow ( )
78- uploadChoosedFiles ( win . webContents , files )
79- }
80- }
91+ handleStartUpFiles ( process . argv , process . cwd ( ) )
8192 }
8293
8394 if ( global . notificationList ?. length > 0 ) {
@@ -91,15 +102,9 @@ class LifeCycle {
91102 }
92103 private onRunning ( ) {
93104 app . on ( 'second-instance' , ( event , commandLine , workingDirectory ) => {
94- let files = getUploadFiles ( commandLine , workingDirectory )
95- if ( files === null || files . length > 0 ) { // 如果有文件列表作为参数,说明是命令行启动
96- if ( files === null ) {
97- uploadClipboardFiles ( )
98- } else {
99- const win = windowManager . getAvailableWindow ( )
100- uploadChoosedFiles ( win . webContents , files )
101- }
102- } else {
105+ logger . info ( 'detect second instance' )
106+ const result = handleStartUpFiles ( commandLine , workingDirectory )
107+ if ( ! result ) {
103108 if ( windowManager . has ( IWindowList . SETTING_WINDOW ) ) {
104109 const settingWindow = windowManager . get ( IWindowList . SETTING_WINDOW ) !
105110 if ( settingWindow . isMinimized ( ) ) {
0 commit comments