Skip to content

Commit

Permalink
Merge pull request #1 from Bellisario/auto-update-dev
Browse files Browse the repository at this point in the history
Update Check
  • Loading branch information
Bellisario committed Sep 5, 2021
2 parents d8403df + 9492212 commit cf84688
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:

- name: Build
shell: cmd
run: build.bat
run: build.bat ${{ github.event.inputs.version }}

- name: Upload Binaries to Release
uses: svenstaro/upload-release-action@v2
Expand Down
38 changes: 38 additions & 0 deletions app/extensions/update-checker/background.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
if (chrome)
var browser = chrome;

var debug = false;

(async function () {
var version = await fetch(browser.runtime.getURL('version.txt'));
version = await version.text();
if (version.includes('default') && debug === false)
return console.log('Not checking for updates:\nChromeTemp is running from source (dev mode).');
console.log('Checking for updates...');
var latest = await fetch('https://github.com/Bellisario/ChromeTemp/releases/latest');
latest = latest.url.replace('https://github.com/Bellisario/ChromeTemp/releases/tag/', '');
console.log('Current version:', version, '\nLatest version:', latest);
if (!version.includes(latest)) {
console.log('Update available.');
await new Promise(r => setTimeout(r, 10000));
notification = browser.notifications.create('chrome-temp.updater', {
title: 'ChromeTemp Update Available',
message: 'Click here to open the download page.',
iconUrl: browser.runtime.getURL('chrome-temp.png'),
type: 'basic',
requireInteraction: true
});
browser.notifications.onClicked.addListener(function () {
browser.notifications.clear('chrome-temp.updater');
browser.tabs.create({url: 'https://github.com/Bellisario/ChromeTemp/releases/latest'});
});
} else {
console.log('No update found.');
};
})();

browser.browserAction.onClicked.addListener(function () {
browser.tabs.create({
url: 'https://github.com/Bellisario/ChromeTemp/releases/latest'
});
});
Binary file added app/extensions/update-checker/chrome-temp.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 22 additions & 0 deletions app/extensions/update-checker/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "ChromeTemp Updater",
"description": "This is the update checker of ChromeTemp.",
"version": "1.0",
"permissions": [
"tabs",
"activeTab",
"webRequest",
"notifications",
"<all_urls>"
],
"background": {
"scripts": ["background.js"]
},
"browser_action": {
"default_title": ""
},
"manifest_version": 2,
"icons": {
"128": "chrome-temp.png"
}
}
1 change: 1 addition & 0 deletions app/extensions/update-checker/version.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
default
5 changes: 3 additions & 2 deletions app/run.bat
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ set welcome="file:///%cd%/welcome.html?url=%urlToLoad%"
set welcomeAdvanced="file:///%cd%/welcome.html?url=%urlToLoad%&advanced=true"
set extensionManager="%cd%/extensions/manager/"
set extensionDDG="%cd%/extensions/duckduckgo/"
set extensionUpdater="%cd%/extensions/update-checker/"
cd ..\temps
set temp="%cd%"
set folder="%cd%\chromeTemp-%random%"
Expand All @@ -27,7 +28,7 @@ if defined Command goto :startChrome

:startChrome
if %advanced% == 1 goto :startChromeAdvanced
start "" "chrome" --start-maximized --user-data-dir=%folder% %welcome% --load-extension=%extensionManager%,%extensionDDG%
start "" /WAIT "chrome" --start-maximized --no-default-browser-check --no-first-run --user-data-dir=%folder% %welcome% --load-extension=%extensionManager%,%extensionUpdater%,%extensionDDG%
echo ChromeTemp started: waiting for close.
goto :endStartChrome
:startChromeAdvanced
Expand Down Expand Up @@ -72,4 +73,4 @@ start error.bat
echo End!

timeout /t 5 /nobreak>nul
exit
exit
14 changes: 14 additions & 0 deletions build.bat
Original file line number Diff line number Diff line change
@@ -1,12 +1,26 @@
@echo off

set build="%cd%\temps\build"
if [%1] == [] goto :versionDefault
set "version=%1"
echo Using %version% as version for build
echo.
goto :endVersion
:versionDefault
echo Not specified any version, using default
echo.
set version=default
:endVersion
echo|set /p="Building... "
if not exist %build% mkdir %build%
xcopy /S .\app\*.* %build%\app\ /Y>nul || goto :error
copy .\app\first-run\RUNME.bat %build%\RUNME.bat>nul || goto :error
mkdir %build%\temps || goto :error
copy .\temps\README.txt %build%\temps\README.txt>nul || goto :error

REM Write version file
echo %version% > %build%\app\extensions\update-checker\version.txt

echo OK.
echo|set /p="Making zip... "
if exist .\temps\chrome-temp.zip del .\temps\chrome-temp.zip
Expand Down

0 comments on commit cf84688

Please sign in to comment.