Skip to content

Commit a81bceb

Browse files
committed
fix: In the Logseq 0.9.2 version, there is an issue with the panel display that needs to be fixed.
1 parent 8161327 commit a81bceb

3 files changed

Lines changed: 261 additions & 197 deletions

File tree

src/helper/constants.ts

Lines changed: 50 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,27 @@
1-
import { SettingSchemaDesc } from "@logseq/libs/dist/LSPlugin.user"
1+
import { SettingSchemaDesc } from "@logseq/libs/dist/LSPlugin.user";
22

33
export const COMMON_STYLE = `
44
#injected-ui-item-git-logseq-git {
55
position: relative;
66
}
7-
#injected-ui-item-git-logseq-git #logseq-git--git #plugin-git-content-wrapper {
8-
position: absolute;
9-
top: 36px;
10-
left: 50%;
11-
transform: translateX(-50%);
7+
.plugin-git-container .plugin-git-mask {
8+
position: fixed;
9+
width: 100vw;
10+
height: 100vh;
11+
left: 0;
12+
top: 0;
13+
z-index: 99;
14+
}
15+
.plugin-git-container .plugin-git-popup {
16+
position: fixed;
17+
z-index: 99;
1218
background-color: var(--ls-secondary-background-color);
1319
padding: 10px;
1420
border-radius: .375rem;
1521
--tw-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1),0 4px 6px -2px rgba(0, 0, 0, 0.05);
1622
box-shadow: var(--tw-ring-offset-shadow,0 0 #0000),var(--tw-ring-shadow,0 0 #0000),var(--tw-shadow);
17-
display: none;
1823
}
19-
#injected-ui-item-git-logseq-git #logseq-git--git #plugin-git-content-wrapper::before {
24+
.plugin-git-container .plugin-git-popup::before {
2025
content: '';
2126
position: absolute;
2227
top: -8px;
@@ -28,33 +33,25 @@ export const COMMON_STYLE = `
2833
border-width: 0 10px 8px 10px;
2934
border-color: transparent transparent var(--ls-secondary-background-color) transparent;
3035
}
31-
#injected-ui-item-git-logseq-git #logseq-git--git #plugin-git-content-wrapper .plugin-git-mask {
32-
position: absolute;
33-
z-index: -1;
34-
width: 100vw;
35-
height: 100vh;
36-
top: -36px;
37-
left: -70vw;
38-
}
39-
`
36+
`;
4037

4138
export const SHOW_POPUP_STYLE = `
42-
#injected-ui-item-git-logseq-git #logseq-git--git #plugin-git-content-wrapper {
39+
.plugin-git-container {
4340
display: block;
4441
}
45-
`
42+
`;
4643
export const HIDE_POPUP_STYLE = `
47-
#injected-ui-item-git-logseq-git #logseq-git--git #plugin-git-content-wrapper {
44+
.plugin-git-container {
4845
display: none;
4946
}
50-
`
47+
`;
5148

5249
export const INACTIVE_STYLE = `
5350
${COMMON_STYLE}
5451
#injected-ui-item-git-logseq-git::after {
5552
display: none;
5653
}
57-
`
54+
`;
5855
export const ACTIVE_STYLE = `
5956
${COMMON_STYLE}
6057
#injected-ui-item-git-logseq-git::after {
@@ -68,7 +65,7 @@ ${COMMON_STYLE}
6865
right: 8px;
6966
top: 6px;
7067
}
71-
`
68+
`;
7269

7370
export const LOADING_STYLE = `
7471
${COMMON_STYLE}
@@ -95,48 +92,49 @@ ${COMMON_STYLE}
9592
opacity: 0;
9693
}
9794
}
98-
`
95+
`;
9996

10097
export const BUTTONS = [
101-
{ key: 'status', title: 'Check Status', event: 'check' },
102-
{ key: 'log', title: 'Show Log', event: 'log' },
103-
{ key: 'pull', title: 'Pull', event: 'pull' },
104-
{ key: 'pullRebase', title: 'Pull Rebase', event: 'pullRebase' },
105-
{ key: 'checkout', title: 'Checkout', event: 'checkout' },
106-
{ key: 'commit', title: 'Commit', event: 'commit' },
107-
{ key: 'push', title: 'Push', event: 'push' },
108-
{ key: 'commitAndPush', title: 'Commit & Push', event: 'commitAndPush' },
109-
]
98+
{ key: "status", title: "Check Status", event: "check" },
99+
{ key: "log", title: "Show Log", event: "log" },
100+
{ key: "pull", title: "Pull", event: "pull" },
101+
{ key: "pullRebase", title: "Pull Rebase", event: "pullRebase" },
102+
{ key: "checkout", title: "Checkout", event: "checkout" },
103+
{ key: "commit", title: "Commit", event: "commit" },
104+
{ key: "push", title: "Push", event: "push" },
105+
{ key: "commitAndPush", title: "Commit & Push", event: "commitAndPush" },
106+
];
110107

111108
export const SETTINGS_SCHEMA: SettingSchemaDesc[] = [
112109
{
113-
key: 'buttons',
114-
title: 'Buttons',
115-
type: 'enum',
116-
default: ['Check Status', 'Show Log', 'Pull Rebase', 'Commit & Push'],
117-
description: 'Select buttons to show',
118-
enumPicker: 'checkbox',
110+
key: "buttons",
111+
title: "Buttons",
112+
type: "enum",
113+
default: ["Check Status", "Show Log", "Pull Rebase", "Commit & Push"],
114+
description: "Select buttons to show",
115+
enumPicker: "checkbox",
119116
enumChoices: BUTTONS.map(({ title }) => title),
120117
},
121118
{
122-
key: 'checkWhenDBChanged',
123-
title: 'Check Status when DB Changed',
124-
type: 'boolean',
119+
key: "checkWhenDBChanged",
120+
title: "Check Status when DB Changed",
121+
type: "boolean",
125122
default: true,
126-
description: 'Check status when DB changed, restart logseq to take effect',
123+
description: "Check status when DB changed, restart logseq to take effect",
127124
},
128125
{
129-
key: 'autoCheckSynced',
130-
title: 'Auto Check If Synced',
131-
type: 'boolean',
126+
key: "autoCheckSynced",
127+
title: "Auto Check If Synced",
128+
type: "boolean",
132129
default: false,
133-
description: 'Automatically check if the local version is the same as the remote',
130+
description:
131+
"Automatically check if the local version is the same as the remote",
134132
},
135133
{
136-
key: 'autoPush',
137-
title: 'Auto Push',
138-
type: 'boolean',
134+
key: "autoPush",
135+
title: "Auto Push",
136+
type: "boolean",
139137
default: false,
140-
description: 'Auto push when logseq hide',
138+
description: "Auto push when logseq hide",
141139
},
142-
]
140+
];

src/helper/util.ts

Lines changed: 64 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,86 @@
1-
import { ACTIVE_STYLE, HIDE_POPUP_STYLE, INACTIVE_STYLE, SHOW_POPUP_STYLE } from './constants'
2-
import { status } from './git'
1+
import {
2+
ACTIVE_STYLE,
3+
HIDE_POPUP_STYLE,
4+
INACTIVE_STYLE,
5+
SHOW_POPUP_STYLE,
6+
} from "./constants";
7+
import { status } from "./git";
38

49
export const checkStatus = async () => {
5-
console.log('Checking status...')
6-
const statusRes = await status(false)
7-
if (statusRes?.stdout === '') {
8-
console.log('No changes', statusRes)
9-
setPluginStyle(INACTIVE_STYLE)
10+
console.log("Checking status...");
11+
const statusRes = await status(false);
12+
if (statusRes?.stdout === "") {
13+
console.log("No changes", statusRes);
14+
setPluginStyle(INACTIVE_STYLE);
1015
} else {
11-
console.log('Need save', statusRes)
12-
setPluginStyle(ACTIVE_STYLE)
16+
console.log("Need save", statusRes);
17+
setPluginStyle(ACTIVE_STYLE);
1318
}
14-
return statusRes
15-
}
19+
return statusRes;
20+
};
1621

17-
let pluginStyle = ''
22+
let pluginStyle = "";
1823
export const setPluginStyle = (style: string) => {
19-
pluginStyle = style
20-
logseq.provideStyle({ key: 'git', style })
21-
}
22-
export const getPluginStyle = () => pluginStyle
23-
24+
pluginStyle = style;
25+
logseq.provideStyle({ key: "git", style });
26+
};
27+
export const getPluginStyle = () => pluginStyle;
2428

2529
export const showPopup = () => {
26-
const _style = getPluginStyle()
27-
setPluginStyle(`${_style}\n${SHOW_POPUP_STYLE}`)
28-
}
30+
const _style = getPluginStyle();
31+
logseq.App.queryElementRect("#logseq-git--git").then((triggerIconRect) => {
32+
console.log("[faiz:] === triggerIconRect", triggerIconRect);
33+
if (!triggerIconRect) return;
34+
const popupWidth = 120 + 10 * 2;
35+
const left =
36+
triggerIconRect.left + triggerIconRect.width / 2 - popupWidth / 2;
37+
const top = triggerIconRect.top + triggerIconRect.height;
38+
const _style = getPluginStyle();
39+
setPluginStyle(
40+
`${_style}\n.plugin-git-popup{left:${left}px;top:${top}px;}`
41+
);
42+
});
43+
setPluginStyle(`${_style}\n${SHOW_POPUP_STYLE}`);
44+
};
2945
export const hidePopup = () => {
30-
const _style = getPluginStyle()
31-
setPluginStyle(`${_style}\n${HIDE_POPUP_STYLE}`)
32-
}
33-
46+
const _style = getPluginStyle();
47+
setPluginStyle(`${_style}\n${HIDE_POPUP_STYLE}`);
48+
};
3449

3550
export const debounce = (fn, wait: number = 100, environment?: any) => {
36-
let timer = null
37-
return function() {
51+
let timer = null;
52+
return function () {
3853
// @ts-ignore
39-
const context = environment || this
40-
const args = arguments
54+
const context = environment || this;
55+
const args = arguments;
4156
if (timer) {
42-
clearTimeout(timer)
43-
timer = null
57+
clearTimeout(timer);
58+
timer = null;
4459
}
4560
// @ts-ignore
4661
timer = setTimeout(function () {
47-
fn.apply(context, args)
48-
}, wait)
49-
}
50-
}
62+
fn.apply(context, args);
63+
}, wait);
64+
};
65+
};
5166

5267
export const checkStatusWithDebounce = debounce(() => {
53-
checkStatus()
54-
}, 2000)
68+
checkStatus();
69+
}, 2000);
5570

5671
export const isRepoUpTodate = async () => {
57-
await logseq.Git.execCommand(['fetch'])
58-
const local = await logseq.Git.execCommand(['rev-parse', 'HEAD'])
59-
const remote = await logseq.Git.execCommand(['rev-parse', '@{u}'])
60-
return local.stdout === remote.stdout
61-
}
72+
await logseq.Git.execCommand(["fetch"]);
73+
const local = await logseq.Git.execCommand(["rev-parse", "HEAD"]);
74+
const remote = await logseq.Git.execCommand(["rev-parse", "@{u}"]);
75+
return local.stdout === remote.stdout;
76+
};
6277

6378
export const checkIsSynced = async () => {
64-
const isSynced = await isRepoUpTodate()
65-
if (!isSynced) logseq.UI.showMsg(`The current repository is not synchronized with the remote repository, please check.`, 'warning', { timeout: 0 })
66-
}
79+
const isSynced = await isRepoUpTodate();
80+
if (!isSynced)
81+
logseq.UI.showMsg(
82+
`The current repository is not synchronized with the remote repository, please check.`,
83+
"warning",
84+
{ timeout: 0 }
85+
);
86+
};

0 commit comments

Comments
 (0)