generated from haydenull/logseq-plugin-react-boilerplate
-
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: In the Logseq 0.9.2 version, there is an issue with the panel di…
…splay that needs to be fixed.
- Loading branch information
Showing
3 changed files
with
261 additions
and
197 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,66 +1,86 @@ | ||
import { ACTIVE_STYLE, HIDE_POPUP_STYLE, INACTIVE_STYLE, SHOW_POPUP_STYLE } from './constants' | ||
import { status } from './git' | ||
import { | ||
ACTIVE_STYLE, | ||
HIDE_POPUP_STYLE, | ||
INACTIVE_STYLE, | ||
SHOW_POPUP_STYLE, | ||
} from "./constants"; | ||
import { status } from "./git"; | ||
|
||
export const checkStatus = async () => { | ||
console.log('Checking status...') | ||
const statusRes = await status(false) | ||
if (statusRes?.stdout === '') { | ||
console.log('No changes', statusRes) | ||
setPluginStyle(INACTIVE_STYLE) | ||
console.log("Checking status..."); | ||
const statusRes = await status(false); | ||
if (statusRes?.stdout === "") { | ||
console.log("No changes", statusRes); | ||
setPluginStyle(INACTIVE_STYLE); | ||
} else { | ||
console.log('Need save', statusRes) | ||
setPluginStyle(ACTIVE_STYLE) | ||
console.log("Need save", statusRes); | ||
setPluginStyle(ACTIVE_STYLE); | ||
} | ||
return statusRes | ||
} | ||
return statusRes; | ||
}; | ||
|
||
let pluginStyle = '' | ||
let pluginStyle = ""; | ||
export const setPluginStyle = (style: string) => { | ||
pluginStyle = style | ||
logseq.provideStyle({ key: 'git', style }) | ||
} | ||
export const getPluginStyle = () => pluginStyle | ||
|
||
pluginStyle = style; | ||
logseq.provideStyle({ key: "git", style }); | ||
}; | ||
export const getPluginStyle = () => pluginStyle; | ||
|
||
export const showPopup = () => { | ||
const _style = getPluginStyle() | ||
setPluginStyle(`${_style}\n${SHOW_POPUP_STYLE}`) | ||
} | ||
const _style = getPluginStyle(); | ||
logseq.App.queryElementRect("#logseq-git--git").then((triggerIconRect) => { | ||
console.log("[faiz:] === triggerIconRect", triggerIconRect); | ||
if (!triggerIconRect) return; | ||
const popupWidth = 120 + 10 * 2; | ||
const left = | ||
triggerIconRect.left + triggerIconRect.width / 2 - popupWidth / 2; | ||
const top = triggerIconRect.top + triggerIconRect.height; | ||
const _style = getPluginStyle(); | ||
setPluginStyle( | ||
`${_style}\n.plugin-git-popup{left:${left}px;top:${top}px;}` | ||
); | ||
}); | ||
setPluginStyle(`${_style}\n${SHOW_POPUP_STYLE}`); | ||
}; | ||
export const hidePopup = () => { | ||
const _style = getPluginStyle() | ||
setPluginStyle(`${_style}\n${HIDE_POPUP_STYLE}`) | ||
} | ||
|
||
const _style = getPluginStyle(); | ||
setPluginStyle(`${_style}\n${HIDE_POPUP_STYLE}`); | ||
}; | ||
|
||
export const debounce = (fn, wait: number = 100, environment?: any) => { | ||
let timer = null | ||
return function() { | ||
let timer = null; | ||
return function () { | ||
// @ts-ignore | ||
const context = environment || this | ||
const args = arguments | ||
const context = environment || this; | ||
const args = arguments; | ||
if (timer) { | ||
clearTimeout(timer) | ||
timer = null | ||
clearTimeout(timer); | ||
timer = null; | ||
} | ||
// @ts-ignore | ||
timer = setTimeout(function () { | ||
fn.apply(context, args) | ||
}, wait) | ||
} | ||
} | ||
fn.apply(context, args); | ||
}, wait); | ||
}; | ||
}; | ||
|
||
export const checkStatusWithDebounce = debounce(() => { | ||
checkStatus() | ||
}, 2000) | ||
checkStatus(); | ||
}, 2000); | ||
|
||
export const isRepoUpTodate = async () => { | ||
await logseq.Git.execCommand(['fetch']) | ||
const local = await logseq.Git.execCommand(['rev-parse', 'HEAD']) | ||
const remote = await logseq.Git.execCommand(['rev-parse', '@{u}']) | ||
return local.stdout === remote.stdout | ||
} | ||
await logseq.Git.execCommand(["fetch"]); | ||
const local = await logseq.Git.execCommand(["rev-parse", "HEAD"]); | ||
const remote = await logseq.Git.execCommand(["rev-parse", "@{u}"]); | ||
return local.stdout === remote.stdout; | ||
}; | ||
|
||
export const checkIsSynced = async () => { | ||
const isSynced = await isRepoUpTodate() | ||
if (!isSynced) logseq.UI.showMsg(`The current repository is not synchronized with the remote repository, please check.`, 'warning', { timeout: 0 }) | ||
} | ||
const isSynced = await isRepoUpTodate(); | ||
if (!isSynced) | ||
logseq.UI.showMsg( | ||
`The current repository is not synchronized with the remote repository, please check.`, | ||
"warning", | ||
{ timeout: 0 } | ||
); | ||
}; |
Oops, something went wrong.