Skip to content

Commit

Permalink
1.6.1 - Cleaning up GUI
Browse files Browse the repository at this point in the history
  • Loading branch information
mickeydarrenlau committed Aug 6, 2024
1 parent f981c28 commit 61e214b
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 11 deletions.
52 changes: 46 additions & 6 deletions main.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Platform, App, Editor, MarkdownView, Modal, Notice, Plugin, PluginManifest, PluginSettingTab, Setting, requestUrl } from 'obsidian';
import { Platform, App, Editor, MarkdownView, Modal, Notice, Plugin, PluginManifest, PluginSettingTab, Setting, requestUrl, SettingTab } from 'obsidian';
import { SpotifyApi, AccessToken } from '@spotify/web-api-ts-sdk';
import { RefreshClass } from './RefreshClass';

Expand Down Expand Up @@ -280,6 +280,7 @@ export default class ObsidianSpotify extends Plugin {
* @param this2 - The ObsidianSpotify object.
*/
async function spotify_auth_logout(manifest: PluginManifest, this2: ObsidianSpotify) {
try {
window.spotifysdk.logOut();
console.log(this2);
this2.settings.spotify_access_token = {
Expand All @@ -291,6 +292,10 @@ export default class ObsidianSpotify extends Plugin {
await this2.saveSettings();
RefreshClass.logoutOrunload({ sharedstuff, settings: this2.settings, manifest: manifest });
console.log("[" + manifest.name + "] Logged out");
try {
sharedstuff.get("refreshname")(this2)
} catch {}
} catch {}
}

sharedstuff.set("spotify_auth_login_function", spotify_auth_login);
Expand All @@ -312,6 +317,23 @@ export default class ObsidianSpotify extends Plugin {
}
});

async function refreshname(plugin: ObsidianSpotify) {
try {
if(plugin.settings.spotify_access_token.access_token) {
(async () => {
let data = await window.spotifysdk.currentUser.profile()
sharedstuff.get("usernametext").setText(data.display_name + " (" + data.id + ")")
})()
} else {
sharedstuff.get("usernametext").setText("Not logged in")
}
} catch(e) {
sharedstuff.get("usernametext").setText("Error getting username")
}
}

sharedstuff.set("refreshname", refreshname);

this.registerObsidianProtocolHandler("spotify/auth", async (e) => {
console.log("[" + this.manifest.name + "] Spotify Auth Code Received From Callback");
let correctstate = sharedstuff.get("spotifystate");
Expand Down Expand Up @@ -344,6 +366,9 @@ export default class ObsidianSpotify extends Plugin {
window.spotifysdk['authenticationStrategy'].refreshTokenAction = async () => { return; };
console.log("[" + this.manifest.name + "] Authed successfuly");
RefreshClass.refreshInit({ sharedstuff, refreshspot, settings: this.settings, manifest: this.manifest });
try {
sharedstuff.get("refreshname")(this)
} catch {}
});
}

Expand Down Expand Up @@ -376,6 +401,7 @@ export default class ObsidianSpotify extends Plugin {

class ObsidianSpotifySettingsTab extends PluginSettingTab {
plugin: ObsidianSpotify;
static display: any;

constructor(app: App, plugin: ObsidianSpotify) {
super(app, plugin);
Expand All @@ -389,7 +415,7 @@ class ObsidianSpotifySettingsTab extends PluginSettingTab {
containerEl.empty();
new Setting(containerEl)
.setName('Spotify Client ID')
.setDesc('Find it in your spotify dev')
.setDesc('Find it in your spotify developer dashboard')
.addText(text => text
.setPlaceholder('Enter your client ID')
.setValue(this.plugin.settings.spotify_client_id)
Expand All @@ -400,7 +426,7 @@ class ObsidianSpotifySettingsTab extends PluginSettingTab {

new Setting(containerEl)
.setName('Spotify Client secret')
.setDesc('Find it in your spotify dev')
.setDesc('Find it in your spotify developer dashboard')
.addText(text => text
.setPlaceholder('Enter your client secret')
.setValue(this.plugin.settings.spotify_client_secret)
Expand All @@ -409,22 +435,36 @@ class ObsidianSpotifySettingsTab extends PluginSettingTab {
await this.plugin.saveSettings();
}));
new Setting(containerEl)
.setName('Spotify Authentification')
.setDesc('Login or logout from spotify')
.addButton((btn) => btn
.setButtonText("Spotify auth")
.setButtonText("Login")
.setCta()
.onClick(async () => {

sharedstuff.get("spotify_auth_login_function")(this.plugin.settings.spotify_client_id, manifest)

}))
new Setting(containerEl)
.addButton((btn) => btn
.setButtonText("Spotify logout")
.setButtonText("Logout")
.setCta()
.onClick(async () => {

sharedstuff.get("spotify_auth_logout_function")(manifest, this.plugin)

}))

const usernamecontainer = new Setting(containerEl)
.setName('Logged in as')
.setDesc('The current logged in user')

const usernamewrapcontainer = usernamecontainer.controlEl.createDiv("spotify-api-refresh-token");
const usernametext = usernamewrapcontainer.createSpan()

sharedstuff.set("usernametext", usernametext)
sharedstuff.get("refreshname")(this.plugin)



}
}
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
"authorUrl": "https://github.com/Darren-project",
"fundingUrl": "https://www.buymeacoffee.com/mickeydarrenlau",
"isDesktopOnly": false,
"version": "1.6.0"
"version": "1.6.1"
}
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"builtin-modules": "3.3.0",
"esbuild": "0.17.3",
"obsidian": "latest",
"tslib": "^2.4.0"
"tslib": "^2.6.3"
},
"dependencies": {
"@spotify/web-api-ts-sdk": "^1.2.0",
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"DOM",
"ES5",
"ES6",
"ES7"
"ES7",
"ES2017"
]
},
"include": [
Expand Down
3 changes: 2 additions & 1 deletion versions.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@
"1.4.5": "0.15.0",
"1.5.0": "0.15.0",
"1.5.1": "0.15.0",
"1.6.0:": "0.15.0"
"1.6.0:": "0.15.0",
"1.6.1": "0.15.0"
}

0 comments on commit 61e214b

Please sign in to comment.