@@ -30,10 +30,12 @@ const {
3030 readRepositoryState,
3131 validateRepositoryPath,
3232} = require ( './git-state.cjs' ) ;
33+ const { readWalkthrough } = require ( './walkthrough.cjs' ) ;
3334
3435const root = dirname ( __dirname ) ;
3536const repositoryWatchers = new Map ( ) ;
3637const windowRepositories = new Map ( ) ;
38+ const windowLaunchOptions = new Map ( ) ;
3739let preferences = {
3840 showWhitespace : false ,
3941} ;
@@ -43,9 +45,21 @@ const getCommandLineRepositoryPath = (commandLine = process.argv) => {
4345 return args . find ( ( arg ) => arg && ! arg . startsWith ( '-' ) ) ;
4446} ;
4547
48+ const getCommandLineLaunchOptions = ( commandLine = process . argv ) => {
49+ const args = commandLine . slice ( process . defaultApp ? 2 : 1 ) ;
50+ return {
51+ walkthrough :
52+ process . env . CODIFF_WALKTHROUGH === '1' ||
53+ args . includes ( '--walkthrough' ) ||
54+ args . includes ( '-w' ) ,
55+ } ;
56+ } ;
57+
4658const getLaunchPath = ( ) =>
4759 resolve ( process . env . CODIFF_REPOSITORY_PATH || getCommandLineRepositoryPath ( ) || process . cwd ( ) ) ;
4860
61+ const getLaunchOptions = ( ) => getCommandLineLaunchOptions ( ) ;
62+
4963const getPreferencesPath = ( ) => join ( app . getPath ( 'userData' ) , 'preferences.json' ) ;
5064
5165const readPreferences = ( ) => {
@@ -138,7 +152,7 @@ const openRepositoryFolder = async (browserWindow) => {
138152 } ) ;
139153
140154 if ( ! result . canceled && result . filePaths [ 0 ] ) {
141- createWindow ( result . filePaths [ 0 ] ) ;
155+ createWindow ( result . filePaths [ 0 ] , { walkthrough : false } ) ;
142156 }
143157} ;
144158
@@ -279,7 +293,7 @@ const buildApplicationMenu = () =>
279293 } ,
280294 ] ) ;
281295
282- const createWindow = ( repositoryPath ) => {
296+ const createWindow = ( repositoryPath , launchOptions = { walkthrough : false } ) => {
283297 const display = screen . getPrimaryDisplay ( ) ;
284298 const { height, width } = display . workAreaSize ;
285299 const window = new BrowserWindow ( {
@@ -303,6 +317,7 @@ const createWindow = (repositoryPath) => {
303317
304318 const webContentsId = window . webContents . id ;
305319 windowRepositories . set ( webContentsId , repositoryPath ) ;
320+ windowLaunchOptions . set ( webContentsId , launchOptions ) ;
306321 startRepositoryWatcher ( window , repositoryPath ) ;
307322 window . once ( 'ready-to-show' , ( ) => window . show ( ) ) ;
308323 window . on ( 'closed' , ( ) => {
@@ -312,6 +327,7 @@ const createWindow = (repositoryPath) => {
312327 }
313328 repositoryWatchers . delete ( webContentsId ) ;
314329 windowRepositories . delete ( webContentsId ) ;
330+ windowLaunchOptions . delete ( webContentsId ) ;
315331 } ) ;
316332
317333 const rendererURL = process . env . ELECTRON_RENDERER_URL ;
@@ -322,7 +338,12 @@ const createWindow = (repositoryPath) => {
322338 }
323339} ;
324340
325- const lock = ! squirrelStartup && app . requestSingleInstanceLock ( { repositoryPath : getLaunchPath ( ) } ) ;
341+ const lock =
342+ ! squirrelStartup &&
343+ app . requestSingleInstanceLock ( {
344+ launchOptions : getLaunchOptions ( ) ,
345+ repositoryPath : getLaunchPath ( ) ,
346+ } ) ;
326347
327348if ( squirrelStartup || ! lock ) {
328349 app . quit ( ) ;
@@ -336,18 +357,19 @@ if (squirrelStartup || !lock) {
336357 getCommandLineRepositoryPath ( commandLine ) ||
337358 workingDirectory ,
338359 ) ,
360+ additionalData ?. launchOptions || getCommandLineLaunchOptions ( commandLine ) ,
339361 ) ;
340362 } ) ;
341363
342364 app . on ( 'ready' , ( ) => {
343365 preferences = readPreferences ( ) ;
344366 Menu . setApplicationMenu ( buildApplicationMenu ( ) ) ;
345- createWindow ( getLaunchPath ( ) ) ;
367+ createWindow ( getLaunchPath ( ) , getLaunchOptions ( ) ) ;
346368 } ) ;
347369
348370 app . on ( 'activate' , ( ) => {
349371 if ( BrowserWindow . getAllWindows ( ) . length === 0 ) {
350- createWindow ( getLaunchPath ( ) ) ;
372+ createWindow ( getLaunchPath ( ) , getLaunchOptions ( ) ) ;
351373 }
352374 } ) ;
353375
@@ -363,6 +385,20 @@ ipcMain.handle('codiff:getRepositoryState', async (event, source) => {
363385 return state ;
364386} ) ;
365387
388+ ipcMain . handle (
389+ 'codiff:getLaunchOptions' ,
390+ ( event ) =>
391+ windowLaunchOptions . get ( event . sender . id ) || {
392+ walkthrough : false ,
393+ } ,
394+ ) ;
395+
396+ ipcMain . handle ( 'codiff:getWalkthrough' , async ( event , source ) => {
397+ const repositoryPath = windowRepositories . get ( event . sender . id ) || getLaunchPath ( ) ;
398+ const state = await readRepositoryState ( repositoryPath , source ) ;
399+ return readWalkthrough ( state ) ;
400+ } ) ;
401+
366402ipcMain . handle ( 'codiff:getDiffSectionContent' , async ( event , request ) => {
367403 const repositoryPath = windowRepositories . get ( event . sender . id ) || getLaunchPath ( ) ;
368404 return readDiffSectionContent ( repositoryPath , request ) ;
0 commit comments