Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
126 changes: 121 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,123 @@
#IDEA
/.idea
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
server.log
# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# Snowpack dependency directory (https://snowpack.dev/)
web_modules

# TypeScript cache
*.tsbuildinfo

# Optional eslint cache
.eslintcache

# Optional stylelint cache
.stylelintcache

# Microbundle cache
.rpt2_cache/
.rts2_cache/
.parcel-cache/

# Next.js build outputs
.next
out

# Nuxt.js build outputs
.nuxt
dist

# Docusaurus build outputs
.docusaurus

# Gatsby build outputs
.cache/
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public

# vuepress build outputs
.vuepress/dist

# serverless build outputs
.serverless/

# FuseBox cache
.fusebox/

# Ionic build outputs
www/

# Roswell build outputs
.roswell/

# Strapi build outputs
.cache
build

# SvelteKit build outputs
.svelte-kit
build

# Remix build outputs
.cache/
build/
public/build/

# Deno dependency directory (https://deno.land/)
deno_dir

# Vite build outputs
dist
dist-ssr
dist-electron

# IDEA
.idea

# VSCode
.vscode

# User-specific files
.env
repositories.json
.env
73 changes: 63 additions & 10 deletions electron/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ async function checkRepos() {

let reposUpdated = false;

for (let i = 0; i < repos.length; i++) {
const repo = repos[i];
for (const repo of repos) {
try {
const git = simpleGit(repo.path)

Expand All @@ -61,28 +60,45 @@ async function checkRepos() {
await git.fetch()
const status = await git.status()

const updateData: any = { id: repo.id, status: 'clean', commits: 0, githubUrl: repo.githubUrl };

if (status.behind > 0) {
const updateData: any = {
id: repo.id,
status: 'clean',
commitsBehind: 0,
commitsAhead: 0,
githubUrl: repo.githubUrl
};

if (status.isClean() === false) {
updateData.status = 'dirty';
} else if (status.ahead > 0 && status.behind > 0) {
updateData.status = 'diverged';
updateData.commitsBehind = status.behind;
updateData.commitsAhead = status.ahead;
} else if (status.behind > 0) {
updateData.status = 'behind';
updateData.commits = status.behind;
updateData.commitsBehind = status.behind;

if (repo.autoPull) {
await git.pull()
notifyUser(repo.name, `Pulled ${status.behind} new commits.`)
updateData.status = 'clean';
updateData.commits = 0;
updateData.commitsBehind = 0;
} else {
notifyUser(repo.name, `${status.behind} commits waiting.`, true)
}
} else if (status.ahead > 0) {
updateData.status = 'ahead';
updateData.commitsAhead = status.ahead;
}

if (mainWindow) mainWindow.webContents.send('repo-update', updateData)

} catch (err: any) {
console.error(`Error checking ${repo.name}:`, err)
if (mainWindow) mainWindow.webContents.send('repo-error', { id: repo.id, message: err.message || 'Unknown error' })
if (mainWindow) mainWindow.webContents.send('repo-update', { id: repo.id, status: 'error', commits: 0 })
if (mainWindow) {
mainWindow.webContents.send('repo-error', { id: repo.id, message: err.message || 'Unknown error' })
mainWindow.webContents.send('repo-update', { id: repo.id, status: 'error' })
}
}
}

Expand All @@ -98,7 +114,7 @@ function notifyUser(title: string, message: string, clickToOpen = false) {
sound: true,
wait: clickToOpen,
appID: 'com.gitwatcher.app',
}, (err, response) => {
}, (_, response) => {
if (clickToOpen && response === 'activate' && mainWindow) {
mainWindow.show()
}
Expand Down Expand Up @@ -313,6 +329,43 @@ app.whenReady().then(() => {
ipcMain.handle('open-vscode', async (_, path) => {
exec(`code "${path}"`)
})

ipcMain.handle('git-pull', async (_, id: string) => {
const repos = store.get('repos') as any[] || []
const repo = repos.find((r: any) => r.id === id)
if (!repo) return false;
try {
await simpleGit(repo.path).pull();
checkRepos(); // Re-check to update status
return true;
} catch (e) {
console.error(e)
checkRepos();
return false;
}
})

ipcMain.handle('git-push', async (_, id: string) => {
const repos = store.get('repos') as any[] || []
const repo = repos.find((r: any) => r.id === id)
if (!repo) return false;
try {
await simpleGit(repo.path).push();
checkRepos(); // Re-check to update status
return true;
} catch (e) {
console.error(e)
checkRepos();
return false;
}
})

ipcMain.handle('delete-repo', (_, id: string) => {
const repos = store.get('repos') as any[] || []
const newRepos = repos.filter((r: any) => r.id !== id)
store.set('repos', newRepos)
return true
})

ipcMain.on('window-minimize', () => mainWindow?.minimize())
ipcMain.on('window-maximize', () => {
Expand Down
4 changes: 4 additions & 0 deletions electron/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ contextBridge.exposeInMainWorld('electronAPI', {
openRepoFolder: (path: string) => ipcRenderer.invoke('open-repo-folder', path),
openRepoUrl: (id: string) => ipcRenderer.invoke('open-repo-url', id),
openInVsCode: (path: string) => ipcRenderer.invoke('open-vscode', path),

gitPull: (id: string) => ipcRenderer.invoke('git-pull', id),
gitPush: (id: string) => ipcRenderer.invoke('git-push', id),
deleteRepo: (id: string) => ipcRenderer.invoke('delete-repo', id),

minimize: () => ipcRenderer.send('window-minimize'),
maximize: () => ipcRenderer.send('window-maximize'),
Expand Down
Loading