Skip to content
This repository has been archived by the owner on Apr 3, 2022. It is now read-only.

Commit

Permalink
Added caching of the user's channel name
Browse files Browse the repository at this point in the history
  • Loading branch information
Stekeblad committed Jun 11, 2020
1 parent 39f01f6 commit 81ebe94
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 11 deletions.
45 changes: 34 additions & 11 deletions src/main/java/io/github/stekeblad/videouploader/main/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ public void start(Stage primaryStage) {
"Failed to load translations, unable to launch. Your detected language: " + Locale.getDefault(), e);
return;
}
Translations trans = TranslationsManager.getTranslation(TranslationBundles.BASE);

// Set the default exception handler, hopefully it can catch some of the exceptions that is not already caught
Thread.setDefaultUncaughtExceptionHandler((thread, exception) -> AlertUtils.unhandledExceptionDialog(exception));
Expand All @@ -46,16 +45,8 @@ public void start(Stage primaryStage) {
MyStage stage = new MyStage(ConfigManager.WindowPropertyNames.MAIN);
stage.makeScene(loader.load(), Constants.MAIN_WINDOW_DIMENSIONS_RESTRICTION);

// Show channel name in window title.
if (configManager.getNeverAuthed()) {
stage.setTitle(trans.getString("app_name"));
} else {
String channelName = Auth.getChannelName();
if (channelName != null)
stage.setTitle(trans.getString("app_name") + " - (" + channelName + ")");
else
stage.setTitle(trans.getString("app_name"));
}
// Show channel name in window title, if authenticated.
stage.setTitle(getWindowTitle());

customizeTooltip();

Expand All @@ -66,6 +57,38 @@ public void start(Stage primaryStage) {
}
}

/**
* If the user has authenticated with YouTube, then an attempt is made
* to show the name of the user's channel in the window title. In order to save time and quota
* may the channel name already be saved in the settings file and loaded from there instead of
* requested from YouTube.
*
* @return A string to show in the window title
*/
private String getWindowTitle() {
Translations trans = TranslationsManager.getTranslation(TranslationBundles.BASE);
// If the user has never authed, only use program name
if (configManager.getNeverAuthed()) {
return trans.getString("app_name");
}
// then check the settings
else if (configManager.getChannelName() == null || configManager.getChannelName().equals("")) {
// Not there, get from YouTube
String channelName = Auth.getChannelName();
if (channelName != null) {
// success, save and return program name + channel name
configManager.setChannelName(channelName);
return trans.getString("app_name") + " - (" + channelName + ")";
} else {
// failure, only return program name
return trans.getString("app_name");
}
} else {
// return program name and saved channel name
return trans.getString("app_name") + " - (" + configManager.getChannelName() + ")";
}
}

private void loadTranslations() throws Exception {
configManager = ConfigManager.INSTANCE;
configManager.configManager();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ private void loadSettings() {
setIfMissing("ui_language", String.valueOf(Locale.getDefault()));
setIfMissing("checkForUpdates", "true");
setIfMissing("silentUpdates", "false");
setIfMissing("channelName", "");

// width x height
setIfMissing(WIN_SIZE + WindowPropertyNames.MAIN, "900x750");
Expand Down Expand Up @@ -207,6 +208,14 @@ public void setSilentUpdates(boolean silentUpdates) {
mainProp.setProperty("silentUpdates", silentUpdates ? "true" : "false");
}

public String getChannelName() {
return mainProp.getProperty("channelName");
}

public void setChannelName(String channelName) {
mainProp.setProperty("channelName", channelName);
}

private static final String WIN_LOC = "window_location_";
private static final String WIN_SIZE = "window_size_";

Expand Down

0 comments on commit 81ebe94

Please sign in to comment.