diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index b28952705..f8cfe2162 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -5,40 +5,31 @@ on: [push] jobs: lint-python: runs-on: ubuntu-latest - strategy: - matrix: - python-version: ["3.9", "3.10"] steps: - - uses: actions/checkout@v3 - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v3 - with: - python-version: ${{ matrix.python-version }} - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install pycodestyle - - name: Analysing the code with pycodestyle - run: | - pycodestyle --ignore=E501,W503 $(git ls-files 'learning_observer/*.py' 'modules/*.py') + - name: Checkout code + uses: actions/checkout@v3 + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: '3.11' + + - name: Install Make + run: sudo apt-get install make + + - name: Lint files + run: make linting-python lint-node: runs-on: ubuntu-latest steps: - name: Checkout code - uses: actions/checkout@v2 - - name: Set up Node.js - uses: actions/setup-node@v2 + uses: actions/checkout@v3 + - name: Set up Node + uses: actions/setup-node@v4 with: - node-version: '16.x' - - name: Install dependencies - run: | - npm install - - - name: List unused CSS - run: npm run find-unused-css + node-version: '22.x' - - name: Lint CSS - run: npm run lint:css + - name: Install Make + run: sudo apt-get install make - - name: Lint JS - run: npm run lint:js + - name: Lint files + run: make linting-node diff --git a/.github/workflows/pytest.yml b/.github/workflows/pytest.yml deleted file mode 100644 index a12bd81d9..000000000 --- a/.github/workflows/pytest.yml +++ /dev/null @@ -1,14 +0,0 @@ -name: Pytest - -on: [push] - -jobs: - build: - runs-on: ubuntu-latest - steps: - - name: Checkout code - uses: actions/checkout@v3 - - name: Build Docker image - run: docker build -t lotesting . - - name: Run tests - run: docker run lotesting diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 000000000..490d33e0e --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,51 @@ +name: Test packages + +on: [push] + +jobs: + test-packages: + runs-on: ubuntu-latest + strategy: + matrix: + package: ['learning_observer/', 'modules/writing_observer/'] + steps: + - name: Checkout code + uses: actions/checkout@v3 + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: '3.11' + + - name: Install Make + run: sudo apt-get install make + + - name: Get list of changed files + id: changes + run: | + git fetch origin master + git diff --name-only origin/master HEAD > changed_files.txt + + - name: Check if package has changes + id: package_check + run: | + if grep -qE "^${{ matrix.package }}" changed_files.txt; then + echo "run_tests=true" >> $GITHUB_ENV + else + echo "run_tests=false" >> $GITHUB_ENV + fi + + - name: Skip tests if no changes + if: env.run_tests == 'false' + run: echo "Skipping tests for ${{ matrix.package }} as there are no changes." + + - name: Install the base Learning Observer + if: env.run_tests == 'true' + run: make install + + - name: Install the package with pip + if: env.run_tests == 'true' + run: pip install -e ${{ matrix.package }} + + - name: Run tests + if: env.run_tests == 'true' + run: make test PKG=${{ matrix.package }} diff --git a/.github/workflows/versioning.yml b/.github/workflows/versioning.yml deleted file mode 100644 index a0b2fd439..000000000 --- a/.github/workflows/versioning.yml +++ /dev/null @@ -1,27 +0,0 @@ -name: Pytest - -on: - push: - branches: - - master - -jobs: - build: - runs-on: ubuntu-latest - steps: - - name: GitHub Script - uses: actions/github-script@v7.0.1 - with: - # The script to run - script: | - const shortSHA = context.sha.substring(0, 7); - const date = new Date().toISOString().split('T')[0]; // Gets date in YYYY-MM-DD format - const formattedDate = date.replace(/-/g, '.'); // Replaces '-' with '.' - const tagName = `${formattedDate}-${shortSHA}`; - - github.rest.git.createRef({ - owner: context.repo.owner, - repo: context.repo.repo, - ref: `refs/tags/${tagName}`, - sha: context.sha - }) diff --git a/Makefile b/Makefile index f22128c14..212c25dc6 100644 --- a/Makefile +++ b/Makefile @@ -1,16 +1,40 @@ -PACKAGES ?= wo,awe +# TODO rename these packages to something else +PACKAGES ?= wo + +help: + @echo "Available commands:" + @echo "" + @echo " run Run the learning_observer Python application." + @echo " install-pre-commit-hook Install the pre-commit git hook." + @echo " install Install the learning_observer package in development mode." + @echo " install-dev Install dev dependencies (requires additional setup)." + @echo " install-packages Install specific packages: [${PACKAGES}]." + @echo " test Run tests for the specified package (PKG=)." + @echo " linting-setup Setup linting tools and dependencies." + @echo " linting-python Lint Python files using pycodestyle and pylint." + @echo " linting-node Lint Node files (JS, CSS, and unused CSS detection)." + @echo " linting Perform all linting tasks (Python and Node)." + @echo " build-wo-chrome-extension Build the writing-process extension." + @echo " build-python-distribution Build a distribution for the specified package (PKG=)." + @echo "" + @echo "Note: All commands are executed in the current shell environment." + @echo " Ensure your virtual environment is activated if desired, as installs and actions" + @echo " will occur in the environment where the 'make' command is run." + @echo "" + @echo "Use 'make ' to execute a command. For example: make run" run: # If you haven't done so yet, run: make install # we need to make sure we are on the virtual env when we do this cd learning_observer && python learning_observer -venv: - # This is unnecessary since LO installs requirements on install. - # pip install --no-cache-dir -r requirements.txt +# Install commands +install-pre-commit-hook: + # Adding pre-commit.sh to Git hooks + cp scripts/hooks/pre-commit.sh .git/hooks/pre-commit + chmod +x .git/hooks/pre-commit -# install commands -install: venv +install: install-pre-commit-hook # The following only works with specified packages # we need to install learning_observer in dev mode to # more easily pass in specific files we need, such as creds @@ -25,28 +49,15 @@ install: venv @LODRC_CURRENT=$$(curl -s https://raw.githubusercontent.com/ETS-Next-Gen/lo_assets/main/lo_dash_react_components/lo_dash_react_components-current.tar.gz); \ pip install https://raw.githubusercontent.com/ETS-Next-Gen/lo_assets/main/lo_dash_react_components/$${LODRC_CURRENT} -install-dev: venv +install-dev: # TODO create a dev requirements file pip install --no-cache-dir -e learning_observer/[${PACKAGES}] . ${HOME}/.nvm/nvm.sh && nvm use && pip install -v -e modules/lo_dash_react_components/ -install-packages: venv +install-packages: pip install -e learning_observer/[${PACKAGES}] # Just a little bit of dependency hell... - - # The AWE Components are built using a specific version of - # `spacy`. This requires an out-of-date `typing-extensions` - # package. There are few other dependecies that require a - # newer version. As far as I can tell, upgrading this package - # does not effect the functionality we receive from the AWE - # components. - # TODO remove this extra step after AWE Component's `spacy` - # is no longer version locked. - # This is no longer an issue, but we will leave until all - # dependecies can be resolved in the appropriate locations. - # pip install -U typing-extensions - # On Python3.11 with tensorflow, we get some odd errors # regarding compatibility with `protobuf`. Some installation # files are missing from the protobuf binary on pip. @@ -54,23 +65,20 @@ install-packages: venv pip uninstall -y protobuf pip install --no-binary=protobuf protobuf==4.25 -# testing commands +# Testing commands test: - # this is where we run doctests - pytest modules/wo_highlight_dashboard + @if [ -z "$(PKG)" ]; then echo "No module specified, please try again with \"make test PKG=path/to/module\""; exit 1; fi + ./test.sh $(PKG) # Linting commands -linting-setup: - # Setting up linting related packages - pip install pycodestyle pylint - npm install - linting-python: # Linting Python modules + pip install pycodestyle pylint pycodestyle --ignore=E501,W503 $$(git ls-files 'learning_observer/*.py' 'modules/*.py') pylint -d W0613,W0511,C0301,R0913,too-few-public-methods $$(git ls-files 'learning_observer/*.py' 'modules/*.py') linting-node: + npm install # TODO each of these have lots of errors and block # the next item from running # Starting to lint Node modules @@ -84,8 +92,27 @@ linting-node: linting: linting-setup linting-python linting-node # Finished linting -build-writing-ext: +# Build commands +build-wo-chrome-extension: # Installing LO Event cd modules/lo_event && npm install & npm link lo_event # Building extension cd extension/writing-process && npm install && npm run build + +build-python-distribution: + # Building distribution for package + pip install build + # Switching to package directory + cd $(PKG) && python -m build + +# TODO we may want to have a separate command for uploading to testpypi +upload-python-package-to-pypi: build-python-distribution + pip install twine + # TODO we currently only upload to testpypi + # TODO we need to include `TWINE_USERNAME=__token__` + # and `TWINE_PASSWORD={ourTwineToken}` to authenticate + # + # TODO We have not fully tested the following commands. + # Try out the following steps and fix any bugs so the + # Makefile can do it automatically. + # cd $(PKG) && twine upload -r testpypi dist/* diff --git a/VERSION b/VERSION new file mode 100644 index 000000000..b1c34e29a --- /dev/null +++ b/VERSION @@ -0,0 +1 @@ +0.1.0+2025.04.14T14.58.15.3NZ.5aef220.dami.lms.pmss diff --git a/autodocs/development.rst b/autodocs/development.rst index 2fae1da45..f32772264 100644 --- a/autodocs/development.rst +++ b/autodocs/development.rst @@ -5,12 +5,6 @@ Development .. include:: ../docs/documentation.md :parser: myst_parser.sphinx_ -.. include:: ../modules/lo_dash_react_components/README.md - :parser: myst_parser.sphinx_ -.. include:: ../modules/lo_event/README.md - :parser: myst_parser.sphinx_ -.. include:: ../modules/writing_observer/README.md - :parser: myst_parser.sphinx_ .. include:: ../docs/interactive_environments.md :parser: myst_parser.sphinx_ .. include:: ../docs/privacy.md @@ -21,5 +15,7 @@ Development :parser: myst_parser.sphinx_ .. include:: ../docs/testing.md :parser: myst_parser.sphinx_ +.. include:: ../docs/versioning.md + :parser: myst_parser.sphinx_ .. include:: ../docs/technologies.md :parser: myst_parser.sphinx_ diff --git a/autodocs/index.rst b/autodocs/index.rst index c631233ae..df1bee6e3 100644 --- a/autodocs/index.rst +++ b/autodocs/index.rst @@ -17,6 +17,7 @@ data. development system_design + modules extension api diff --git a/autodocs/modules.rst b/autodocs/modules.rst new file mode 100644 index 000000000..dd2b9f08a --- /dev/null +++ b/autodocs/modules.rst @@ -0,0 +1,11 @@ +.. _modules: + +Modules +----------- + +.. include:: ../modules/lo_dash_react_components/README.md + :parser: myst_parser.sphinx_ +.. include:: ../modules/lo_event/README.md + :parser: myst_parser.sphinx_ +.. include:: ../modules/writing_observer/README.md + :parser: myst_parser.sphinx_ diff --git a/autodocs/system_design.rst b/autodocs/system_design.rst index a48558798..43c818d49 100644 --- a/autodocs/system_design.rst +++ b/autodocs/system_design.rst @@ -12,3 +12,5 @@ System Design :parser: myst_parser.sphinx_ .. include:: ../docs/reducers.md :parser: myst_parser.sphinx_ +.. include:: ../learning_observer/learning_observer/communication_protocol/README.md + :parser: myst_parser.sphinx_ diff --git a/awe_requirements.txt b/awe_requirements.txt deleted file mode 100644 index 042887396..000000000 --- a/awe_requirements.txt +++ /dev/null @@ -1,7 +0,0 @@ -spacy==3.4.4 -pydantic==1.10 -spacytextblob==3.0.1 -AWE_SpellCorrect @ git+https://github.com/ETS-Next-Gen/AWE_SpellCorrect.git -AWE_Components @ git+https://github.com/ETS-Next-Gen/AWE_Components.git -AWE_Lexica @ git+https://github.com/ETS-Next-Gen/AWE_Lexica.git -AWE_LanguageTool @ git+https://github.com/ETS-Next-Gen/AWE_LanguageTool.git diff --git a/devops/requirements.txt b/devops/requirements.txt index fbb305608..e548f11b9 100644 --- a/devops/requirements.txt +++ b/devops/requirements.txt @@ -2,4 +2,5 @@ chevron boto3 pyyaml fabric - +invoke +filetype diff --git a/docs/dashboards.md b/docs/dashboards.md index baa271f70..b003941ea 100644 --- a/docs/dashboards.md +++ b/docs/dashboards.md @@ -6,7 +6,7 @@ We can create custom dashboards for the system. Dash is a package for writing and serving web applications directly in Python. In Dash, there are 2 primary items, 1) page components such as headers, divs, spans, etc. and 2) callbacks. -### Getting started +### Getting Started with Dash Page components can be set up similar to other `html` layouts, like so @@ -180,3 +180,38 @@ DASH_PAGES = [ } ] ``` + +## NextJS + +NextJS is web framework for building React-based web applications along with additional server-side functionality. + +### Getting Started with NextJS + +Follow the [Getting Started Guide](https://nextjs.org/docs/app/getting-started) in the official NextJS documentation. + +### NextJS in the Learning Observer + +Before add a NextJS application can be built and added to the system, a few configurations changes need to be made. The built application will not access the server-side code. Any server-side API endpoints need to be implemented in Python. The code that calls these endpoints will need to be updated to point to the correct path. + +Additionally, we need to add a `basePath` to our `next.config.js` file. When building the application, this replaces prefixes all paths with the defined base path. This allows links to function appropriately while being served from Learning Observer. + +```js +const nextConfig = { + // ... the rest of your config + basePath: '/_next/moduleName/pathOfBuiltApplication' +``` + +To add a NextJS project to a module, first the code needs to be built with `npm run build`. A directory named `out` will be created and the built application will be placed there. Copy this directoy to a module within Learning Observer. + +Next, add the path to the built application to the module's `module.py` file + +```python +# module.py +# ...other definitions +''' +Next js dashboards +''' +NEXTJS_PAGES = [ + {'path': 'pathOfBuiltApplication/'} +] +``` diff --git a/docs/testing.md b/docs/testing.md index 80f2aa46f..1c4d1e99b 100644 --- a/docs/testing.md +++ b/docs/testing.md @@ -2,6 +2,54 @@ Testing is an essential part of software development to ensure the reliability and stability of your code. In the Learning Observer project, we currently support Python testing, using the pytest framework. This document provides an overview of how the testing framework is used in the project. +## Preparing a Module for Testing + +The following workflow is a **HACK** while we work toward better testing infrastructure. +Each module should define a `test.sh` at the root of the module's directory. This script should define how to run the tests for the module. + +### How Testing Ought to be + +We want to have a finite set of testing infrastructure. The types of tests we ought to support are + +- Client / dashboard tests + - Basic: we're not getting 500 errors on any pages (which can be semi-automatic from routes) + - Advanced: things work as expected. +- Python unit tests +- Server-side integration tests +- Data pipeline tests + - The very explicit models, like reducers, are designed to support this + - Also, query language, etc. + - This is related to replicability, which is important in science and in debugging in ways we discussed + +We should have an opinionated, recommended way to do things, included in the example template package. + +## Running Tests + +The Makefile offers a `test` command which calls an overall `test.sh` script. This script takes the passed in module paths and runs each of their respective `test.sh` scripts. To run via the Makefile, use + +```bash +make test PKG=path/to/module +# OR to test multiple packages at once +make test PKG="modules/writing_observer learning_observer" +``` + +## GitHub Actions for Automated Testing + +To automate testing in your project, you can use GitHub Actions. This allows you to run tests automatically when you push changes to your repository. The provided GitHub Action YAML file will iterate over the defined modules and + +1. Check for any changes within that module. If no changes are found, proceed to next module in list. +1. Install Learning Observer - `make install` +1. Install the module itself - `pip install path/to/module` +1. Run tests - `make test PKG=path/to/module` + +To add an additional module to this testing pipeline, add its path to the list of packages under the matrix strategy in `.github/workflows/test.yml`, like so: + +```yml + strategy: + matrix: + package: ['learning_observer/', 'modules/writing_observer/', 'path/to/new/module/'] +``` + ## Python Testing We use the [pytest framework](https://docs.pytest.org/) for Python testing. Pytest is a popular testing framework that simplifies writing and running test cases. It provides powerful features, such as fixtures, parametrized tests, and plugins, to help you test your code efficiently and effectively. @@ -23,7 +71,7 @@ To write test cases for your Python code, follow these guidelines: 2. For each file or functionality you want to test, create a separate test file with a name in the format `test_.py` or `test_.py`. 3. Inside each test file, write test functions that test specific aspects of your code. Start each test function's name with `test_` to ensure that pytest can discover and run the test. -### Running Tests +### Running PyTests Once you have written your test cases, you can run them using the pytest command: @@ -37,18 +85,6 @@ For example, to run tests for the `wo_highlight_dashboard` module, you would run pytest modules/wo_highlight_dashboard/ ``` -### GitHub Actions for Automated Testing - -To automate testing in your project, you can use GitHub Actions. This allows you to run tests automatically when you push changes to your repository. The provided GitHub Action YAML file sets up a testing environment for the specified Python versions, installs the necessary dependencies, and runs the tests using pytest. You can customize this file to add or modify steps as needed for your project. - -If your tests should be automated make sure to provide them as a parameter in the `.github/workflows/pytest.yml`. While we work on cleaning up the prior testing framework, we only run select tests. - -```yaml - - name: Unit testing with pytest - run: | - pytest modules/wo_highlight_dashboard/ -``` - ## Other testing Not yet implemented. diff --git a/docs/versioning.md b/docs/versioning.md new file mode 100644 index 000000000..f0efb4d87 --- /dev/null +++ b/docs/versioning.md @@ -0,0 +1,47 @@ +# Versioning + +## Tracking Versions + +Each module should include a `VERSION` file to specify the module's current version. This version is referenced in the module's setup configuration. Typically, this is done in the `setup.cfg` file as follows: + +```cfg +# setup.cfg +[metadata] +name = Module name +version = file:VERSION +``` + +## Version Format + +The version format is split into 2 pieces, the semantic version and the local version string separated by a `+`. The semantic version is primarily used for uploading to PyPI and resolving dependency conflicts. The local version string contains additional metadata about when the code was last modified and the commit it came from. The versions should follow the following format: + +```sh +major.minor.patch+%Y.%m.%dT%H.%M.%S.%3NZ.abc123.branch.name +``` + +A example version string might look like this: + +```sh +0.1.0+2024.12.16T16.42.38.637Z.abc123.branch.name +``` + +## Bumping Versions + +The local version strings that contain metadata are automatically managed using a Git pre-commit hook. Before each commit is made, the appropriate `VERSION` is updated to reflect the current time and commit. + +Bumping the semantic version is done manually. + +## Setting Up the Pre-Commit Hook + +To enable automatic version bumping, use the `install-pre-commit-hook` command provided in the `Makefile`. This command handles copying the pre-commit hook script into the appropriate location and making it executable. Run the following command: + +```bash +make install-pre-commit-hook +``` + +With this setup, every commit will automatically update the version for you. + +## Notes + +- Ensure that `setup.cfg` properly references the `VERSION` file to avoid version mismatches. +- Avoid manually editing the `VERSION` file; rely on the pre-commit hook for consistency. diff --git a/docs/workshop.md b/docs/workshop.md index e32f6fdd8..a79b6c664 100644 --- a/docs/workshop.md +++ b/docs/workshop.md @@ -149,7 +149,7 @@ We can stream data into the system to simulate a classroom of students working. ```bash workon lo_workshop -python learning_observer/util/stream_writing.py --streams=10 +python scripts/stream_writing.py --streams=10 ``` To avoid cache issues, we recommend this order: diff --git a/docs/workshop_creds.md b/docs/workshop_creds.md index 9cf605d56..7bfad2f2a 100644 --- a/docs/workshop_creds.md +++ b/docs/workshop_creds.md @@ -63,11 +63,12 @@ The platform expects both of these files to exist under `learning_observer/learn ### passwd.lo -Each install of the system needs an admin password file associated with it. The `learning_observer/util/lo_passwd.py` file can be used to generate this password file. This does not have to be done in the same virtual environment as the main server. If you are using Docker, just create a local virtual environment to run this command. +Each install of the system needs an admin password file associated with it. The `scripts/lo_passwd.py` file can be used to generate this password file. This does not have to be done in the same virtual environment as the main server. If you are using Docker, just create a local virtual environment to run this command. ```bash -cd learning_observer/ -python util/lo_passwd.py --username admin --password supersecureadminpassword --filename passwd.lo +python scripts/lo_passwd.py --username admin --password supersecureadminpassword --filename learning_observer/passwd.lo ``` +Note that Learning Observer expects the file to be placed in the `learning_observer/` directory, similar to `creds.yaml`. + Depending on how the `creds.yaml` authorization settings are configured, you may be required to use the password you create. diff --git a/extension/writing-process/package.json b/extension/writing-process/package.json index b789a11c1..7b5c0e504 100644 --- a/extension/writing-process/package.json +++ b/extension/writing-process/package.json @@ -1,7 +1,7 @@ { "name": "writing-process", "description": "Tracks writing in Google Docs, and provides nifty insights to you and your teachers!", - "version": "1.0.0.2", + "version": "1.0.0.4", "homepage": "http://chrome.google.com/webstore", "author": "Piotr Mitros, Bradley Erickson", "repository": { @@ -62,10 +62,6 @@ "name": "background", "src": "./src/background.bundle.js" }, - { - "name": "inject", - "src": "./src/inject.bundle.js" - }, { "name": "service_worker", "src": "./src/service_worker.bundle.js" diff --git a/extension/writing-process/src/background.js b/extension/writing-process/src/background.js index aa569cfed..5396ce383 100644 --- a/extension/writing-process/src/background.js +++ b/extension/writing-process/src/background.js @@ -17,7 +17,9 @@ import * as loEvent from 'lo_event/lo_event/lo_event.js'; import * as loEventDebug from 'lo_event/lo_event/debugLog.js'; import { websocketLogger } from 'lo_event/lo_event/websocketLogger.js'; import { consoleLogger } from 'lo_event/lo_event/consoleLogger.js'; -import * as loEventUtils from 'lo_event/lo_event/util.js'; +import { browserInfo } from 'lo_event/lo_event/metadata/browserinfo.js'; +import { chromeAuth } from 'lo_event/lo_event/metadata/chromeauth.js'; +import { localStorageInfo, sessionStorageInfo } from 'lo_event/lo_event/metadata/storage.js'; // We would like to support fetching the websocket server from storage @@ -33,8 +35,20 @@ const loggers = [ websocketLogger(WEBSOCKET_SERVER_URL) ] -loEvent.init('org.mitros.writing_analytics', '0.01', loggers, loEventDebug.LEVEL.SIMPLE); -loEvent.setFieldSet([loEventUtils.getBrowserInfo(), loEventUtils.fetchDebuggingIdentifier()]); +loEvent.init( + 'org.mitros.writing_analytics', + '0.01', + loggers, + { + debugLevel: loEventDebug.LEVEL.SIMPLE, + metadata: [ + browserInfo(), + chromeAuth(), + localStorageInfo(), + sessionStorageInfo(), + ] + } +); loEvent.go(); // Function to serve as replacement for @@ -205,16 +219,6 @@ async function reinjectContentScripts() { // Let the server know we've loaded. loEvent.logEvent("extension_loaded", {}); -// Send the server the user info. This might not always be available. -// HACK: this code will be changed pending server side changes to how we -// handle auth and metadata. -loEventUtils.profileInfoWrapper().then((result) => { - if (Object.keys(result).length > 0) { - loEvent.logEvent('chrome_identity', { chrome_identity: result }); - loEvent.logEvent('metadata_finished', {}) - } -}); - // And let the console know we've loaded // chrome.extension.getBackgroundPage().console.log("Loaded"); remove logFromServiceWorker("Loaded"); diff --git a/extension/writing-process/src/inject.js b/extension/writing-process/src/inject.js deleted file mode 100644 index 613429ba3..000000000 --- a/extension/writing-process/src/inject.js +++ /dev/null @@ -1,19 +0,0 @@ -/* - Inject script. This is a web_accessible_resources used to pass the id - of the document as a globally accessible variable to the extension. - It is called by the injectScript function in writing.js to make the result - accessible using an event listener. - - TODO: - * We don't really understand this code. It should be commented - * In particular, why are we using an IIFE (immediately invoked function - expression) rather than just the code? - - If this is a relic, it should be cleaned up. If this has a - reason, it should be documented. -*/ - -(function() { - const result = JSON.stringify(_docs_flag_initialData.info_params.token); - window.postMessage({ from: 'inject.js', data: result }); -})(); diff --git a/extension/writing-process/src/manifest.json b/extension/writing-process/src/manifest.json index 9d26efaa6..89ede3945 100644 --- a/extension/writing-process/src/manifest.json +++ b/extension/writing-process/src/manifest.json @@ -4,8 +4,8 @@ "description": "__MSG_appDescription__", "homepage_url": "https://github.com/ETS-Next-Gen/writing_observer/tree/master/extension/writing-process", "incognito": "not_allowed", - "version": "1.0.0.2", - "version_name": "1.0.0.2", + "version": "1.0.0.4", + "version_name": "1.0.0.4", "manifest_version": 3, "default_locale": "en", "minimum_chrome_version": "88", @@ -36,15 +36,10 @@ "matches": ["*://docs.google.com/document/*"], "js": ["3rdparty/sha256.js", "writing_common.js", "writing.js"] }], - "web_accessible_resources": [{ - "resources": ["inject.js"], - "matches": ["*://docs.google.com/*"], - "use_dynamic_url": true - }], "host_permissions": [ "*://docs.google.com/document/*" ], "options_ui": { "page": "pages/options.html" } -} \ No newline at end of file +} diff --git a/extension/writing-process/src/writing.js b/extension/writing-process/src/writing.js index 653544a28..f318f404d 100644 --- a/extension/writing-process/src/writing.js +++ b/extension/writing-process/src/writing.js @@ -3,7 +3,7 @@ */ /* For debugging purposes: we know the extension is active */ -document.body.style.border = "5px solid blue"; +// document.body.style.border = "1px solid blue"; import { googledocs_id_from_url, treeget } from './writing_common'; /* @@ -37,7 +37,7 @@ function log_event(event_type, event) { "title": google_docs_title(), "id": doc_id(), "url": window.location.href, - } + }; event['event'] = event_type; // We want to track the page status during events. For example, @@ -142,29 +142,31 @@ function is_string(myVar) { } } -function injectScript(file_path, tag) { - /* - This function is to inject a script from 'file_path' - into a specific DOM tag passed in as 'tag' - */ - var node = document.getElementsByTagName(tag)[0]; - var script = document.createElement('script'); - script.setAttribute('type', 'text/javascript'); - script.setAttribute('src', file_path); - node.appendChild(script); -} - -function execute_on_page_space(code){ - /* This is from - https://stackoverflow.com/questions/9602022/chrome-extension-retrieving-global-variable-from-webpage - - It is used to run code outside of the extension isolation box, - for example to access page JavaScript variables. +function extractDocsToken() { + /** + * We need the doc token to be able to fetch the document + * history. This token is provided via a