Skip to content

Commit

Permalink
refactor: use native git instead of isomorphic-git (#47)
Browse files Browse the repository at this point in the history
* refactor: initial git refactor to use native git

* fix: git status + git stage/unstage

* feat: discard changes + fix commit

* feat: git push

* feat: git new branch + checkout + delete local branch

* feat: clone + init repo + delete / set remote branch
  • Loading branch information
NGPixel authored Jan 24, 2025
1 parent fc65ee3 commit d12a31f
Show file tree
Hide file tree
Showing 11 changed files with 1,082 additions and 389 deletions.
33 changes: 31 additions & 2 deletions src-electron/electron-main.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { app, BrowserWindow, Menu, screen } from 'electron'
import { app, dialog, BrowserWindow, Menu, screen } from 'electron'
import path from 'node:path'
import { fileURLToPath } from 'node:url'
import cmdExists from 'command-exists'
import tlm from './instrumentation.js'
import { trace } from '@opentelemetry/api'
import { registerMenu } from './menu.js'
Expand All @@ -10,6 +11,7 @@ import auth from './auth.js'
import git from './git.js'
import lsp from './lsp.js'
import updater from './updater.js'
import { createKeybindingsHandler } from './keyhandler.js'

const currentDir = fileURLToPath(new URL('.', import.meta.url))

Expand All @@ -30,7 +32,19 @@ let splashWindow
let mainWindow
let mainMenu

function createWindow () {
const menuHandlers = createKeybindingsHandler({
'Escape d': () => {
console.info('SHIFT + D')
},
'y e e t': () => {
console.info("The keys 'y', 'e', 'e', and 't' were pressed in order")
},
'$mod+([0-9])': (event, input) => {
console.info(`Either 'Control+${input.key}' or 'Meta+${input.key}' were pressed`)
},
})

async function createWindow () {
const span = tracer.startSpan('createWindow')

// Show splash screen
Expand All @@ -44,6 +58,15 @@ function createWindow () {
})
splashWindow.loadFile(path.resolve(import.meta.dirname, process.env.QUASAR_PUBLIC_FOLDER, 'splash.html'))

// Ensure git is install
try {
await cmdExists('git')
} catch (err) {
splashWindow.destroy()
dialog.showErrorBox('Missing Git Dependency', 'Git is not installed or is not in path. Install git first and then launch DraftForge again.')
app.exit(1)
}

// -> Get primary screen dimensions
const primaryDisplay = screen.getPrimaryDisplay()
const { width, height } = primaryDisplay.workAreaSize
Expand Down Expand Up @@ -93,6 +116,12 @@ function createWindow () {
splashWindow.destroy()
mainWindow.show()
mainWindow.moveTop()

mainWindow.webContents.on('before-input-event', (evt, input) => {
if (input?.type === 'keyDown') {
menuHandlers(evt, input)
}
})
})

// -> Load start URL
Expand Down
32 changes: 21 additions & 11 deletions src-electron/electron-preload.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,27 @@ contextBridge.exposeInMainWorld('ipcBridge', {
readDirectory: (dirPath) => ipcRenderer.invoke('readDirectory', { dirPath }),
fetchGitConfig: () => ipcRenderer.invoke('fetchGitConfig'),
clearGitKey: () => ipcRenderer.invoke('clearGitKey'),
gitCloneRepository: (url, target, upstreamUrl) => ipcRenderer.invoke('gitCloneRepository', { url, target, upstreamUrl }),
gitPerformFetch: (dir, remote) => ipcRenderer.invoke('gitPerformFetch', { dir, remote }),
gitListRemotes: (dir) => ipcRenderer.invoke('gitListRemotes', { dir }),
gitAddRemote: (dir, remote, url) => ipcRenderer.invoke('gitAddRemote', { dir, remote, url }),
gitDeleteRemote: (dir, remote) => ipcRenderer.invoke('gitDeleteRemote', { dir, remote }),
gitListBranches: (dir, remote) => ipcRenderer.invoke('gitListBranches', { dir, remote }),
gitCommitsLog: (dir) => ipcRenderer.invoke('gitCommitsLog', { dir }),
gitStatusMatrix: (dir) => ipcRenderer.invoke('gitStatusMatrix', { dir }),
gitStageFiles: (dir, files) => ipcRenderer.invoke('gitStageFiles', { dir, files }),
gitUnstageFiles: (dir, files) => ipcRenderer.invoke('gitUnstageFiles', { dir, files }),
gitCommit: (dir, message) => ipcRenderer.invoke('gitCommit', { dir, message }),
gitCloneRepository: (url, target, upstreamUrl, cloneInSubDir) => ipcRenderer.invoke('gitCloneRepository', { url, target, upstreamUrl, cloneInSubDir }),
gitInitRepository: (target) => ipcRenderer.invoke('gitInitRepository', { target }),
setGitWorkingDirectory: (dir) => ipcRenderer.invoke('gitSetWorkingDirectory', { dir }),
gitPerformFetch: (remote) => ipcRenderer.invoke('gitPerformFetch', { remote }),
gitListRemotes: () => ipcRenderer.invoke('gitListRemotes'),
gitAddRemote: (remote, url) => ipcRenderer.invoke('gitAddRemote', { remote, url }),
gitDeleteRemote: (remote) => ipcRenderer.invoke('gitDeleteRemote', { remote }),
gitPull: (mode, remote, branch) => ipcRenderer.invoke('gitPull', { mode, remote, branch }),
gitPush: (remote, branch) => ipcRenderer.invoke('gitPush', { remote, branch }),
gitListBranches: (remote) => ipcRenderer.invoke('gitListBranches', { remote }),
gitNewBranch: (branchName, source, tracking) => ipcRenderer.invoke('gitNewBranch', { branchName, source, tracking }),
gitDeleteBranch: (branch) => ipcRenderer.invoke('gitDeleteBranch', { branch }),
gitDeleteRemoteBranch: (remote, branch) => ipcRenderer.invoke('gitDeleteRemoteBranch', { remote, branch }),
gitSetBranchTracking: (branch, tracking) => ipcRenderer.invoke('gitSetBranchTracking', { branch, tracking }),
gitCheckoutBranch: (branch, tracking) => ipcRenderer.invoke('gitCheckoutBranch', { branch, tracking }),
gitCommitsLog: () => ipcRenderer.invoke('gitCommitsLog'),
gitStatusMatrix: () => ipcRenderer.invoke('gitStatusMatrix'),
gitStageFiles: (files) => ipcRenderer.invoke('gitStageFiles', { files }),
gitUnstageFiles: (files) => ipcRenderer.invoke('gitUnstageFiles', { files }),
gitDiscardChanges: (files) => ipcRenderer.invoke('gitDiscardChanges', { files }),
gitCommit: (message) => ipcRenderer.invoke('gitCommit', { message }),
lspSendRequest: (method, params) => ipcRenderer.invoke('lspSendRequest', { method, params }),
persistSession: (data) => ipcRenderer.invoke('persistSession', data),
restoreSession: () => ipcRenderer.invoke('restoreSession')
Expand Down
Loading

0 comments on commit d12a31f

Please sign in to comment.