Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuakto committed Mar 7, 2024
2 parents e77d5c3 + 7ba0867 commit dea0ace
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 48 deletions.
50 changes: 19 additions & 31 deletions main.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Notice, Platform, Plugin } from 'obsidian';
import { Notice, Plugin } from 'obsidian';
import { Fit } from 'src/fit';
import { FitPull } from 'src/fitPull';
import { FitPush } from 'src/fitPush';
Expand All @@ -15,22 +15,14 @@ export interface FitSettings {
}

const DEFAULT_SETTINGS: FitSettings = {
pat: "<Personal-Access-Token>",
owner: "<Github-Username>",
repo: "<Repository-Name>",
branch: "main",
pat: "",
owner: "",
repo: "",
branch: "",
deviceName: "",
singleButtonMode: false
singleButtonMode: true
}

const DEFAULT_MOBILE_SETTINGS: FitSettings = {
pat: "<Personal-Access-Token>",
owner: "<Github-Username>",
repo: "<Repository-Name>",
branch: "main",
deviceName: "",
singleButtonMode: false
}

export interface LocalStores {
localSha: Record<string, string>
Expand Down Expand Up @@ -60,15 +52,15 @@ export default class FitPlugin extends Plugin {
fitSyncRibbonIconEl: HTMLElement

checkSettingsConfigured(): boolean {
if (["<Personal-Access-Token> ", ""].includes(this.settings.pat)) {
if (this.settings.pat === "") {
new Notice("Please provide git personal access tokens in Fit settings and try again.")
return false
}
if (["<Github-Username>", ""].includes(this.settings.owner)) {
if (this.settings.owner === "") {
new Notice("Please provide git repo owner in Fit settings and try again.")
return false
}
if (["<Repository-Name>", ""].includes(this.settings.repo)) {
if (this.settings.repo === "") {
this.settings.repo = `obsidian-${this.app.vault.getName()}-storage`
}
this.fit.loadSettings(this.settings)
Expand Down Expand Up @@ -203,10 +195,10 @@ export default class FitPlugin extends Plugin {
return
}

initializeFitNotice(): Notice {
initializeFitNotice(addClasses = ["loading"]): Notice {
const notice = new Notice(" ", 0) // keep at least one empty space to make the height consistent
notice.noticeEl.addClass("fit-notice")
notice.noticeEl.addClass("loading")
notice.noticeEl.addClass("fit-notice")
addClasses.map(cls => notice.noticeEl.addClass(cls))
return notice
}

Expand Down Expand Up @@ -273,7 +265,7 @@ export default class FitPlugin extends Plugin {


async onload() {
await this.loadSettings(Platform.isMobile);
await this.loadSettings();
await this.loadLocalStore();
this.fit = new Fit(this.settings, this.localStore, this.app.vault)
this.vaultOps = new VaultOperations(this.app.vault)
Expand Down Expand Up @@ -304,22 +296,18 @@ export default class FitPlugin extends Plugin {
if (this.checkSettingsConfigured()) {
const updatedRemoteCommitSha = await this.fitPull.remoteHasUpdates()
if (updatedRemoteCommitSha) {
console.log(`Remote updated, latest remote commit sha: ${updatedRemoteCommitSha}.`)
} else {
console.log(`Local copy up to date.`)
}
const intervalNotice = this.initializeFitNotice(["static"]);
intervalNotice.setMessage("Remote update detected, please pull the latest changes.")
}
}
}, 5 * 60 * 1000));
}, 10 * 1000));
}

onunload() {}

async loadSettings(isMobile?: boolean) {
async loadSettings() {
const userSetting = await this.loadData()
let settings = Object.assign({}, DEFAULT_SETTINGS, userSetting);
if (isMobile && !userSetting) {
settings = Object.assign({}, DEFAULT_MOBILE_SETTINGS);
}
const settings = Object.assign({}, DEFAULT_SETTINGS, userSetting);
const settingsObj: FitSettings = Object.keys(DEFAULT_SETTINGS).reduce(
(obj, key: keyof FitSettings) => {
if (settings.hasOwnProperty(key)) {
Expand Down
6 changes: 3 additions & 3 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"id": "fit",
"name": "Fit",
"version": "1.0.6",
"minAppVersion": "0.15.0",
"description": "File gIT - a barebone git system for files in obsidian",
"version": "1.0.7",
"minAppVersion": "1.5.8",
"description": "Minimalist File gIT (FIT) to sync your files across mobile and desktop devices using GitHub.",
"author": "joshuakto",
"authorUrl": "https://github.com/joshuakto",
"fundingUrl": "https://www.buymeacoffee.com/joshuakto",
Expand Down
12 changes: 6 additions & 6 deletions src/fitSetting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default class FitSettingTab extends PluginSettingTab {
.setName('Github personal access token')
.setDesc('Remember to give it the appropriate access for reading and writing to the storage repo.')
.addText(text => text
.setPlaceholder('Enter your token')
.setPlaceholder('GitHub personal access token')
.setValue(this.plugin.settings.pat)
.onChange(async (value) => {
this.plugin.settings.pat = value;
Expand All @@ -28,7 +28,7 @@ export default class FitSettingTab extends PluginSettingTab {
.setName('Github username')
.setDesc('Your github handle.')
.addText(text => text
.setPlaceholder('Enter your username')
.setPlaceholder('GitHub username')
.setValue(this.plugin.settings.owner)
.onChange(async (value) => {
this.plugin.settings.owner = value;
Expand All @@ -38,7 +38,7 @@ export default class FitSettingTab extends PluginSettingTab {
.setName('Github repository name')
.setDesc('The repo you dedicate to tracking this vault.')
.addText(text => text
.setPlaceholder('Enter your repository name')
.setPlaceholder('Repository')
.setValue(this.plugin.settings.repo)
.onChange(async (value) => {
this.plugin.settings.repo = value;
Expand All @@ -48,7 +48,7 @@ export default class FitSettingTab extends PluginSettingTab {
.setName('Branch name')
.setDesc('The branch name you set to push to (default to main)')
.addText(text => text
.setPlaceholder('Enter the branch name')
.setPlaceholder('Branch name')
.setValue(this.plugin.settings.branch)
.onChange(async (value) => {
this.plugin.settings.branch = value;
Expand All @@ -59,7 +59,7 @@ export default class FitSettingTab extends PluginSettingTab {
.setName('Device name')
.setDesc('The name of this device, used to decorate commit message')
.addText(text => text
.setPlaceholder('Enter device name')
.setPlaceholder('Device name')
.setValue(this.plugin.settings.deviceName)
.onChange(async (value) => {
this.plugin.settings.deviceName = value;
Expand All @@ -68,7 +68,7 @@ export default class FitSettingTab extends PluginSettingTab {

new Setting(containerEl)
.setName('Single button mode')
.setDesc('Single button mode is in early alpha, (recommended to turn off and push and pull separately).')
.setDesc('Single button to sync your repo to github (In early alpha, please file an issue if you encounter error with steps to reproduce).')
.addToggle(selected=>selected
.setValue(this.plugin.settings.singleButtonMode)
.onChange(async (selected) => {
Expand Down
21 changes: 20 additions & 1 deletion styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@
overflow: hidden;
}

.fit-notice.static::after {
content: url("data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDI0IDI0IiBmaWxsPSJub25lIiBzdHJva2U9IiM5NDk0OTQiIHN0cm9rZS13aWR0aD0iMiIgc3Ryb2tlLWxpbmVjYXA9InJvdW5kIiBzdHJva2UtbGluZWpvaW49InJvdW5kIiBjbGFzcz0ibHVjaWRlIGx1Y2lkZS1naXRodWIiPjxwYXRoIGQ9Ik0xNSAyMnYtNGE0LjggNC44IDAgMCAwLTEtMy41YzMgMCA2LTIgNi01LjUuMDgtMS4yNS0uMjctMi40OC0xLTMuNS4yOC0xLjE1LjI4LTIuMzUgMC0zLjUgMCAwLTEgMC0zIDEuNS0yLjY0LS41LTUuMzYtLjUtOCAwQzYgMiA1IDIgNSAyYy0uMyAxLjE1LS4zIDIuMzUgMCAzLjVBNS40MDMgNS40MDMgMCAwIDAgNCA5YzAgMy41IDMgNS41IDYgNS41LS4zOS40OS0uNjggMS4wNS0uODUgMS42NS0uMTcuNi0uMjIgMS4yMy0uMTUgMS44NXY0Ii8+PHBhdGggZD0iTTkgMThjLTQuNTEgMi01LTItNy0yIi8+PC9zdmc+"); /* Add content to pseudo-element */
position: absolute; /* Set position to absolute */
width: 24px; /* Set width of the pseudo-element */
height: 24px; /* Set height of the pseudo-element */
top: 47%; /* Position at the center vertically */
left: 5.7%; /* Position at the center horizontally */
transform: translate(-50%, -50%); /* Center the pseudo-element */
}

.fit-notice.loading::after {
content: var(--custom-svg); /* Add content to pseudo-element */
position: absolute; /* Set position to absolute */
Expand All @@ -16,7 +26,16 @@
top: 15%; /* Position at the center vertically */
left: 2%; /* Position at the center horizontally */
transform: translate(-50%, -50%); /* Center the pseudo-element */
animation: spin 2s linear infinite; /* Apply spinning animation to the icon */
animation: spin-notice 2s linear infinite; /* Apply spinning animation to the icon */
}

@keyframes spin-notice {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}

.fit-notice.done::after {
Expand Down
15 changes: 8 additions & 7 deletions versions.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
{
"1.0.0": "0.15.0",
"1.0.1": "0.15.0",
"1.0.2": "0.15.0",
"1.0.3": "0.15.0",
"1.0.4": "0.15.0",
"1.0.5": "0.15.0",
"1.0.6": "0.15.0"
"1.0.0": "1.5.8",
"1.0.1": "1.5.8",
"1.0.2": "1.5.8",
"1.0.3": "1.5.8",
"1.0.4": "1.5.8",
"1.0.5": "1.5.8",
"1.0.6": "1.5.8",
"1.0.7": "1.5.8"
}

0 comments on commit dea0ace

Please sign in to comment.