diff --git a/package.json b/package.json index f41be4fb..5c942772 100644 --- a/package.json +++ b/package.json @@ -60,7 +60,7 @@ "activitybar": [ { "id": "frontmatter-explorer", - "title": "FrontMatter", + "title": "Front Matter", "icon": "assets/frontmatter-short-min.svg" } ] @@ -69,9 +69,9 @@ "frontmatter-explorer": [ { "id": "frontMatter.explorer", - "name": "FrontMatter", + "name": "Front Matter", "icon": "assets/frontmatter-short-min.svg", - "contextualTitle": "FrontMatter", + "contextualTitle": "Front Matter", "type": "webview" } ] @@ -1383,27 +1383,27 @@ { "command": "frontMatter.authenticate", "title": "Authenticate", - "category": "Front matter" + "category": "Front Matter" }, { "command": "frontMatter.contenttype.generate", "title": "Generate content type from current file", - "category": "Front matter" + "category": "Front Matter" }, { "command": "frontMatter.contenttype.addMissingFields", "title": "Add missing fields from front matter to content type", - "category": "Front matter" + "category": "Front Matter" }, { "command": "frontMatter.contenttype.setContentType", "title": "Set the content type to use for the current file", - "category": "Front matter" + "category": "Front Matter" }, { "command": "frontMatter.markup.blockquote", "title": "Blockquote", - "category": "Front matter", + "category": "Front Matter", "icon": { "light": "assets/icons/blockquote-light.svg", "dark": "assets/icons/blockquote-dark.svg" @@ -1412,7 +1412,7 @@ { "command": "frontMatter.markup.bold", "title": "Bold", - "category": "Front matter", + "category": "Front Matter", "icon": { "light": "assets/icons/bold-light.svg", "dark": "assets/icons/bold-dark.svg" @@ -1421,7 +1421,7 @@ { "command": "frontMatter.dashboard.close", "title": "Close dashboard", - "category": "Front matter", + "category": "Front Matter", "icon": { "dark": "/assets/icons/frontmatter-small-teal.svg", "light": "/assets/icons/frontmatter-small-teal.svg" @@ -1430,7 +1430,7 @@ { "command": "frontMatter.markup.code", "title": "Code", - "category": "Front matter", + "category": "Front Matter", "icon": { "light": "assets/icons/code-light.svg", "dark": "assets/icons/code-dark.svg" @@ -1439,7 +1439,7 @@ { "command": "frontMatter.markup.codeblock", "title": "Codeblock", - "category": "Front matter", + "category": "Front Matter", "icon": { "light": "assets/icons/codeblock-light.svg", "dark": "assets/icons/codeblock-dark.svg" @@ -1448,7 +1448,7 @@ { "command": "frontMatter.collapseSections", "title": "Collapse sections", - "category": "Front matter", + "category": "Front Matter", "icon": { "light": "assets/icons/close-light.svg", "dark": "assets/icons/close-dark.svg" @@ -1457,37 +1457,37 @@ { "command": "frontMatter.initTemplate", "title": "Initialize the template folder", - "category": "Front matter" + "category": "Front Matter" }, { "command": "frontMatter.createTemplate", "title": "Create template from current file", - "category": "Front matter" + "category": "Front Matter" }, { "command": "frontMatter.createCategory", "title": "Create category", - "category": "Front matter" + "category": "Front Matter" }, { "command": "frontMatter.createContent", "title": "Create new content from defined content type or template", - "category": "Front matter" + "category": "Front Matter" }, { "command": "frontMatter.createTag", "title": "Create tag", - "category": "Front matter" + "category": "Front Matter" }, { "command": "frontMatter.diagnostics", "title": "Diagnostic logging", - "category": "Front matter" + "category": "Front Matter" }, { "command": "frontMatter.exportTaxonomy", "title": "Export all tags & categories to your settings", - "category": "Front matter" + "category": "Front Matter" }, { "command": "frontMatter.createFromTemplate", @@ -1504,12 +1504,12 @@ { "command": "frontMatter.generateSlug", "title": "Generate slug based on content title", - "category": "Front matter" + "category": "Front Matter" }, { "command": "frontMatter.markup.heading", "title": "Heading", - "category": "Front matter", + "category": "Front Matter", "icon": { "light": "assets/icons/heading-light.svg", "dark": "assets/icons/heading-dark.svg" @@ -1518,17 +1518,17 @@ { "command": "frontMatter.init", "title": "Initialize project", - "category": "Front matter" + "category": "Front Matter" }, { "command": "frontMatter.insertCategories", "title": "Insert categories", - "category": "Front matter" + "category": "Front Matter" }, { "command": "frontMatter.insertMedia", "title": "Insert media into your content", - "category": "Front matter", + "category": "Front Matter", "icon": { "dark": "/assets/icons/media-dark.svg", "light": "/assets/icons/media-light.svg" @@ -1537,7 +1537,7 @@ { "command": "frontMatter.insertSnippet", "title": "Insert snippet into your content", - "category": "Front matter", + "category": "Front Matter", "icon": { "dark": "/assets/icons/scissors-dark.svg", "light": "/assets/icons/scissors-light.svg" @@ -1546,12 +1546,12 @@ { "command": "frontMatter.insertTags", "title": "Insert tags", - "category": "Front matter" + "category": "Front Matter" }, { "command": "frontMatter.markup.italic", "title": "Italic", - "category": "Front matter", + "category": "Front Matter", "icon": { "light": "assets/icons/italic-light.svg", "dark": "assets/icons/italic-dark.svg" @@ -1560,7 +1560,7 @@ { "command": "frontMatter.dashboard", "title": "Open dashboard", - "category": "Front matter", + "category": "Front Matter", "icon": { "dark": "/assets/icons/frontmatter-small-dark.svg", "light": "/assets/icons/frontmatter-small-light.svg" @@ -1569,7 +1569,7 @@ { "command": "frontMatter.dashboard.data", "title": "Open data dashboard", - "category": "Front matter", + "category": "Front Matter", "icon": { "dark": "/assets/icons/frontmatter-small-dark.svg", "light": "/assets/icons/frontmatter-small-light.svg" @@ -1578,7 +1578,7 @@ { "command": "frontMatter.dashboard.media", "title": "Open media dashboard", - "category": "Front matter", + "category": "Front Matter", "icon": { "dark": "/assets/icons/frontmatter-small-dark.svg", "light": "/assets/icons/frontmatter-small-light.svg" @@ -1587,7 +1587,7 @@ { "command": "frontMatter.dashboard.snippets", "title": "Open snippets dashboard", - "category": "Front matter", + "category": "Front Matter", "icon": { "dark": "/assets/icons/frontmatter-small-dark.svg", "light": "/assets/icons/frontmatter-small-light.svg" @@ -1596,7 +1596,7 @@ { "command": "frontMatter.dashboard.taxonomy", "title": "Open taxonomies dashboard", - "category": "Front matter", + "category": "Front Matter", "icon": { "dark": "/assets/icons/frontmatter-small-dark.svg", "light": "/assets/icons/frontmatter-small-light.svg" @@ -1605,7 +1605,7 @@ { "command": "frontMatter.markup.orderedlist", "title": "Ordered list", - "category": "Front matter", + "category": "Front Matter", "icon": { "light": "assets/icons/ordered-list-light.svg", "dark": "assets/icons/ordered-list-dark.svg" @@ -1614,7 +1614,7 @@ { "command": "frontMatter.markup.options", "title": "Other markup options", - "category": "Front matter", + "category": "Front Matter", "icon": { "light": "assets/icons/options-light.svg", "dark": "assets/icons/options-dark.svg" @@ -1623,27 +1623,27 @@ { "command": "frontMatter.preview", "title": "Preview content", - "category": "Front matter" + "category": "Front Matter" }, { "command": "frontMatter.promoteSettings", "title": "Promote settings from local to team level", - "category": "Front matter" + "category": "Front Matter" }, { "command": "frontMatter.remap", "title": "Remap or remove tag/category in all articles", - "category": "Front matter" + "category": "Front Matter" }, { "command": "frontMatter.setLastModifiedDate", "title": "Set lastmod date", - "category": "Front matter" + "category": "Front Matter" }, { "command": "frontMatter.markup.strikethrough", "title": "Strikethrough", - "category": "Front matter", + "category": "Front Matter", "icon": { "light": "assets/icons/strikethrough-light.svg", "dark": "assets/icons/strikethrough-dark.svg" @@ -1652,22 +1652,27 @@ { "command": "frontMatter.mode.switch", "title": "Switch mode", - "category": "Front matter", + "category": "Front Matter", "icon": "$(preview)" }, { "command": "frontMatter.markup.tasklist", "title": "Task list", - "category": "Front matter" + "category": "Front Matter" }, { "command": "frontMatter.markup.unorderedlist", "title": "Unordered list", - "category": "Front matter", + "category": "Front Matter", "icon": { "light": "assets/icons/unordered-list-light.svg", "dark": "assets/icons/unordered-list-dark.svg" } + }, + { + "command": "frontMatter.git.sync", + "title": "Sync", + "category": "Front Matter" } ], "menus": { @@ -1786,6 +1791,10 @@ "command": "frontMatter.dashboard.snippets", "when": "frontMatter:dashboard:snippets:enabled" }, + { + "command": "frontMatter.git.sync", + "when": "frontMatter:git:enabled" + }, { "command": "frontMatter.collapseSections", "when": "false" diff --git a/src/constants/Extension.ts b/src/constants/Extension.ts index e3cffae4..ada6a795 100644 --- a/src/constants/Extension.ts +++ b/src/constants/Extension.ts @@ -62,4 +62,7 @@ export const COMMAND_NAME = { generateContentType: getCommandName("contenttype.generate"), addMissingFields: getCommandName("contenttype.addMissingFields"), setContentType: getCommandName("contenttype.setContentType"), + + // Git + gitSync: getCommandName("git.sync"), }; \ No newline at end of file diff --git a/src/constants/TelemetryEvent.ts b/src/constants/TelemetryEvent.ts index 4b6bb928..302a1327 100644 --- a/src/constants/TelemetryEvent.ts +++ b/src/constants/TelemetryEvent.ts @@ -43,4 +43,7 @@ export const TelemetryEvent = { webviewContentsView: 'webviewContentsView', webviewSnippetsView: 'webviewSnippetsView', webviewTaxonomyDashboard: 'webviewTaxonomyDashboard', + + // Git + gitSync: 'gitSync', }; \ No newline at end of file diff --git a/src/constants/context.ts b/src/constants/context.ts index 007ddae4..4878599d 100644 --- a/src/constants/context.ts +++ b/src/constants/context.ts @@ -13,4 +13,6 @@ export const CONTEXT = { isSnippetsDashboardEnabled: "frontMatter:dashboard:snippets:enabled", isDataDashboardEnabled: "frontMatter:dashboard:data:enabled", + + isGitEnabled: "frontMatter:git:enabled", }; \ No newline at end of file diff --git a/src/extension.ts b/src/extension.ts index e5a7201b..84cd562d 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -1,3 +1,4 @@ +import { GitListener } from './listeners/general/GitListener'; import * as vscode from 'vscode'; import { Telemetry } from './helpers/Telemetry'; import { ContentType } from './helpers/ContentType'; @@ -202,6 +203,7 @@ export async function activate(context: vscode.ExtensionContext) { SettingsHelper.onConfigChange((global?: any) => { Template.init(); Preview.init(); + GitListener.init(); SettingsListener.getSettings(); DataListener.getFoldersAndFiles(); @@ -261,6 +263,9 @@ export async function activate(context: vscode.ExtensionContext) { // Diagnostics subscriptions.push(vscode.commands.registerCommand(COMMAND_NAME.diagnostics, Diagnostics.show)); + // Git + GitListener.init(); + // Subscribe all commands subscriptions.push( insertTags, diff --git a/src/helpers/Extension.ts b/src/helpers/Extension.ts index 31847e65..4ab882ec 100644 --- a/src/helpers/Extension.ts +++ b/src/helpers/Extension.ts @@ -104,10 +104,20 @@ export class Extension { return this.ctx.extensionMode === ExtensionMode.Production; } + /** + * Get the diagnostic collection for the extension + */ public get diagnosticCollection(): DiagnosticCollection { return this._collection; } + /** + * Get extension subscriptions + */ + public get subscriptions() { + return this.ctx.subscriptions; + } + /** * Set the current version information for the extension */ diff --git a/src/listeners/general/GitListener.ts b/src/listeners/general/GitListener.ts index a5271457..82b19e32 100644 --- a/src/listeners/general/GitListener.ts +++ b/src/listeners/general/GitListener.ts @@ -1,15 +1,39 @@ import { Settings } from './../../helpers/SettingsHelper'; import { Dashboard } from '../../commands/Dashboard'; import { ExplorerView } from '../../explorerView/ExplorerView'; -import { Extension, Logger } from '../../helpers'; +import { Extension, Logger, Telemetry } from '../../helpers'; import { GeneralCommands } from './../../constants/GeneralCommands'; import simpleGit, { SimpleGit } from 'simple-git'; -import { SETTING_GIT_COMMIT_MSG } from '../../constants'; +import { COMMAND_NAME, CONTEXT, SETTING_GIT_COMMIT_MSG, SETTING_GIT_ENABLED, TelemetryEvent } from '../../constants'; import { Folders } from '../../commands/Folders'; +import { commands } from 'vscode'; export class GitListener { + private static isRegistered: boolean = false; private static client: SimpleGit | null = null; + public static async init() { + let isEnabled = false; + const gitEnabled = Settings.get(SETTING_GIT_ENABLED); + if (gitEnabled) { + const isRepo = await GitListener.isGitRepository(); + if (isRepo) { + isEnabled = true; + } + } + + await commands.executeCommand('setContext', CONTEXT.isGitEnabled, isEnabled); + + if (!this.isRegistered) { + const ext = Extension.getInstance(); + ext.subscriptions.push( + commands.registerCommand(COMMAND_NAME.gitSync, GitListener.sync) + ); + + this.isRegistered = true; + } + } + /** * Process the messages * @param msg @@ -26,6 +50,8 @@ export class GitListener { try { this.sendMsg(GeneralCommands.toWebview.gitSyncingStart, {}); + Telemetry.send(TelemetryEvent.gitSync); + await this.pull(); await this.push(); @@ -86,6 +112,10 @@ export class GitListener { } private static getClient() { + if (this.client) { + return this.client; + } + const wsFolder = Folders.getWorkspaceFolder(); const options = { @@ -94,7 +124,8 @@ export class GitListener { maxConcurrentProcesses: 6, } - return simpleGit(options); + this.client = simpleGit(options); + return this.client; } private static sendMsg(command: string, data: any) {